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.
This commit is contained in:
Norman Feske 2022-06-13 11:11:58 +02:00 committed by Christian Helmuth
parent b4ded050e1
commit 202bb707ce

View File

@ -56,6 +56,10 @@ struct Menu_view::Box_layout_widget : Widget
w.position(position); w.position(position);
/* don't account space for zero-sized child widgets */
if (child_min_size.count() == 0)
return;
if (_direction == VERTICAL) { if (_direction == VERTICAL) {
unsigned const next_top_margin = w.next() ? w.next()->margin.top : 0; 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); 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); unsigned const dx = child_min_size.w() - min(w.margin.right, next_left_margin);
position = position + Point(dx, 0); position = position + Point(dx, 0);
} }
_count++; _count++;
}); });
@ -99,6 +104,9 @@ struct Menu_view::Box_layout_widget : Widget
w.position(w.geometry().p1() + Point(consumed_fp >> 8, 0)); w.position(w.geometry().p1() + Point(consumed_fp >> 8, 0));
w.size(Area(w.min_size().w() + padding_pixels, geometry().h())); w.size(Area(w.min_size().w() + padding_pixels, geometry().h()));
} }
/* don't account space for zero-sized child widgets */
if (w.min_size().count())
consumed_fp = next_consumed_fp; consumed_fp = next_consumed_fp;
}); });
} }