Add drag start/end signals for Slider
(cherry picked from commit 753ae7403f
)
This commit is contained in:
parent
0b6b2015f0
commit
4621b41bfc
2 changed files with 21 additions and 0 deletions
|
@ -27,6 +27,19 @@
|
||||||
If [code]true[/code], the slider will display ticks for minimum and maximum values.
|
If [code]true[/code], the slider will display ticks for minimum and maximum values.
|
||||||
</member>
|
</member>
|
||||||
</members>
|
</members>
|
||||||
|
<signals>
|
||||||
|
<signal name="drag_ended">
|
||||||
|
<argument index="0" name="value_changed" type="bool" />
|
||||||
|
<description>
|
||||||
|
Emitted when dragging stops. If [code]value_changed[/code] is true, [member Range.value] is different from the value when you started the dragging.
|
||||||
|
</description>
|
||||||
|
</signal>
|
||||||
|
<signal name="drag_started">
|
||||||
|
<description>
|
||||||
|
Emitted when dragging is started.
|
||||||
|
</description>
|
||||||
|
</signal>
|
||||||
|
</signals>
|
||||||
<constants>
|
<constants>
|
||||||
</constants>
|
</constants>
|
||||||
</class>
|
</class>
|
||||||
|
|
|
@ -68,8 +68,13 @@ void Slider::_gui_input(Ref<InputEvent> p_event) {
|
||||||
}
|
}
|
||||||
grab.active = true;
|
grab.active = true;
|
||||||
grab.uvalue = get_as_ratio();
|
grab.uvalue = get_as_ratio();
|
||||||
|
|
||||||
|
emit_signal("drag_started");
|
||||||
} else {
|
} else {
|
||||||
grab.active = false;
|
grab.active = false;
|
||||||
|
|
||||||
|
const bool value_changed = !Math::is_equal_approx((double)grab.uvalue, get_as_ratio());
|
||||||
|
emit_signal("drag_ended", value_changed);
|
||||||
}
|
}
|
||||||
} else if (scrollable) {
|
} else if (scrollable) {
|
||||||
if (mb->is_pressed() && mb->get_button_index() == BUTTON_WHEEL_UP) {
|
if (mb->is_pressed() && mb->get_button_index() == BUTTON_WHEEL_UP) {
|
||||||
|
@ -263,6 +268,9 @@ void Slider::_bind_methods() {
|
||||||
ClassDB::bind_method(D_METHOD("set_scrollable", "scrollable"), &Slider::set_scrollable);
|
ClassDB::bind_method(D_METHOD("set_scrollable", "scrollable"), &Slider::set_scrollable);
|
||||||
ClassDB::bind_method(D_METHOD("is_scrollable"), &Slider::is_scrollable);
|
ClassDB::bind_method(D_METHOD("is_scrollable"), &Slider::is_scrollable);
|
||||||
|
|
||||||
|
ADD_SIGNAL(MethodInfo("drag_started"));
|
||||||
|
ADD_SIGNAL(MethodInfo("drag_ended", PropertyInfo(Variant::BOOL, "value_changed")));
|
||||||
|
|
||||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "editable"), "set_editable", "is_editable");
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "editable"), "set_editable", "is_editable");
|
||||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "scrollable"), "set_scrollable", "is_scrollable");
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "scrollable"), "set_scrollable", "is_scrollable");
|
||||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "tick_count", PROPERTY_HINT_RANGE, "0,4096,1"), "set_ticks", "get_ticks");
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "tick_count", PROPERTY_HINT_RANGE, "0,4096,1"), "set_ticks", "get_ticks");
|
||||||
|
|
Loading…
Reference in a new issue