diff options
author | Haoyu Qiu <timothyqiu32@gmail.com> | 2023-12-21 11:23:35 +0800 |
---|---|---|
committer | Haoyu Qiu <timothyqiu32@gmail.com> | 2023-12-21 11:23:35 +0800 |
commit | 58db3e5d7be22ca73175b873e29cfa984dfafcd4 (patch) | |
tree | 16fc33d419dd44caf08b14e9481e08a018c0ba8f | |
parent | 9d1cbab1c432b6f1d66ec939445bec68b6af519e (diff) | |
download | redot-engine-58db3e5d7be22ca73175b873e29cfa984dfafcd4.tar.gz |
Emit slider's drag_started signal before the first value change
-rw-r--r-- | doc/classes/Slider.xml | 2 | ||||
-rw-r--r-- | scene/gui/slider.cpp | 5 | ||||
-rw-r--r-- | scene/gui/slider.h | 3 |
3 files changed, 6 insertions, 4 deletions
diff --git a/doc/classes/Slider.xml b/doc/classes/Slider.xml index 0471b8c275..492b6164bf 100644 --- a/doc/classes/Slider.xml +++ b/doc/classes/Slider.xml @@ -33,7 +33,7 @@ </signal> <signal name="drag_started"> <description> - Emitted when dragging is started. + Emitted when dragging is started. This is emitted before the corresponding [signal Range.value_changed] signal. </description> </signal> </signals> diff --git a/scene/gui/slider.cpp b/scene/gui/slider.cpp index 586334a0b4..69d281e373 100644 --- a/scene/gui/slider.cpp +++ b/scene/gui/slider.cpp @@ -64,6 +64,8 @@ void Slider::gui_input(const Ref<InputEvent> &p_event) { } grab.pos = orientation == VERTICAL ? mb->get_position().y : mb->get_position().x; + grab.value_before_dragging = get_as_ratio(); + emit_signal(SNAME("drag_started")); double grab_width = (double)grabber->get_width(); double grab_height = (double)grabber->get_height(); @@ -78,12 +80,11 @@ void Slider::gui_input(const Ref<InputEvent> &p_event) { grab.active = true; grab.uvalue = get_as_ratio(); - emit_signal(SNAME("drag_started")); _notify_shared_value_changed(); } else { grab.active = false; - const bool value_changed = !Math::is_equal_approx((double)grab.uvalue, get_as_ratio()); + const bool value_changed = !Math::is_equal_approx((double)grab.value_before_dragging, get_as_ratio()); emit_signal(SNAME("drag_ended"), value_changed); } } else if (scrollable) { diff --git a/scene/gui/slider.h b/scene/gui/slider.h index 05766fa742..07c1d23e32 100644 --- a/scene/gui/slider.h +++ b/scene/gui/slider.h @@ -38,7 +38,8 @@ class Slider : public Range { struct Grab { int pos = 0; - double uvalue = 0.0; + double uvalue = 0.0; // Value at `pos`. + double value_before_dragging = 0.0; bool active = false; } grab; |