Fixes the 'CLAMP' problem in the 'EditorSpinSlider' ...

... when arrow keys are pressed up or down.
This commit is contained in:
Alexander Hartmann 2023-09-03 19:23:14 +02:00
parent d2ae309f2c
commit 053d718154

View file

@ -203,7 +203,6 @@ void EditorSpinSlider::_value_input_gui_input(const Ref<InputEvent> &p_event) {
Ref<InputEventKey> k = p_event;
if (k.is_valid() && k->is_pressed() && !is_read_only()) {
double step = get_step();
double real_step = step;
if (step < 1) {
double divisor = 1.0 / get_step();
@ -221,30 +220,22 @@ void EditorSpinSlider::_value_input_gui_input(const Ref<InputEvent> &p_event) {
}
Key code = k->get_keycode();
switch (code) {
case Key::UP: {
_evaluate_input_text();
double last_value = get_value();
set_value(last_value + step);
double new_value = get_value();
if (new_value < CLAMP(last_value + step, get_min(), get_max())) {
set_value(last_value + real_step);
}
value_input_dirty = true;
set_process_internal(true);
} break;
case Key::UP:
case Key::DOWN: {
_evaluate_input_text();
double last_value = get_value();
set_value(last_value - step);
if (code == Key::DOWN) {
step *= -1;
}
set_value(last_value + step);
double new_value = get_value();
if (new_value > CLAMP(last_value - step, get_min(), get_max())) {
set_value(last_value - real_step);
double clamp_value = CLAMP(new_value, get_min(), get_max());
if (new_value != clamp_value) {
set_value(clamp_value);
}
value_input_dirty = true;