From e5647e2ddf721043e7dec78b975a69ada4e20e13 Mon Sep 17 00:00:00 2001 From: Jelle Raaijmakers Date: Thu, 13 May 2021 01:25:31 +0200 Subject: [PATCH] LibGUI/Splitter: Support setting minimum resizee size --- Userland/Libraries/LibGUI/Splitter.cpp | 12 +++++++----- Userland/Libraries/LibGUI/Splitter.h | 7 +++++++ 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/Userland/Libraries/LibGUI/Splitter.cpp b/Userland/Libraries/LibGUI/Splitter.cpp index 6708ecfb68..764a701fec 100644 --- a/Userland/Libraries/LibGUI/Splitter.cpp +++ b/Userland/Libraries/LibGUI/Splitter.cpp @@ -18,6 +18,9 @@ namespace GUI { Splitter::Splitter(Orientation orientation) : m_orientation(orientation) { + REGISTER_INT_PROPERTY("first_resizee_minimum_size", first_resizee_minimum_size, set_first_resizee_minimum_size); + REGISTER_INT_PROPERTY("second_resizee_minimum_size", second_resizee_minimum_size, set_second_resizee_minimum_size); + set_background_role(ColorRole::Button); set_layout(orientation); set_fill_with_background_color(true); @@ -149,20 +152,19 @@ void Splitter::mousemove_event(MouseEvent& event) m_resizing = false; return; } - int minimum_size = 0; auto new_first_resizee_size = m_first_resizee_start_size; auto new_second_resizee_size = m_second_resizee_start_size; new_first_resizee_size.set_primary_size_for_orientation(m_orientation, new_first_resizee_size.primary_size_for_orientation(m_orientation) + delta.primary_offset_for_orientation(m_orientation)); new_second_resizee_size.set_primary_size_for_orientation(m_orientation, new_second_resizee_size.primary_size_for_orientation(m_orientation) - delta.primary_offset_for_orientation(m_orientation)); - if (new_first_resizee_size.primary_size_for_orientation(m_orientation) < minimum_size) { - int correction = minimum_size - new_first_resizee_size.primary_size_for_orientation(m_orientation); + if (new_first_resizee_size.primary_size_for_orientation(m_orientation) < m_first_resizee_minimum_size) { + int correction = m_first_resizee_minimum_size - new_first_resizee_size.primary_size_for_orientation(m_orientation); new_first_resizee_size.set_primary_size_for_orientation(m_orientation, new_first_resizee_size.primary_size_for_orientation(m_orientation) + correction); new_second_resizee_size.set_primary_size_for_orientation(m_orientation, new_second_resizee_size.primary_size_for_orientation(m_orientation) - correction); } - if (new_second_resizee_size.primary_size_for_orientation(m_orientation) < minimum_size) { - int correction = minimum_size - new_second_resizee_size.primary_size_for_orientation(m_orientation); + if (new_second_resizee_size.primary_size_for_orientation(m_orientation) < m_second_resizee_minimum_size) { + int correction = m_second_resizee_minimum_size - new_second_resizee_size.primary_size_for_orientation(m_orientation); new_second_resizee_size.set_primary_size_for_orientation(m_orientation, new_second_resizee_size.primary_size_for_orientation(m_orientation) + correction); new_first_resizee_size.set_primary_size_for_orientation(m_orientation, new_first_resizee_size.primary_size_for_orientation(m_orientation) - correction); } diff --git a/Userland/Libraries/LibGUI/Splitter.h b/Userland/Libraries/LibGUI/Splitter.h index 663f15b0ea..66283df6ee 100644 --- a/Userland/Libraries/LibGUI/Splitter.h +++ b/Userland/Libraries/LibGUI/Splitter.h @@ -16,6 +16,11 @@ class Splitter : public Widget { public: virtual ~Splitter() override; + int first_resizee_minimum_size() { return m_first_resizee_minimum_size; } + void set_first_resizee_minimum_size(int minimum_size) { m_first_resizee_minimum_size = minimum_size; } + int second_resizee_minimum_size() { return m_second_resizee_minimum_size; } + void set_second_resizee_minimum_size(int minimum_size) { m_second_resizee_minimum_size = minimum_size; } + protected: explicit Splitter(Gfx::Orientation); @@ -41,6 +46,8 @@ private: WeakPtr m_second_resizee; Gfx::IntSize m_first_resizee_start_size; Gfx::IntSize m_second_resizee_start_size; + int m_first_resizee_minimum_size { 0 }; + int m_second_resizee_minimum_size { 0 }; Gfx::IntRect m_grabbable_rect; };