mirror of
https://github.com/fergalmoran/ladybird.git
synced 2026-01-04 07:36:50 +00:00
LibGUI: Subtract layout margin when placing items along secondary axis
While space distribution along the primary axis of a BoxLayout is pretty sophisticated, the secondary axis is very simple: we simply center the widget. However, this doesn't always look very nice if we don't take margins into account, so make sure we subtract them from the rect we do all the centering within.
This commit is contained in:
@@ -198,6 +198,12 @@ void BoxLayout::run(Widget& widget)
|
||||
int current_x = margins().left();
|
||||
int current_y = margins().top();
|
||||
|
||||
auto widget_rect_with_margins_subtracted = widget.rect();
|
||||
widget_rect_with_margins_subtracted.take_from_left(margins().left());
|
||||
widget_rect_with_margins_subtracted.take_from_top(margins().top());
|
||||
widget_rect_with_margins_subtracted.take_from_right(margins().right());
|
||||
widget_rect_with_margins_subtracted.take_from_bottom(margins().bottom());
|
||||
|
||||
for (auto& item : items) {
|
||||
Gfx::IntRect rect { current_x, current_y, 0, 0 };
|
||||
|
||||
@@ -220,9 +226,9 @@ void BoxLayout::run(Widget& widget)
|
||||
rect.set_secondary_size_for_orientation(orientation(), secondary);
|
||||
|
||||
if (orientation() == Gfx::Orientation::Horizontal)
|
||||
rect.center_vertically_within(widget.rect());
|
||||
rect.center_vertically_within(widget_rect_with_margins_subtracted);
|
||||
else
|
||||
rect.center_horizontally_within(widget.rect());
|
||||
rect.center_horizontally_within(widget_rect_with_margins_subtracted);
|
||||
|
||||
item.widget->set_relative_rect(rect);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user