Fix Spinbox display does not round properly when using decimal custom arrow steps
This commit is contained in:
parent
76a135926a
commit
b75efcee95
|
@ -41,7 +41,13 @@ Size2 SpinBox::get_minimum_size() const {
|
|||
}
|
||||
|
||||
void SpinBox::_update_text(bool p_keep_line_edit) {
|
||||
String value = String::num(get_value(), Math::range_step_decimals(get_step()));
|
||||
double step = 0.0;
|
||||
if (get_step() != 0.0 && ((get_custom_arrow_step() == 0.0) != (get_step() < get_custom_arrow_step()))) {
|
||||
step = get_step();
|
||||
} else {
|
||||
step = get_custom_arrow_step();
|
||||
}
|
||||
String value = String::num(get_value(), Math::range_step_decimals(step));
|
||||
if (is_localizing_numeral_system()) {
|
||||
value = TS->format_number(value);
|
||||
}
|
||||
|
@ -114,8 +120,14 @@ void SpinBox::_line_edit_input(const Ref<InputEvent> &p_event) {
|
|||
void SpinBox::_range_click_timeout() {
|
||||
if (!drag.enabled && Input::get_singleton()->is_mouse_button_pressed(MouseButton::LEFT)) {
|
||||
bool up = get_local_mouse_position().y < (get_size().height / 2);
|
||||
double step = get_custom_arrow_step() != 0.0 ? get_custom_arrow_step() : get_step();
|
||||
set_value(get_value() + (up ? step : -step));
|
||||
bool original_do_round = is_using_rounded_values();
|
||||
double step = get_step();
|
||||
double temp_step = get_custom_arrow_step() != 0.0 ? get_custom_arrow_step() : get_step();
|
||||
_rounded_values = false;
|
||||
_set_step_no_signal(temp_step);
|
||||
set_value(get_value() + (up ? temp_step : -temp_step));
|
||||
_set_step_no_signal(step);
|
||||
_rounded_values = original_do_round;
|
||||
|
||||
if (range_click_timer->is_one_shot()) {
|
||||
range_click_timer->set_wait_time(0.075);
|
||||
|
@ -156,8 +168,7 @@ void SpinBox::gui_input(const Ref<InputEvent> &p_event) {
|
|||
Ref<InputEventMouseButton> mb = p_event;
|
||||
Ref<InputEventMouseMotion> mm = p_event;
|
||||
|
||||
double step = get_custom_arrow_step() != 0.0 ? get_custom_arrow_step() : get_step();
|
||||
|
||||
double step = get_step();
|
||||
Vector2 mpos;
|
||||
bool mouse_on_up_button = false;
|
||||
bool mouse_on_down_button = false;
|
||||
|
@ -177,7 +188,13 @@ void SpinBox::gui_input(const Ref<InputEvent> &p_event) {
|
|||
line_edit->grab_focus();
|
||||
|
||||
if (mouse_on_up_button || mouse_on_down_button) {
|
||||
set_value(get_value() + (mouse_on_up_button ? step : -step));
|
||||
bool original_do_round = is_using_rounded_values();
|
||||
double temp_step = get_custom_arrow_step() != 0.0 ? get_custom_arrow_step() : get_step();
|
||||
_rounded_values = false;
|
||||
_set_step_no_signal(temp_step);
|
||||
set_value(get_value() + (mouse_on_up_button ? temp_step : -temp_step));
|
||||
_rounded_values = original_do_round;
|
||||
_set_step_no_signal(step);
|
||||
}
|
||||
state_cache.up_button_pressed = mouse_on_up_button;
|
||||
state_cache.down_button_pressed = mouse_on_down_button;
|
||||
|
@ -519,6 +536,12 @@ void SpinBox::_update_buttons_state_for_current_value() {
|
|||
}
|
||||
}
|
||||
|
||||
void SpinBox::_set_step_no_signal(double p_step) {
|
||||
set_block_signals(true);
|
||||
set_step(p_step);
|
||||
set_block_signals(false);
|
||||
}
|
||||
|
||||
void SpinBox::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("set_horizontal_alignment", "alignment"), &SpinBox::set_horizontal_alignment);
|
||||
ClassDB::bind_method(D_METHOD("get_horizontal_alignment"), &SpinBox::get_horizontal_alignment);
|
||||
|
|
|
@ -133,6 +133,7 @@ class SpinBox : public Range {
|
|||
|
||||
void _mouse_exited();
|
||||
void _update_buttons_state_for_current_value();
|
||||
void _set_step_no_signal(double p_step);
|
||||
|
||||
protected:
|
||||
virtual void gui_input(const Ref<InputEvent> &p_event) override;
|
||||
|
|
Loading…
Reference in New Issue