aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--dc/dc.c2
-rw-r--r--teensy/teensy_ui.c30
-rw-r--r--teensy/teensy_ui.h2
3 files changed, 33 insertions, 1 deletions
diff --git a/dc/dc.c b/dc/dc.c
index 66fbf1c..74c0ea3 100644
--- a/dc/dc.c
+++ b/dc/dc.c
@@ -65,8 +65,10 @@ void tick(void)
double frame_time = ty_get_time() - last_frame;
last_frame = ty_get_time();
+ tyui_layout((float[]){0.25, 0});
tyui_text("%.2g ms", frame_time * 1000);
tyui_text("%.2d fps", (int)(1.0 / frame_time));
+ tyui_layout(NULL);
tyui_text("%d", (int)ty_get_time());
tyui_text("abcdefghijklmnopqrstuvwxyz");
tyui_text("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
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++) {
diff --git a/teensy/teensy_ui.h b/teensy/teensy_ui.h
index 771de61..0a1837a 100644
--- a/teensy/teensy_ui.h
+++ b/teensy/teensy_ui.h
@@ -26,6 +26,8 @@ typedef uint8_t tyui_Id;
void tyui_init(const ty_Font *font);
void tyui_deinit(void);
+void tyui_layout(const float *layout);
+
void tyui_draw(void);
bool tyui_begin_window_ex(