LibGUI: Factor out Splitter hit testing into a separate function
This commit is contained in:
parent
01cefa83aa
commit
7aa62665a3
Notes:
sideshowbarker
2024-07-19 09:26:47 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/7aa62665a30
2 changed files with 24 additions and 14 deletions
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Reference in a new issue