aboutsummaryrefslogtreecommitdiff
path: root/teensy/teensy_ui.c
diff options
context:
space:
mode:
Diffstat (limited to 'teensy/teensy_ui.c')
-rw-r--r--teensy/teensy_ui.c31
1 files changed, 18 insertions, 13 deletions
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
@@ -35,6 +35,12 @@ typedef struct {
} Cmd;
typedef struct {
+ size_t len;
+ size_t cap;
+ Cmd *items;
+} CmdList;
+
+typedef struct {
int idx;
int columns;
float column_widths[TYUI_MAX_LAYOUT_SIZE];
@@ -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