Emit slider's drag_started signal before the first value change
This commit is contained in:
parent
9d1cbab1c4
commit
58db3e5d7b
3 changed files with 6 additions and 4 deletions
|
@ -33,7 +33,7 @@
|
||||||
</signal>
|
</signal>
|
||||||
<signal name="drag_started">
|
<signal name="drag_started">
|
||||||
<description>
|
<description>
|
||||||
Emitted when dragging is started.
|
Emitted when dragging is started. This is emitted before the corresponding [signal Range.value_changed] signal.
|
||||||
</description>
|
</description>
|
||||||
</signal>
|
</signal>
|
||||||
</signals>
|
</signals>
|
||||||
|
|
|
@ -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.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_width = (double)grabber->get_width();
|
||||||
double grab_height = (double)grabber->get_height();
|
double grab_height = (double)grabber->get_height();
|
||||||
|
@ -78,12 +80,11 @@ void Slider::gui_input(const Ref<InputEvent> &p_event) {
|
||||||
grab.active = true;
|
grab.active = true;
|
||||||
grab.uvalue = get_as_ratio();
|
grab.uvalue = get_as_ratio();
|
||||||
|
|
||||||
emit_signal(SNAME("drag_started"));
|
|
||||||
_notify_shared_value_changed();
|
_notify_shared_value_changed();
|
||||||
} else {
|
} else {
|
||||||
grab.active = false;
|
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);
|
emit_signal(SNAME("drag_ended"), value_changed);
|
||||||
}
|
}
|
||||||
} else if (scrollable) {
|
} else if (scrollable) {
|
||||||
|
|
|
@ -38,7 +38,8 @@ class Slider : public Range {
|
||||||
|
|
||||||
struct Grab {
|
struct Grab {
|
||||||
int pos = 0;
|
int pos = 0;
|
||||||
double uvalue = 0.0;
|
double uvalue = 0.0; // Value at `pos`.
|
||||||
|
double value_before_dragging = 0.0;
|
||||||
bool active = false;
|
bool active = false;
|
||||||
} grab;
|
} grab;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue