mirror of
https://github.com/godotengine/godot.git
synced 2025-12-07 22:00:10 +00:00
SpinBox: Fix custom_arrow_step by snapping it to step
This commit is contained in:
parent
e1b4101e34
commit
453f4f13e4
3 changed files with 4 additions and 10 deletions
|
|
@ -50,7 +50,8 @@
|
||||||
Changes the alignment of the underlying [LineEdit].
|
Changes the alignment of the underlying [LineEdit].
|
||||||
</member>
|
</member>
|
||||||
<member name="custom_arrow_step" type="float" setter="set_custom_arrow_step" getter="get_custom_arrow_step" default="0.0">
|
<member name="custom_arrow_step" type="float" setter="set_custom_arrow_step" getter="get_custom_arrow_step" default="0.0">
|
||||||
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].
|
||||||
</member>
|
</member>
|
||||||
<member name="editable" type="bool" setter="set_editable" getter="is_editable" default="true" keywords="readonly, disabled, enabled">
|
<member name="editable" type="bool" setter="set_editable" getter="is_editable" default="true" keywords="readonly, disabled, enabled">
|
||||||
If [code]true[/code], the [SpinBox] will be editable. Otherwise, it will be read only.
|
If [code]true[/code], the [SpinBox] will be editable. Otherwise, it will be read only.
|
||||||
|
|
|
||||||
|
|
@ -144,8 +144,6 @@ void SpinBox::_text_submitted(const String &p_string) {
|
||||||
|
|
||||||
Error err = expr->parse(text);
|
Error err = expr->parse(text);
|
||||||
|
|
||||||
use_custom_arrow_step = false;
|
|
||||||
|
|
||||||
if (err != OK) {
|
if (err != OK) {
|
||||||
// If the expression failed try without converting commas to dots - they might have been for parameter separation.
|
// If the expression failed try without converting commas to dots - they might have been for parameter separation.
|
||||||
text = p_string;
|
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);
|
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.
|
// 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();
|
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);
|
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)) {
|
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);
|
new_value = _calc_value(get_value() + (mouse_on_up_button ? temp_step : -temp_step), temp_step);
|
||||||
}
|
}
|
||||||
set_value(new_value);
|
set_value(new_value);
|
||||||
use_custom_arrow_step = true;
|
|
||||||
|
|
||||||
if (range_click_timer->is_one_shot()) {
|
if (range_click_timer->is_one_shot()) {
|
||||||
range_click_timer->set_wait_time(0.075);
|
range_click_timer->set_wait_time(0.075);
|
||||||
|
|
@ -264,12 +262,12 @@ void SpinBox::gui_input(const Ref<InputEvent> &p_event) {
|
||||||
if (mouse_on_up_button || mouse_on_down_button) {
|
if (mouse_on_up_button || mouse_on_down_button) {
|
||||||
// Arrow button is being pressed. Snap the value to next step.
|
// 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();
|
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);
|
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)) {
|
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);
|
new_value = _calc_value(get_value() + (mouse_on_up_button ? temp_step : -temp_step), temp_step);
|
||||||
}
|
}
|
||||||
set_value(new_value);
|
set_value(new_value);
|
||||||
use_custom_arrow_step = true;
|
|
||||||
}
|
}
|
||||||
state_cache.up_button_pressed = mouse_on_up_button;
|
state_cache.up_button_pressed = mouse_on_up_button;
|
||||||
state_cache.down_button_pressed = mouse_on_down_button;
|
state_cache.down_button_pressed = mouse_on_down_button;
|
||||||
|
|
@ -285,20 +283,17 @@ void SpinBox::gui_input(const Ref<InputEvent> &p_event) {
|
||||||
case MouseButton::RIGHT: {
|
case MouseButton::RIGHT: {
|
||||||
line_edit->grab_focus();
|
line_edit->grab_focus();
|
||||||
if (mouse_on_up_button || mouse_on_down_button) {
|
if (mouse_on_up_button || mouse_on_down_button) {
|
||||||
use_custom_arrow_step = false;
|
|
||||||
set_value(mouse_on_up_button ? get_max() : get_min());
|
set_value(mouse_on_up_button ? get_max() : get_min());
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
case MouseButton::WHEEL_UP: {
|
case MouseButton::WHEEL_UP: {
|
||||||
if (line_edit->is_editing()) {
|
if (line_edit->is_editing()) {
|
||||||
use_custom_arrow_step = false;
|
|
||||||
set_value(get_value() + step * mb->get_factor());
|
set_value(get_value() + step * mb->get_factor());
|
||||||
accept_event();
|
accept_event();
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
case MouseButton::WHEEL_DOWN: {
|
case MouseButton::WHEEL_DOWN: {
|
||||||
if (line_edit->is_editing()) {
|
if (line_edit->is_editing()) {
|
||||||
use_custom_arrow_step = false;
|
|
||||||
set_value(get_value() - step * mb->get_factor());
|
set_value(get_value() - step * mb->get_factor());
|
||||||
accept_event();
|
accept_event();
|
||||||
}
|
}
|
||||||
|
|
@ -338,7 +333,6 @@ void SpinBox::gui_input(const Ref<InputEvent> &p_event) {
|
||||||
if (drag.enabled) {
|
if (drag.enabled) {
|
||||||
drag.diff_y += mm->get_relative().y;
|
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);
|
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()));
|
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) {
|
} else if (drag.allowed && drag.capture_pos.distance_to(mm->get_position()) > 2) {
|
||||||
Input::get_singleton()->set_mouse_mode(Input::MOUSE_MODE_CAPTURED);
|
Input::get_singleton()->set_mouse_mode(Input::MOUSE_MODE_CAPTURED);
|
||||||
|
|
|
||||||
|
|
@ -76,7 +76,6 @@ class SpinBox : public Range {
|
||||||
String suffix;
|
String suffix;
|
||||||
String last_text_value;
|
String last_text_value;
|
||||||
double custom_arrow_step = 0.0;
|
double custom_arrow_step = 0.0;
|
||||||
bool use_custom_arrow_step = false;
|
|
||||||
|
|
||||||
void _line_edit_input(const Ref<InputEvent> &p_event);
|
void _line_edit_input(const Ref<InputEvent> &p_event);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue