Merge cd9e980e91
into 7211012c4f
This commit is contained in:
commit
156980320a
|
@ -47,6 +47,9 @@
|
|||
<member name="align" type="int" setter="set_align" getter="get_align" enum="LineEdit.Align" default="0">
|
||||
Sets the text alignment of the [SpinBox].
|
||||
</member>
|
||||
<member name="arrow_step" type="float" setter="set_arrow_step" getter="get_arrow_step" default="0.0">
|
||||
If greater than 0, [code]value[/code] will always be rounded to a multiple of [code]arrow_step[/code] when interacting with the arrow buttons of the [SpinBox].
|
||||
</member>
|
||||
<member name="editable" type="bool" setter="set_editable" getter="is_editable" default="true">
|
||||
If [code]true[/code], the [SpinBox] will be editable. Otherwise, it will be read only.
|
||||
</member>
|
||||
|
|
|
@ -87,7 +87,7 @@ 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(MOUSE_BUTTON_LEFT)) {
|
||||
bool up = get_local_mouse_position().y < (get_size().height / 2);
|
||||
set_value(get_value() + (up ? get_step() : -get_step()));
|
||||
set_value(get_value() + (up ? MAX(get_step(), get_arrow_step()) : -MAX(get_step(), get_arrow_step())));
|
||||
|
||||
if (range_click_timer->is_one_shot()) {
|
||||
range_click_timer->set_wait_time(0.075);
|
||||
|
@ -124,7 +124,7 @@ void SpinBox::gui_input(const Ref<InputEvent> &p_event) {
|
|||
case MOUSE_BUTTON_LEFT: {
|
||||
line_edit->grab_focus();
|
||||
|
||||
set_value(get_value() + (up ? get_step() : -get_step()));
|
||||
set_value(get_value() + (up ? MAX(get_step(), get_arrow_step()) : -MAX(get_step(), get_arrow_step())));
|
||||
|
||||
range_click_timer->set_wait_time(0.6);
|
||||
range_click_timer->set_one_shot(true);
|
||||
|
@ -139,13 +139,13 @@ void SpinBox::gui_input(const Ref<InputEvent> &p_event) {
|
|||
} break;
|
||||
case MOUSE_BUTTON_WHEEL_UP: {
|
||||
if (line_edit->has_focus()) {
|
||||
set_value(get_value() + get_step() * mb->get_factor());
|
||||
set_value(get_value() + MAX(get_step(), get_arrow_step()) * mb->get_factor());
|
||||
accept_event();
|
||||
}
|
||||
} break;
|
||||
case MOUSE_BUTTON_WHEEL_DOWN: {
|
||||
if (line_edit->has_focus()) {
|
||||
set_value(get_value() - get_step() * mb->get_factor());
|
||||
set_value(get_value() - MAX(get_step(), get_arrow_step()) * mb->get_factor());
|
||||
accept_event();
|
||||
}
|
||||
} break;
|
||||
|
@ -167,7 +167,7 @@ void SpinBox::gui_input(const Ref<InputEvent> &p_event) {
|
|||
if (drag.enabled) {
|
||||
drag.diff_y += mm->get_relative().y;
|
||||
float diff_y = -0.01 * Math::pow(ABS(drag.diff_y), 1.8f) * SGN(drag.diff_y);
|
||||
set_value(CLAMP(drag.base_val + get_step() * diff_y, get_min(), get_max()));
|
||||
set_value(CLAMP(drag.base_val + MAX(get_step(), get_arrow_step()) * ceil(diff_y), get_min(), get_max()));
|
||||
} else if (drag.allowed && drag.capture_pos.distance_to(mm->get_position()) > 2) {
|
||||
Input::get_singleton()->set_mouse_mode(Input::MOUSE_MODE_CAPTURED);
|
||||
drag.enabled = true;
|
||||
|
@ -283,6 +283,14 @@ void SpinBox::apply() {
|
|||
_text_submitted(line_edit->get_text());
|
||||
}
|
||||
|
||||
void SpinBox::set_arrow_step(double p_arrow_step) {
|
||||
arrow_step = p_arrow_step;
|
||||
}
|
||||
|
||||
double SpinBox::get_arrow_step() const {
|
||||
return arrow_step;
|
||||
}
|
||||
|
||||
void SpinBox::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("set_align", "align"), &SpinBox::set_align);
|
||||
ClassDB::bind_method(D_METHOD("get_align"), &SpinBox::get_align);
|
||||
|
@ -291,6 +299,8 @@ void SpinBox::_bind_methods() {
|
|||
ClassDB::bind_method(D_METHOD("set_prefix", "prefix"), &SpinBox::set_prefix);
|
||||
ClassDB::bind_method(D_METHOD("get_prefix"), &SpinBox::get_prefix);
|
||||
ClassDB::bind_method(D_METHOD("set_editable", "enabled"), &SpinBox::set_editable);
|
||||
ClassDB::bind_method(D_METHOD("set_arrow_step", "arrow_step"), &SpinBox::set_arrow_step);
|
||||
ClassDB::bind_method(D_METHOD("get_arrow_step"), &SpinBox::get_arrow_step);
|
||||
ClassDB::bind_method(D_METHOD("is_editable"), &SpinBox::is_editable);
|
||||
ClassDB::bind_method(D_METHOD("set_update_on_text_changed", "enabled"), &SpinBox::set_update_on_text_changed);
|
||||
ClassDB::bind_method(D_METHOD("get_update_on_text_changed"), &SpinBox::get_update_on_text_changed);
|
||||
|
@ -302,6 +312,7 @@ void SpinBox::_bind_methods() {
|
|||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "update_on_text_changed"), "set_update_on_text_changed", "get_update_on_text_changed");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::STRING, "prefix"), "set_prefix", "get_prefix");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::STRING, "suffix"), "set_suffix", "get_suffix");
|
||||
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "arrow_step"), "set_arrow_step", "get_arrow_step");
|
||||
}
|
||||
|
||||
SpinBox::SpinBox() {
|
||||
|
|
|
@ -52,6 +52,7 @@ class SpinBox : public Range {
|
|||
|
||||
String prefix;
|
||||
String suffix;
|
||||
double arrow_step = 0.0;
|
||||
|
||||
void _line_edit_input(const Ref<InputEvent> &p_event);
|
||||
|
||||
|
@ -95,6 +96,8 @@ public:
|
|||
bool get_update_on_text_changed() const;
|
||||
|
||||
void apply();
|
||||
void set_arrow_step(const double p_arrow_step);
|
||||
double get_arrow_step() const;
|
||||
|
||||
SpinBox();
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue