aboutsummaryrefslogtreecommitdiff
path: root/teensy/teensy_ui.c
diff options
context:
space:
mode:
authoriamcheeseman <[email protected]>2026-05-22 19:09:14 -0400
committeriamcheeseman <[email protected]>2026-05-22 19:09:14 -0400
commit2d5c6f38f73453e4b1185017ff01b02f095a5db0 (patch)
tree4e832ff92070b1c81d40acf32e9848833b279c41 /teensy/teensy_ui.c
parentb4d44545a641c2c27e63aa10d651dcec985971c1 (diff)
fix negative column widths
Diffstat (limited to 'teensy/teensy_ui.c')
-rw-r--r--teensy/teensy_ui.c42
1 files changed, 21 insertions, 21 deletions
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();
}