diff options
author | Andreas Kling <kling@serenityos.org> | 2020-02-11 10:56:26 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-02-11 11:53:38 +0100 |
commit | 7aa62665a304be74b780f91cf8b06c8fd9203e2a (patch) | |
tree | 002f5ad889c680a9c88c4fe72f15aee9b4071f8e /Libraries | |
parent | 01cefa83aa1d5444ce917ca98e5888aa50a9f815 (diff) | |
download | serenity-7aa62665a304be74b780f91cf8b06c8fd9203e2a.zip |
LibGUI: Factor out Splitter hit testing into a separate function
Diffstat (limited to 'Libraries')
-rw-r--r-- | Libraries/LibGUI/Splitter.cpp | 36 | ||||
-rw-r--r-- | Libraries/LibGUI/Splitter.h | 2 |
2 files changed, 24 insertions, 14 deletions
diff --git a/Libraries/LibGUI/Splitter.cpp b/Libraries/LibGUI/Splitter.cpp index a319266017..8783301267 100644 --- a/Libraries/LibGUI/Splitter.cpp +++ b/Libraries/LibGUI/Splitter.cpp @@ -60,29 +60,37 @@ void Splitter::leave_event(Core::Event&) update(); } -void Splitter::mousedown_event(MouseEvent& event) +void Splitter::get_resize_candidates_at(const Gfx::Point& position, Widget*& first, Widget*& second) { - if (event.button() != MouseButton::Left) - return; - m_resizing = true; - int x_or_y = event.position().primary_offset_for_orientation(m_orientation); - Widget* first_resizee { nullptr }; - Widget* second_resizee { nullptr }; + int x_or_y = position.primary_offset_for_orientation(m_orientation); int fudge = layout()->spacing(); for_each_child_widget([&](auto& child) { int child_start = child.relative_rect().first_edge_for_orientation(m_orientation); int child_end = child.relative_rect().last_edge_for_orientation(m_orientation); if (x_or_y > child_end && (x_or_y - fudge) <= child_end) - first_resizee = &child; + first = &child; if (x_or_y < child_start && (x_or_y + fudge) >= child_start) - second_resizee = &child; + second = &child; return IterationDecision::Continue; }); - ASSERT(first_resizee && second_resizee); - m_first_resizee = first_resizee->make_weak_ptr(); - m_second_resizee = second_resizee->make_weak_ptr(); - m_first_resizee_start_size = first_resizee->size(); - m_second_resizee_start_size = second_resizee->size(); + ASSERT(first); + ASSERT(second); +} + +void Splitter::mousedown_event(MouseEvent& event) +{ + if (event.button() != MouseButton::Left) + return; + m_resizing = true; + + Widget* first { nullptr }; + Widget* second { nullptr }; + get_resize_candidates_at(event.position(), first, second); + + m_first_resizee = first->make_weak_ptr(); + m_second_resizee = second->make_weak_ptr(); + m_first_resizee_start_size = first->size(); + m_second_resizee_start_size = second->size(); m_resize_origin = event.position(); } diff --git a/Libraries/LibGUI/Splitter.h b/Libraries/LibGUI/Splitter.h index 15b1a6f9e7..4cf876648c 100644 --- a/Libraries/LibGUI/Splitter.h +++ b/Libraries/LibGUI/Splitter.h @@ -45,6 +45,8 @@ protected: virtual void leave_event(Core::Event&) override; private: + void get_resize_candidates_at(const Gfx::Point&, Widget*&, Widget*&); + Orientation m_orientation; bool m_resizing { false }; Gfx::Point m_resize_origin; |