From bcf1439eb8d936d3b43ac817519cd47e9624210e Mon Sep 17 00:00:00 2001 From: iamcheeseman Date: Sun, 24 May 2026 09:04:26 -0400 Subject: completely redo lists --- teensy/teensy_ui.c | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) (limited to 'teensy/teensy_ui.c') diff --git a/teensy/teensy_ui.c b/teensy/teensy_ui.c index 6a156bb..7ff2418 100644 --- a/teensy/teensy_ui.c +++ b/teensy/teensy_ui.c @@ -34,6 +34,12 @@ typedef struct { tyui_Align align; } Cmd; +typedef struct { + size_t len; + size_t cap; + Cmd *items; +} CmdList; + typedef struct { int idx; int columns; @@ -45,7 +51,7 @@ typedef struct { } Layout; typedef struct { - Cmd *cmds; + CmdList cmds; Layout *layout; Layout layout_stack[MAX_LAYOUTS]; ty_Recti rect; @@ -105,7 +111,7 @@ void rect_cmd(ty_Recti rect, ty_Color color) cmd.rect = rect; cmd.color = color; - ty_list_append(window()->cmds, cmd); + ty_list_append(&window()->cmds, cmd); } static @@ -117,7 +123,7 @@ void text_cmd(const char *text, ty_Recti rect, tyui_Align align) cmd.rect = rect; cmd.align = align; - ty_list_append(window()->cmds, cmd); + ty_list_append(&window()->cmds, cmd); } static @@ -127,7 +133,7 @@ void image_cmd(ty_Image img, ty_Recti rect) cmd.kind = CMD_IMAGE; cmd.img = img; cmd.rect = rect; - ty_list_append(window()->cmds, cmd); + ty_list_append(&window()->cmds, cmd); } static @@ -140,7 +146,7 @@ void clip_cmd(ty_Recti rect) rect = window()->rect; // This is a full screen clip cmd.rect = ty_recti_clamp(rect, window()->rect); - ty_list_append(window()->cmds, cmd); + ty_list_append(&window()->cmds, cmd); } static @@ -230,11 +236,10 @@ bool is_hovered(ty_Recti rect) static Window create_window(ty_Recti rect, uint32_t flags) { - Window win = {}; + Window win = {0}; win.rect = rect; win.flags = flags; - win.cmds = ty_list_create(); - ty_list_reserve(win.cmds, 64); + ty_list_reserve(&win.cmds, 8); return win; } @@ -258,9 +263,9 @@ void tyui_init(const ty_Font *font) void tyui_deinit(void) { - ty_list_free(tyui.root.cmds); + ty_list_free(&tyui.root.cmds); for (int i = 0; i < tyui.window_count; i++) - ty_list_free(tyui.windows[i].cmds); + ty_list_free(&tyui.windows[i].cmds); } void tyui_push_layout(const float *column_widths) @@ -562,8 +567,8 @@ void tyui_text_input(tyui_Text_Input *input) static void draw_window(Window *win) { - for (size_t i = 0; i < ty_list_len(win->cmds); i++) { - Cmd cmd = win->cmds[i]; + for (size_t i = 0; i < win->cmds.len; i++) { + Cmd cmd = win->cmds.items[i]; switch (cmd.kind) { case CMD_RECT: ty_draw_rect(cmd.rect, cmd.color); @@ -594,7 +599,7 @@ void draw_window(Window *win) } } ty_draw_set_clip(TY_CLIP_NONE); - ty_list_clear(win->cmds); + ty_list_clear(&win->cmds); } static -- cgit v1.3-2-g0d8e