aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--dc/dc.c12
-rw-r--r--teensy/teensy_ui.c42
2 files changed, 31 insertions, 23 deletions
diff --git a/dc/dc.c b/dc/dc.c
index 97be641..679d43a 100644
--- a/dc/dc.c
+++ b/dc/dc.c
@@ -69,7 +69,7 @@ void tick(void)
if (tyui_begin_window("Test Window", ty_recti(5, 5, 100, 120), &winid1)) {
tyui_button("before");
- tyui_push_layout((float[]){0.5, -1, 0});
+ tyui_push_layout((float[]){-50, -1, 0});
tyui_push_layout((float[]){-1, 0});
tyui_text_ex(TYUI_ALIGN_CENTER, "Buttons");
tyui_button("test1");
@@ -97,6 +97,14 @@ void tick(void)
tyui_slider_ex(0, 100, &value, true, TYUI_ALIGN_LEFT);
tyui_slider_ex(0, 100, &value, true, TYUI_ALIGN_RIGHT);
tyui_blank_slider(0, 100, &value);
+
+ tyui_push_layout((float[]){-50, -1, 0});
+ tyui_button("abc");
+ tyui_button("xyz");
+ tyui_button("abc");
+ tyui_button("xyz");
+ tyui_pop_layout();
+
tyui_end_window();
}
@@ -161,7 +169,7 @@ int main(void)
tick();
ty_free_temp_allocs();
- // ty_sleep(1000 / hints.ticrate);
+ ty_sleep(1000 / hints.ticrate);
}
ty_free_image(img);
diff --git a/teensy/teensy_ui.c b/teensy/teensy_ui.c
index 58005b8..8449417 100644
--- a/teensy/teensy_ui.c
+++ b/teensy/teensy_ui.c
@@ -42,6 +42,7 @@ typedef struct {
float column_widths[TYUI_MAX_LAYOUT_SIZE];
int max_height;
int total_height;
+ int x;
int width;
} Layout;
@@ -160,46 +161,45 @@ void advance_layout(void)
l->total_height += l->max_height + padding();
l->idx = 0;
l->max_height = 0;
+
+ if (l == window()->layout_stack)
+ l->x = padding();
+ else
+ l->x = 0;
}
static
-int get_column_width(const Layout *l, int x, float width)
+int get_column_width(const Layout *l)
{
+ float width = l->column_widths[l->idx];
if (width < 0)
- return (l->width - padding() * 2) - width - x;
+ return width + l->width - l->x + 1;
if (width < 1)
return (l->width - padding() * 2) * width;
return width;
}
static
-int get_column_x(const Layout *l)
-{
- int x = 0;
- for (int i = 0; i < l->idx; i++)
- x += get_column_width(l, x, l->column_widths[i]) + padding();
- return x;
-}
-
-static
ty_Recti next_rect(int height)
{
Layout *l = layout();
l->max_height = ty_max(l->max_height, height);
- int x = get_column_x(l) + padding();
- float width = get_column_width(l, x, l->column_widths[l->idx]);
+ float width = get_column_width(l);
+ int x = 0;
int y = 0;
for (Layout *outer = window()->layout_stack; outer <= l; outer++) {
- x += get_column_x(outer);
+ x += outer->x;
y += outer->total_height;
}
x += window()->rect.x;
y += window()->rect.y;
+ l->x += width + padding();
+
advance_layout();
return ty_recti(x, y, width, height);
@@ -274,15 +274,14 @@ void tyui_push_layout(const float *column_widths)
sizeof(*column_widths) * new->columns
);
- new->total_height = 0;
+ new->x = 0;
- if (new != window()->layout_stack) {
- int x = get_column_x(outer);
- new->width =
- get_column_width(outer, x, outer->column_widths[outer->idx]);
- } else {
+ if (new != window()->layout_stack)
+ new->width = get_column_width(outer);
+ else
new->width = window()->rect.w;
- }
+
+ new->width -= padding();
}
void tyui_pop_layout(void)
@@ -290,6 +289,7 @@ void tyui_pop_layout(void)
Layout *old = pop_layout();
Layout *top = layout();
top->max_height = ty_max(top->max_height, old->total_height - padding());
+ top->x += old->width + padding();
advance_layout();
}