diff options
author | Enver Balalic <balalic.enver@gmail.com> | 2022-04-02 11:29:55 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-04-02 19:01:14 +0200 |
commit | 747f347b757bf8c4292e06ab22776b6e657bed37 (patch) | |
tree | 8e7b2fc2e40d521486f2e4aa360fd0aec495b476 /Userland | |
parent | 645d49fa53d9c9d200d9366f0ba337847f113bb7 (diff) | |
download | serenity-747f347b757bf8c4292e06ab22776b6e657bed37.zip |
LibWeb: Implement flex reverse layouts
This builds on the work done by implementing the flex order CSS
property and implements flex reverse layouts by just reversing
the order and the items within each order bucket.
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp | 20 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/Layout/FlexFormattingContext.h | 2 |
2 files changed, 16 insertions, 6 deletions
diff --git a/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp index 74ce0b9afc..de64b3d631 100644 --- a/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp @@ -48,8 +48,6 @@ void FlexFormattingContext::run(Box const& run_box, LayoutMode) // This implements https://www.w3.org/TR/css-flexbox-1/#layout-algorithm - // FIXME: Implement reverse and ordering. - // 1. Generate anonymous flex items generate_anonymous_flex_items(); @@ -203,13 +201,25 @@ void FlexFormattingContext::generate_anonymous_flex_items() }); auto keys = order_item_bucket.keys(); - quick_sort(keys, [](auto& a, auto& b) { return a < b; }); + + if (is_direction_reverse()) { + quick_sort(keys, [](auto& a, auto& b) { return a > b; }); + } else { + quick_sort(keys, [](auto& a, auto& b) { return a < b; }); + } for (auto key : keys) { auto order_bucket = order_item_bucket.get(key); if (order_bucket.has_value()) { - for (auto flex_item : order_bucket.value()) { - m_flex_items.append(move(flex_item)); + auto items = order_bucket.value(); + if (is_direction_reverse()) { + for (auto flex_item : items.in_reverse()) { + m_flex_items.append(move(flex_item)); + } + } else { + for (auto flex_item : items) { + m_flex_items.append(move(flex_item)); + } } } } diff --git a/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.h b/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.h index d6d50bb2a1..71b28718be 100644 --- a/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.h +++ b/Userland/Libraries/LibWeb/Layout/FlexFormattingContext.h @@ -118,7 +118,7 @@ private: bool is_row_layout() const { return m_flex_direction == CSS::FlexDirection::Row || m_flex_direction == CSS::FlexDirection::RowReverse; } bool is_single_line() const { return flex_container().computed_values().flex_wrap() == CSS::FlexWrap::Nowrap; } - + bool is_direction_reverse() const { return m_flex_direction == CSS::FlexDirection::ColumnReverse || m_flex_direction == CSS::FlexDirection::RowReverse; } void populate_specified_margins(FlexItem&, CSS::FlexDirection) const; FormattingState::NodeState& m_flex_container_state; |