Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix clamping logic in EditorSpinSlider #81278

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 9 additions & 18 deletions editor/gui/editor_spin_slider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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;
switch (code) {
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;
Expand Down
Loading