diff --git a/doc/classes/SpinBox.xml b/doc/classes/SpinBox.xml index fbcd2fa9a27..c5a39741c6f 100644 --- a/doc/classes/SpinBox.xml +++ b/doc/classes/SpinBox.xml @@ -50,7 +50,8 @@ Changes the alignment of the underlying [LineEdit]. - If not [code]0[/code], [member Range.value] will always be rounded to a multiple of [member custom_arrow_step] when interacting with the arrow buttons of the [SpinBox]. + If not [code]0[/code], sets the step when interacting with the arrow buttons of the [SpinBox]. + [b]Note:[/b] [member Range.value] will still be rounded to a multiple of [member step]. If [code]true[/code], the [SpinBox] will be editable. Otherwise, it will be read only. diff --git a/scene/gui/spin_box.cpp b/scene/gui/spin_box.cpp index 12e02594ea6..f8c97617375 100644 --- a/scene/gui/spin_box.cpp +++ b/scene/gui/spin_box.cpp @@ -144,8 +144,6 @@ void SpinBox::_text_submitted(const String &p_string) { Error err = expr->parse(text); - use_custom_arrow_step = false; - if (err != OK) { // If the expression failed try without converting commas to dots - they might have been for parameter separation. text = p_string; @@ -195,12 +193,12 @@ void SpinBox::_range_click_timeout() { bool mouse_on_up_button = get_local_mouse_position().y < (get_size().height / 2); // Arrow button is being pressed. Snap the value to next step. double temp_step = get_custom_arrow_step() != 0.0 ? get_custom_arrow_step() : get_step(); + temp_step = Math::snapped(temp_step, get_step()); double new_value = _calc_value(get_value(), temp_step); if ((mouse_on_up_button && new_value <= get_value() + CMP_EPSILON) || (!mouse_on_up_button && new_value >= get_value() - CMP_EPSILON)) { new_value = _calc_value(get_value() + (mouse_on_up_button ? temp_step : -temp_step), temp_step); } set_value(new_value); - use_custom_arrow_step = true; if (range_click_timer->is_one_shot()) { range_click_timer->set_wait_time(0.075); @@ -264,12 +262,12 @@ void SpinBox::gui_input(const Ref &p_event) { if (mouse_on_up_button || mouse_on_down_button) { // Arrow button is being pressed. Snap the value to next step. double temp_step = get_custom_arrow_step() != 0.0 ? get_custom_arrow_step() : get_step(); + temp_step = Math::snapped(temp_step, get_step()); double new_value = _calc_value(get_value(), temp_step); if ((mouse_on_up_button && new_value <= get_value() + CMP_EPSILON) || (!mouse_on_up_button && new_value >= get_value() - CMP_EPSILON)) { new_value = _calc_value(get_value() + (mouse_on_up_button ? temp_step : -temp_step), temp_step); } set_value(new_value); - use_custom_arrow_step = true; } state_cache.up_button_pressed = mouse_on_up_button; state_cache.down_button_pressed = mouse_on_down_button; @@ -285,20 +283,17 @@ void SpinBox::gui_input(const Ref &p_event) { case MouseButton::RIGHT: { line_edit->grab_focus(); if (mouse_on_up_button || mouse_on_down_button) { - use_custom_arrow_step = false; set_value(mouse_on_up_button ? get_max() : get_min()); } } break; case MouseButton::WHEEL_UP: { if (line_edit->is_editing()) { - use_custom_arrow_step = false; set_value(get_value() + step * mb->get_factor()); accept_event(); } } break; case MouseButton::WHEEL_DOWN: { if (line_edit->is_editing()) { - use_custom_arrow_step = false; set_value(get_value() - step * mb->get_factor()); accept_event(); } @@ -338,7 +333,6 @@ void SpinBox::gui_input(const Ref &p_event) { if (drag.enabled) { drag.diff_y += mm->get_relative().y; double diff_y = -0.01 * Math::pow(Math::abs(drag.diff_y), 1.8) * SIGN(drag.diff_y); - use_custom_arrow_step = false; set_value(CLAMP(drag.base_val + step * diff_y, get_min(), get_max())); } else if (drag.allowed && drag.capture_pos.distance_to(mm->get_position()) > 2) { Input::get_singleton()->set_mouse_mode(Input::MOUSE_MODE_CAPTURED); diff --git a/scene/gui/spin_box.h b/scene/gui/spin_box.h index 46393fb1844..a8734bee562 100644 --- a/scene/gui/spin_box.h +++ b/scene/gui/spin_box.h @@ -76,7 +76,6 @@ class SpinBox : public Range { String suffix; String last_text_value; double custom_arrow_step = 0.0; - bool use_custom_arrow_step = false; void _line_edit_input(const Ref &p_event);