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.c30
1 files changed, 29 insertions, 1 deletions
diff --git a/teensy/teensy_ui.c b/teensy/teensy_ui.c
index 8a99ec9..6ab0198 100644
--- a/teensy/teensy_ui.c
+++ b/teensy/teensy_ui.c
@@ -38,8 +38,11 @@ typedef struct {
Window root;
Window windows[255];
int window_count;
+ int layout_idx;
+ int layout_size;
tyui_Style style;
const ty_Font *font;
+ const float *layout;
Cmd *cmds;
ty_Vec2i prev_mouse_pos;
@@ -105,7 +108,18 @@ static
ty_Vec2i next_pos(int height)
{
ty_Vec2i next = uictx.active->next_pos;
- uictx.active->next_pos.y += height;
+
+ float x_perc = 0;
+ for (int i = 0; i < uictx.layout_idx; i++)
+ x_perc += uictx.layout[i];
+ next.x = uictx.active->rect.w * x_perc;
+
+ uictx.layout_idx++;
+ if (uictx.layout_idx >= uictx.layout_size) {
+ uictx.layout_idx = 0;
+ uictx.active->next_pos.y += height;
+ }
+
return next;
}
@@ -153,6 +167,8 @@ void tyui_init(const ty_Font *font)
uictx.font = font;
uictx.active = &uictx.root;
+
+ tyui_layout(NULL);
}
void tyui_deinit(void)
@@ -165,6 +181,18 @@ void tyui_deinit(void)
}
}
+void tyui_layout(const float *layout)
+{
+ if (!layout)
+ layout = (float[]){0};
+
+ uictx.layout = layout;
+ uictx.layout_size = 1;
+ for (const float *p = layout; *p > 0; p++)
+ uictx.layout_size++;
+ uictx.layout_idx = 0;
+}
+
void tyui_draw(void)
{
for (size_t i = 0; i < ty_list_len(uictx.cmds); i++) {