1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-19 07:57:34 +00:00

LibGUI: Add callbacks for Slider drags starting and ending

This commit is contained in:
Zaggy1024 2023-02-05 19:19:31 -06:00 committed by Sam Atkins
parent fa98c43c0d
commit d9a73bbc96
2 changed files with 11 additions and 1 deletions

View file

@ -82,6 +82,8 @@ void Slider::start_drag(Gfx::IntPoint start_position)
m_dragging = true; m_dragging = true;
m_drag_origin = start_position; m_drag_origin = start_position;
m_drag_origin_value = value(); m_drag_origin_value = value();
if (on_drag_start)
on_drag_start();
} }
void Slider::mousedown_event(MouseEvent& event) void Slider::mousedown_event(MouseEvent& event)
@ -98,8 +100,11 @@ void Slider::mousedown_event(MouseEvent& event)
} }
int new_value = static_cast<int>(min() + ((max() - min()) * normalized_mouse_offset)); int new_value = static_cast<int>(min() + ((max() - min()) * normalized_mouse_offset));
set_value(new_value); set_value(new_value, AllowCallback::No);
start_drag(event.position()); start_drag(event.position());
// Delay the callback to make it aware that a drag has started.
if (on_change)
on_change(new_value);
return; return;
} }
@ -136,6 +141,8 @@ void Slider::end_drag()
{ {
if (m_dragging) { if (m_dragging) {
m_dragging = false; m_dragging = false;
if (on_drag_end)
on_drag_end();
} }
} }

View file

@ -40,6 +40,9 @@ public:
return rect().shrunken(0, track_margin() * 2); return rect().shrunken(0, track_margin() * 2);
} }
Function<void()> on_drag_start;
Function<void()> on_drag_end;
protected: protected:
explicit Slider(Orientation = Orientation::Vertical); explicit Slider(Orientation = Orientation::Vertical);