From 2d5c6f38f73453e4b1185017ff01b02f095a5db0 Mon Sep 17 00:00:00 2001 From: iamcheeseman Date: Fri, 22 May 2026 19:09:14 -0400 Subject: fix negative column widths --- teensy/teensy_ui.c | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) (limited to 'teensy/teensy_ui.c') 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,27 +161,24 @@ 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) { @@ -188,18 +186,20 @@ ty_Recti next_rect(int height) 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(); } -- cgit v1.3-2-g0d8e