summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2021-04-02 22:53:58 +0200
committerAndreas Kling <kling@serenityos.org>2021-04-02 23:33:17 +0200
commit6ba00ae5b934c33a4ff2de7ed41619a3acf6ca04 (patch)
tree81027fb0f6b7f7146fe439b541b9d38f349a628d /Userland
parent05d7869dc05779c003ec2c05a647ea980c6650eb (diff)
downloadserenity-6ba00ae5b934c33a4ff2de7ed41619a3acf6ca04.zip
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.
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Libraries/LibGUI/BoxLayout.cpp10
1 files changed, 8 insertions, 2 deletions
diff --git a/Userland/Libraries/LibGUI/BoxLayout.cpp b/Userland/Libraries/LibGUI/BoxLayout.cpp
index b9abc69309..74e0f3c2fd 100644
--- a/Userland/Libraries/LibGUI/BoxLayout.cpp
+++ b/Userland/Libraries/LibGUI/BoxLayout.cpp
@@ -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);
}