From 34c96280d7686444321590bceff4dc5b2c95cdc7 Mon Sep 17 00:00:00 2001 From: FrHun <28605587+frhun@users.noreply.github.com> Date: Sun, 12 Jun 2022 23:37:57 +0200 Subject: [PATCH] LibGUI: Use new layout system in Splitter --- Userland/Libraries/LibGUI/Splitter.cpp | 30 ++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/Userland/Libraries/LibGUI/Splitter.cpp b/Userland/Libraries/LibGUI/Splitter.cpp index 83ffdd4064..ade4ab746f 100644 --- a/Userland/Libraries/LibGUI/Splitter.cpp +++ b/Userland/Libraries/LibGUI/Splitter.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include @@ -190,6 +191,7 @@ void Splitter::recompute_grabbables() set_hovered_grabbable(&m_grabbables[old_hovered_index.value()]); } +// FIXME: Respect the child widgets min and max sizes void Splitter::mousemove_event(MouseEvent& event) { auto* grabbable = grabbable_at(event.position()); @@ -222,11 +224,27 @@ void Splitter::mousemove_event(MouseEvent& event) } if (m_orientation == Orientation::Horizontal) { - m_first_resizee->set_fixed_width(fixed_resizee() == FixedResizee::First ? new_first_resizee_size.width() : -1); - m_second_resizee->set_fixed_width(fixed_resizee() == FixedResizee::Second ? new_second_resizee_size.width() : -1); + if (fixed_resizee() == FixedResizee::First) { + m_first_resizee->set_fixed_width(new_first_resizee_size.width()); + m_second_resizee->set_min_width(SpecialDimension::Shrink); + m_second_resizee->set_max_width(SpecialDimension::Grow); + } else { + VERIFY(fixed_resizee() == FixedResizee::Second); + m_second_resizee->set_fixed_width(new_second_resizee_size.width()); + m_first_resizee->set_min_width(SpecialDimension::Shrink); + m_first_resizee->set_max_width(SpecialDimension::Grow); + } } else { - m_first_resizee->set_fixed_height(fixed_resizee() == FixedResizee::First ? new_first_resizee_size.height() : -1); - m_second_resizee->set_fixed_height(fixed_resizee() == FixedResizee::Second ? new_second_resizee_size.height() : -1); + if (fixed_resizee() == FixedResizee::First) { + m_first_resizee->set_fixed_height(new_first_resizee_size.height()); + m_second_resizee->set_min_height(SpecialDimension::Shrink); + m_second_resizee->set_max_height(SpecialDimension::Grow); + } else { + VERIFY(fixed_resizee() == FixedResizee::Second); + m_second_resizee->set_fixed_height(new_second_resizee_size.height()); + m_first_resizee->set_min_height(SpecialDimension::Shrink); + m_first_resizee->set_max_height(SpecialDimension::Grow); + } } invalidate_layout(); @@ -248,13 +266,13 @@ void Splitter::custom_layout() if (m_last_child_count > child_widgets.size()) { bool has_child_to_fill_space = false; for (auto& child : child_widgets) { - if (child.max_size() == Gfx::IntSize { -1, -1 }) { + if (child.max_size().primary_size_for_orientation(m_orientation).is_grow()) { has_child_to_fill_space = true; break; } } if (!has_child_to_fill_space) - child_widgets.last().set_fixed_size({ -1, -1 }); + child_widgets.last().set_preferred_size(SpecialDimension::Grow); } }