summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2022-06-21 21:18:00 +0200
committerAndreas Kling <kling@serenityos.org>2022-06-21 21:18:00 +0200
commit75e8b1305d32fbe53556023b586dbdec5478edcf (patch)
treeca77516bb28c2b1b99482ea551b5db9de3093abf /Userland/Libraries/LibWeb
parent99e96f951fbe5db87ba0f8fcfeaab3ef942bc289 (diff)
downloadserenity-75e8b1305d32fbe53556023b586dbdec5478edcf.zip
LibWeb: Actually distribute free space to flex items with auto margins
We were not applying the distributed space to the used offset of flex items, as we were only assigning the margins to the layout state of the box, not the internal FlexItem::margins.
Diffstat (limited to 'Userland/Libraries/LibWeb')
-rw-r--r--Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp22
-rw-r--r--Userland/Libraries/LibWeb/Layout/FlexFormattingContext.h4
2 files changed, 14 insertions, 12 deletions
diff --git a/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp
index f9726b4dc8..5f5afa99b0 100644
--- a/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp
+++ b/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp
@@ -412,20 +412,22 @@ void FlexFormattingContext::set_offset(Box const& box, float main_offset, float
m_state.get_mutable(box).offset = Gfx::FloatPoint { cross_offset, main_offset };
}
-void FlexFormattingContext::set_main_axis_first_margin(Box const& box, float margin)
+void FlexFormattingContext::set_main_axis_first_margin(FlexItem& item, float margin)
{
+ item.margins.main_before = margin;
if (is_row_layout())
- m_state.get_mutable(box).margin_left = margin;
+ m_state.get_mutable(item.box).margin_left = margin;
else
- m_state.get_mutable(box).margin_top = margin;
+ m_state.get_mutable(item.box).margin_top = margin;
}
-void FlexFormattingContext::set_main_axis_second_margin(Box const& box, float margin)
+void FlexFormattingContext::set_main_axis_second_margin(FlexItem& item, float margin)
{
+ item.margins.main_after = margin;
if (is_row_layout())
- m_state.get_mutable(box).margin_right = margin;
+ m_state.get_mutable(item.box).margin_right = margin;
else
- m_state.get_mutable(box).margin_bottom = margin;
+ m_state.get_mutable(item.box).margin_bottom = margin;
}
float FlexFormattingContext::sum_of_margin_padding_border_in_main_axis(Box const& box) const
@@ -1067,16 +1069,16 @@ void FlexFormattingContext::distribute_any_remaining_free_space()
float size_per_auto_margin = remaining_free_space / (float)auto_margins;
for (auto& flex_item : flex_line.items) {
if (is_main_axis_margin_first_auto(flex_item->box))
- set_main_axis_first_margin(flex_item->box, size_per_auto_margin);
+ set_main_axis_first_margin(*flex_item, size_per_auto_margin);
if (is_main_axis_margin_second_auto(flex_item->box))
- set_main_axis_second_margin(flex_item->box, size_per_auto_margin);
+ set_main_axis_second_margin(*flex_item, size_per_auto_margin);
}
} else {
for (auto& flex_item : flex_line.items) {
if (is_main_axis_margin_first_auto(flex_item->box))
- set_main_axis_first_margin(flex_item->box, 0);
+ set_main_axis_first_margin(*flex_item, 0);
if (is_main_axis_margin_second_auto(flex_item->box))
- set_main_axis_second_margin(flex_item->box, 0);
+ set_main_axis_second_margin(*flex_item, 0);
}
}
diff --git a/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.h b/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.h
index 5a7f87b153..d997bdd973 100644
--- a/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.h
+++ b/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.h
@@ -87,8 +87,8 @@ private:
void set_main_size(Box const&, float size);
void set_cross_size(Box const&, float size);
void set_offset(Box const&, float main_offset, float cross_offset);
- void set_main_axis_first_margin(Box const&, float margin);
- void set_main_axis_second_margin(Box const&, float margin);
+ void set_main_axis_first_margin(FlexItem&, float margin);
+ void set_main_axis_second_margin(FlexItem&, float margin);
void copy_dimensions_from_flex_items_to_boxes();