From b3fe85995f54adc7948ad28f71b0f92b5ae8756c Mon Sep 17 00:00:00 2001 From: Přemysl Eric Janouch
Date: Mon, 19 Jun 2023 13:44:53 +0200 Subject: Dissolve widget_redistribute() liberty-xui has xui_hbox() and xui_vbox(), the way we use widgets is odd. --- nncmpp.c | 77 ++++++++++++++++++++++++++++++---------------------------------- 1 file changed, 36 insertions(+), 41 deletions(-) diff --git a/nncmpp.c b/nncmpp.c index cd8b1a3..efe3366 100644 --- a/nncmpp.c +++ b/nncmpp.c @@ -1172,46 +1172,6 @@ struct app_ui bool have_icons; }; -/// Replaces negative widths amongst widgets in the sublist by redistributing -/// any width remaining after all positive claims are satisfied from "width". -/// Also unifies heights to the maximum value of the run, and returns it. -/// Then the widths are taken as final, and used to initialize X coordinates. -static int -widget_redistribute (struct widget *head, int width) -{ - int parts = 0, max_height = 0; - LIST_FOR_EACH (struct widget, w, head) - { - max_height = MAX (max_height, w->height); - if (w->width < 0) - parts -= w->width; - else - width -= w->width; - } - - int remaining = MAX (width, 0), part_width = parts ? remaining / parts : 0; - struct widget *last = NULL; - LIST_FOR_EACH (struct widget, w, head) - { - w->height = max_height; - if (w->width < 0) - { - remaining -= (w->width *= -part_width); - last = w; - } - } - if (last) - last->width += remaining; - - int x = 0; - LIST_FOR_EACH (struct widget, w, head) - { - widget_move (w, x - w->x, 0); - x += w->width; - } - return max_height; -} - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - struct tab; @@ -1666,11 +1626,46 @@ app_append_layout (struct layout *l, struct layout *dest) *l = (struct layout) {}; } +/// Replaces negative widths amongst widgets in the layout by redistributing +/// any width remaining after all positive claims are satisfied from "width". +/// Also unifies heights to the maximum value of the run. +/// Then the widths are taken as final, and used to initialize X coordinates. static void app_flush_layout_full (struct layout *l, int width, struct layout *dest) { hard_assert (l != NULL && l->head != NULL); - widget_redistribute (l->head, width); + + int parts = 0, max_height = 0; + LIST_FOR_EACH (struct widget, w, l->head) + { + max_height = MAX (max_height, w->height); + if (w->width < 0) + parts -= w->width; + else + width -= w->width; + } + + int remaining = MAX (width, 0), part_width = parts ? remaining / parts : 0; + struct widget *last = NULL; + LIST_FOR_EACH (struct widget, w, l->head) + { + w->height = max_height; + if (w->width < 0) + { + remaining -= (w->width *= -part_width); + last = w; + } + } + if (last) + last->width += remaining; + + int x = 0; + LIST_FOR_EACH (struct widget, w, l->head) + { + widget_move (w, x - w->x, 0); + x += w->width; + } + app_append_layout (l, dest); } -- cgit v1.2.3-70-g09d2