1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-24 15:37:43 +00:00

LibGUI: Factor out Splitter hit testing into a separate function

This commit is contained in:
Andreas Kling 2020-02-11 10:56:26 +01:00
parent 01cefa83aa
commit 7aa62665a3
2 changed files with 24 additions and 14 deletions

View file

@ -60,29 +60,37 @@ void Splitter::leave_event(Core::Event&)
update(); 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) int x_or_y = position.primary_offset_for_orientation(m_orientation);
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 fudge = layout()->spacing(); int fudge = layout()->spacing();
for_each_child_widget([&](auto& child) { for_each_child_widget([&](auto& child) {
int child_start = child.relative_rect().first_edge_for_orientation(m_orientation); int child_start = child.relative_rect().first_edge_for_orientation(m_orientation);
int child_end = child.relative_rect().last_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) 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) if (x_or_y < child_start && (x_or_y + fudge) >= child_start)
second_resizee = &child; second = &child;
return IterationDecision::Continue; return IterationDecision::Continue;
}); });
ASSERT(first_resizee && second_resizee); ASSERT(first);
m_first_resizee = first_resizee->make_weak_ptr(); ASSERT(second);
m_second_resizee = second_resizee->make_weak_ptr(); }
m_first_resizee_start_size = first_resizee->size();
m_second_resizee_start_size = second_resizee->size(); 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(); m_resize_origin = event.position();
} }

View file

@ -45,6 +45,8 @@ protected:
virtual void leave_event(Core::Event&) override; virtual void leave_event(Core::Event&) override;
private: private:
void get_resize_candidates_at(const Gfx::Point&, Widget*&, Widget*&);
Orientation m_orientation; Orientation m_orientation;
bool m_resizing { false }; bool m_resizing { false };
Gfx::Point m_resize_origin; Gfx::Point m_resize_origin;