From b7fbdf4bed156ff319b569c557a1e5710a351c8c Mon Sep 17 00:00:00 2001 From: Eric M Date: Wed, 6 May 2020 10:38:15 +1000 Subject: [PATCH] Updated editor spin slider to have better behaviour and adjusted control's size_flags_stretch_ratio value range (cherry picked from commit 915ab50673e9ee2304716b2094edf17f1a8adfef) --- editor/editor_spin_slider.cpp | 17 +++++++++++++++++ scene/gui/control.cpp | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/editor/editor_spin_slider.cpp b/editor/editor_spin_slider.cpp index 5db18d8853d..b16e8571870 100644 --- a/editor/editor_spin_slider.cpp +++ b/editor/editor_spin_slider.cpp @@ -34,6 +34,9 @@ #include "editor_scale.h" String EditorSpinSlider::get_tooltip(const Point2 &p_pos) const { + if (grabber->is_visible()) { + return rtos(get_value()) + "\n\n" + TTR("Hold Ctrl to round to integers. Hold Shift for more precise changes."); + } return rtos(get_value()); } @@ -109,7 +112,21 @@ void EditorSpinSlider::_gui_input(const Ref &p_event) { } if (grabbing_spinner) { + // Don't make the user scroll all the way back to 'in range' if they went off the end. + if (pre_grab_value < get_min() && !is_lesser_allowed()) { + pre_grab_value = get_min(); + } + if (pre_grab_value > get_max() && !is_greater_allowed()) { + pre_grab_value = get_max(); + } + if (mm->get_control()) { + // If control was just pressed, don't make the value do a huge jump in magnitude. + if (grabbing_spinner_dist_cache != 0) { + pre_grab_value += grabbing_spinner_dist_cache * get_step(); + grabbing_spinner_dist_cache = 0; + } + set_value(Math::round(pre_grab_value + get_step() * grabbing_spinner_dist_cache * 10)); } else { set_value(pre_grab_value + get_step() * grabbing_spinner_dist_cache); diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp index ae48a1356e6..a96f2b7b804 100644 --- a/scene/gui/control.cpp +++ b/scene/gui/control.cpp @@ -3008,7 +3008,7 @@ void Control::_bind_methods() { ADD_GROUP("Size Flags", "size_flags_"); ADD_PROPERTY(PropertyInfo(Variant::INT, "size_flags_horizontal", PROPERTY_HINT_FLAGS, "Fill,Expand,Shrink Center,Shrink End"), "set_h_size_flags", "get_h_size_flags"); ADD_PROPERTY(PropertyInfo(Variant::INT, "size_flags_vertical", PROPERTY_HINT_FLAGS, "Fill,Expand,Shrink Center,Shrink End"), "set_v_size_flags", "get_v_size_flags"); - ADD_PROPERTY(PropertyInfo(Variant::REAL, "size_flags_stretch_ratio", PROPERTY_HINT_RANGE, "0,128,0.01"), "set_stretch_ratio", "get_stretch_ratio"); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "size_flags_stretch_ratio", PROPERTY_HINT_RANGE, "0,20,0.01,or_greater"), "set_stretch_ratio", "get_stretch_ratio"); ADD_GROUP("Theme", ""); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "theme", PROPERTY_HINT_RESOURCE_TYPE, "Theme"), "set_theme", "get_theme"); ADD_GROUP("", "");