Skip to content

Commit c6be28a

Browse files
committed
Fix SpinBox value change when held down on separation between buttons
1 parent 825ef23 commit c6be28a

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

scene/gui/spin_box.cpp

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -190,15 +190,24 @@ void SpinBox::_line_edit_input(const Ref<InputEvent> &p_event) {
190190

191191
void SpinBox::_range_click_timeout() {
192192
if (!drag.enabled && Input::get_singleton()->is_mouse_button_pressed(MouseButton::LEFT)) {
193-
bool mouse_on_up_button = get_local_mouse_position().y < (get_size().height / 2);
194-
// Arrow button is being pressed. Snap the value to next step.
195-
double temp_step = get_custom_arrow_step() != 0.0 ? get_custom_arrow_step() : get_step();
196-
temp_step = Math::snapped(temp_step, get_step());
197-
double new_value = _calc_value(get_value(), temp_step);
198-
if ((mouse_on_up_button && new_value <= get_value() + CMP_EPSILON) || (!mouse_on_up_button && new_value >= get_value() - CMP_EPSILON)) {
199-
new_value = _calc_value(get_value() + (mouse_on_up_button ? temp_step : -temp_step), temp_step);
193+
Rect2 up_button_rc = Rect2(sizing_cache.buttons_left, 0, sizing_cache.buttons_width, sizing_cache.button_up_height);
194+
Rect2 down_button_rc = Rect2(sizing_cache.buttons_left, sizing_cache.second_button_top, sizing_cache.buttons_width, sizing_cache.button_down_height);
195+
196+
Vector2 mpos = get_local_mouse_position();
197+
198+
bool mouse_on_up_button = up_button_rc.has_point(mpos);
199+
bool mouse_on_down_button = down_button_rc.has_point(mpos);
200+
201+
if (mouse_on_up_button || mouse_on_down_button) {
202+
// Arrow button is being pressed. Snap the value to next step.
203+
double temp_step = get_custom_arrow_step() != 0.0 ? get_custom_arrow_step() : get_step();
204+
temp_step = Math::snapped(temp_step, get_step());
205+
double new_value = _calc_value(get_value(), temp_step);
206+
if ((mouse_on_up_button && new_value <= get_value() + CMP_EPSILON) || (!mouse_on_up_button && new_value >= get_value() - CMP_EPSILON)) {
207+
new_value = _calc_value(get_value() + (mouse_on_up_button ? temp_step : -temp_step), temp_step);
208+
}
209+
set_value(new_value);
200210
}
201-
set_value(new_value);
202211

203212
if (range_click_timer->is_one_shot()) {
204213
range_click_timer->set_wait_time(0.075);

0 commit comments

Comments
 (0)