summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorZaggy1024 <zaggy1024@gmail.com>2023-02-05 19:19:31 -0600
committerSam Atkins <atkinssj@gmail.com>2023-02-07 14:36:58 +0000
commitd9a73bbc96745263ac33134b5f9341fd0006255c (patch)
treede7048222aba2f4ab4773bbcb6864ec7d74dc0be /Userland
parentfa98c43c0d40f8b85b5e65448f45fa20329f6f71 (diff)
downloadserenity-d9a73bbc96745263ac33134b5f9341fd0006255c.zip
LibGUI: Add callbacks for Slider drags starting and ending
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Libraries/LibGUI/Slider.cpp9
-rw-r--r--Userland/Libraries/LibGUI/Slider.h3
2 files changed, 11 insertions, 1 deletions
diff --git a/Userland/Libraries/LibGUI/Slider.cpp b/Userland/Libraries/LibGUI/Slider.cpp
index ce4c14217e..0f9a641c64 100644
--- a/Userland/Libraries/LibGUI/Slider.cpp
+++ b/Userland/Libraries/LibGUI/Slider.cpp
@@ -82,6 +82,8 @@ void Slider::start_drag(Gfx::IntPoint start_position)
m_dragging = true;
m_drag_origin = start_position;
m_drag_origin_value = value();
+ if (on_drag_start)
+ on_drag_start();
}
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));
- set_value(new_value);
+ set_value(new_value, AllowCallback::No);
start_drag(event.position());
+ // Delay the callback to make it aware that a drag has started.
+ if (on_change)
+ on_change(new_value);
return;
}
@@ -136,6 +141,8 @@ void Slider::end_drag()
{
if (m_dragging) {
m_dragging = false;
+ if (on_drag_end)
+ on_drag_end();
}
}
diff --git a/Userland/Libraries/LibGUI/Slider.h b/Userland/Libraries/LibGUI/Slider.h
index 56be2641eb..a2f3cfd800 100644
--- a/Userland/Libraries/LibGUI/Slider.h
+++ b/Userland/Libraries/LibGUI/Slider.h
@@ -40,6 +40,9 @@ public:
return rect().shrunken(0, track_margin() * 2);
}
+ Function<void()> on_drag_start;
+ Function<void()> on_drag_end;
+
protected:
explicit Slider(Orientation = Orientation::Vertical);