@@ -41,7 +41,11 @@ Size2 SpinBox::get_minimum_size() const {
41
41
}
42
42
43
43
void SpinBox::_update_text (bool p_keep_line_edit) {
44
- String value = String::num (get_value (), Math::range_step_decimals (get_step ()));
44
+ double step = get_step ();
45
+ if (use_custom_arrow_step && custom_arrow_step != 0.0 ) {
46
+ step = custom_arrow_step;
47
+ }
48
+ String value = String::num (get_value (), Math::range_step_decimals (step));
45
49
if (is_localizing_numeral_system ()) {
46
50
value = TS->format_number (value);
47
51
}
@@ -75,6 +79,9 @@ void SpinBox::_text_submitted(const String &p_string) {
75
79
text = text.trim_prefix (prefix + " " ).trim_suffix (" " + suffix);
76
80
77
81
Error err = expr->parse (text);
82
+
83
+ use_custom_arrow_step = false ;
84
+
78
85
if (err != OK) {
79
86
// If the expression failed try without converting commas to dots - they might have been for parameter separation.
80
87
text = p_string;
@@ -114,8 +121,13 @@ void SpinBox::_line_edit_input(const Ref<InputEvent> &p_event) {
114
121
void SpinBox::_range_click_timeout () {
115
122
if (!drag.enabled && Input::get_singleton ()->is_mouse_button_pressed (MouseButton::LEFT)) {
116
123
bool up = get_local_mouse_position ().y < (get_size ().height / 2 );
117
- double step = get_custom_arrow_step () != 0.0 ? get_custom_arrow_step () : get_step ();
118
- set_value (get_value () + (up ? step : -step));
124
+ double step = get_step ();
125
+ // Arrow button is being pressed, so we also need to set the step to the same value as custom_arrow_step if its not 0.
126
+ double temp_step = get_custom_arrow_step () != 0.0 ? get_custom_arrow_step () : get_step ();
127
+ _set_step_no_signal (temp_step);
128
+ set_value (get_value () + (up ? temp_step : -temp_step));
129
+ _set_step_no_signal (step);
130
+ use_custom_arrow_step = true ;
119
131
120
132
if (range_click_timer->is_one_shot ()) {
121
133
range_click_timer->set_wait_time (0.075 );
@@ -156,8 +168,7 @@ void SpinBox::gui_input(const Ref<InputEvent> &p_event) {
156
168
Ref<InputEventMouseButton> mb = p_event;
157
169
Ref<InputEventMouseMotion> mm = p_event;
158
170
159
- double step = get_custom_arrow_step () != 0.0 ? get_custom_arrow_step () : get_step ();
160
-
171
+ double step = get_step ();
161
172
Vector2 mpos;
162
173
bool mouse_on_up_button = false ;
163
174
bool mouse_on_down_button = false ;
@@ -177,7 +188,12 @@ void SpinBox::gui_input(const Ref<InputEvent> &p_event) {
177
188
line_edit->grab_focus ();
178
189
179
190
if (mouse_on_up_button || mouse_on_down_button) {
180
- set_value (get_value () + (mouse_on_up_button ? step : -step));
191
+ // Arrow button is being pressed, so step is being changed temporarily.
192
+ double temp_step = get_custom_arrow_step () != 0.0 ? get_custom_arrow_step () : get_step ();
193
+ _set_step_no_signal (temp_step);
194
+ set_value (get_value () + (mouse_on_up_button ? temp_step : -temp_step));
195
+ _set_step_no_signal (step);
196
+ use_custom_arrow_step = true ;
181
197
}
182
198
state_cache.up_button_pressed = mouse_on_up_button;
183
199
state_cache.down_button_pressed = mouse_on_down_button;
@@ -193,17 +209,20 @@ void SpinBox::gui_input(const Ref<InputEvent> &p_event) {
193
209
case MouseButton::RIGHT: {
194
210
line_edit->grab_focus ();
195
211
if (mouse_on_up_button || mouse_on_down_button) {
212
+ use_custom_arrow_step = false ;
196
213
set_value (mouse_on_up_button ? get_max () : get_min ());
197
214
}
198
215
} break ;
199
216
case MouseButton::WHEEL_UP: {
200
217
if (line_edit->is_editing ()) {
218
+ use_custom_arrow_step = false ;
201
219
set_value (get_value () + step * mb->get_factor ());
202
220
accept_event ();
203
221
}
204
222
} break ;
205
223
case MouseButton::WHEEL_DOWN: {
206
224
if (line_edit->is_editing ()) {
225
+ use_custom_arrow_step = false ;
207
226
set_value (get_value () - step * mb->get_factor ());
208
227
accept_event ();
209
228
}
@@ -243,6 +262,7 @@ void SpinBox::gui_input(const Ref<InputEvent> &p_event) {
243
262
if (drag.enabled ) {
244
263
drag.diff_y += mm->get_relative ().y ;
245
264
double diff_y = -0.01 * Math::pow (ABS (drag.diff_y ), 1.8 ) * SIGN (drag.diff_y );
265
+ use_custom_arrow_step = false ;
246
266
set_value (CLAMP (drag.base_val + step * diff_y, get_min (), get_max ()));
247
267
} else if (drag.allowed && drag.capture_pos .distance_to (mm->get_position ()) > 2 ) {
248
268
Input::get_singleton ()->set_mouse_mode (Input::MOUSE_MODE_CAPTURED);
@@ -519,6 +539,12 @@ void SpinBox::_update_buttons_state_for_current_value() {
519
539
}
520
540
}
521
541
542
+ void SpinBox::_set_step_no_signal (double p_step) {
543
+ set_block_signals (true );
544
+ set_step (p_step);
545
+ set_block_signals (false );
546
+ }
547
+
522
548
void SpinBox::_bind_methods () {
523
549
ClassDB::bind_method (D_METHOD (" set_horizontal_alignment" , " alignment" ), &SpinBox::set_horizontal_alignment);
524
550
ClassDB::bind_method (D_METHOD (" get_horizontal_alignment" ), &SpinBox::get_horizontal_alignment);
0 commit comments