summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorTobias Christiansen <tobi@tobyase.de>2021-07-16 18:48:08 +0200
committerAli Mohammad Pur <Ali.mpfard@gmail.com>2021-07-19 18:47:09 +0430
commit439d955471538f4f0d77169928eb667e58c8ea82 (patch)
tree53bc5a6c0f8fda373b985cb608dc4931d5222fc3 /Userland
parent80a44c3891684f09a119af0a6a6cdce73a6eca5b (diff)
downloadserenity-439d955471538f4f0d77169928eb667e58c8ea82.zip
LibWeb: Implement justify-content for the FlexFormattingContext
This patch implements the algorithm for placing flex-items on a line according to the specified justify-content property.
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp27
1 files changed, 24 insertions, 3 deletions
diff --git a/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp
index 1c9cb5d431..5ce95b2e06 100644
--- a/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp
+++ b/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp
@@ -646,12 +646,33 @@ void FlexFormattingContext::run(Box& box, LayoutMode)
}
// 12.2.
- // FIXME: Support justify-content
+ float space_between_items = 0;
+ float space_before_first_item = 0;
+ auto number_of_items = flex_line.items.size();
+
+ switch (box.computed_values().justify_content()) {
+ case CSS::JustifyContent::FlexStart:
+ break;
+ case CSS::JustifyContent::FlexEnd:
+ space_before_first_item = main_available_size - used_main_space;
+ break;
+ case CSS::JustifyContent::Center:
+ space_before_first_item = (main_available_size - used_main_space) / 2.0f;
+ break;
+ case CSS::JustifyContent::SpaceBetween:
+ space_between_items = remaining_free_space / (number_of_items - 1);
+ break;
+ case CSS::JustifyContent::SpaceAround:
+ space_between_items = remaining_free_space / number_of_items;
+ space_before_first_item = space_between_items / 2.0f;
+ break;
+ }
+
// FIXME: Support reverse
- float main_offset = 0;
+ float main_offset = space_before_first_item;
for (auto& flex_item : flex_line.items) {
flex_item->main_offset = main_offset;
- main_offset += flex_item->main_size;
+ main_offset += flex_item->main_size + space_between_items;
}
}