From 202bb707ceee5ad909e6837d927dcc9da881ec42 Mon Sep 17 00:00:00 2001 From: Norman Feske Date: Mon, 13 Jun 2022 11:11:58 +0200 Subject: [PATCH] menu_view: ignore zero-sized widgets in box layout The box layout evenly distributes the child widgets according to the number of children. This is not desired in the special case where a child widget has a size of zero. The patch changes the layout algorithm such that zero-sized widgets are not taken into account for distributing residual space. --- repos/gems/src/app/menu_view/box_layout_widget.h | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/repos/gems/src/app/menu_view/box_layout_widget.h b/repos/gems/src/app/menu_view/box_layout_widget.h index 7af362885b..51e22e3d17 100644 --- a/repos/gems/src/app/menu_view/box_layout_widget.h +++ b/repos/gems/src/app/menu_view/box_layout_widget.h @@ -56,6 +56,10 @@ struct Menu_view::Box_layout_widget : Widget w.position(position); + /* don't account space for zero-sized child widgets */ + if (child_min_size.count() == 0) + return; + if (_direction == VERTICAL) { unsigned const next_top_margin = w.next() ? w.next()->margin.top : 0; unsigned const dy = child_min_size.h() - min(w.margin.bottom, next_top_margin); @@ -65,6 +69,7 @@ struct Menu_view::Box_layout_widget : Widget unsigned const dx = child_min_size.w() - min(w.margin.right, next_left_margin); position = position + Point(dx, 0); } + _count++; }); @@ -99,7 +104,10 @@ struct Menu_view::Box_layout_widget : Widget w.position(w.geometry().p1() + Point(consumed_fp >> 8, 0)); w.size(Area(w.min_size().w() + padding_pixels, geometry().h())); } - consumed_fp = next_consumed_fp; + + /* don't account space for zero-sized child widgets */ + if (w.min_size().count()) + consumed_fp = next_consumed_fp; }); }