2014-02-10 01:10:30 +00:00
|
|
|
/**************************************************************************/
|
|
|
|
/* spin_box.cpp */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* https://godotengine.org */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
|
|
|
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/**************************************************************************/
|
2018-01-04 23:50:27 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
#include "spin_box.h"
|
2020-03-04 16:36:09 +00:00
|
|
|
|
2020-04-28 13:19:37 +00:00
|
|
|
#include "core/input/input.h"
|
2019-08-29 21:48:50 +00:00
|
|
|
#include "core/math/expression.h"
|
2023-09-08 19:00:10 +00:00
|
|
|
#include "scene/theme/theme_db.h"
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
Size2 SpinBox::get_minimum_size() const {
|
|
|
|
Size2 ms = line_edit->get_combined_minimum_size();
|
|
|
|
ms.width += last_w;
|
|
|
|
return ms;
|
|
|
|
}
|
|
|
|
|
2023-10-08 12:03:08 +00:00
|
|
|
void SpinBox::_update_text(bool p_keep_line_edit) {
|
2022-11-17 12:54:45 +00:00
|
|
|
String value = String::num(get_value(), Math::range_step_decimals(get_step()));
|
|
|
|
if (is_localizing_numeral_system()) {
|
|
|
|
value = TS->format_number(value);
|
|
|
|
}
|
2022-08-17 11:27:19 +00:00
|
|
|
|
|
|
|
if (!line_edit->has_focus()) {
|
|
|
|
if (!prefix.is_empty()) {
|
|
|
|
value = prefix + " " + value;
|
|
|
|
}
|
|
|
|
if (!suffix.is_empty()) {
|
|
|
|
value += " " + suffix;
|
|
|
|
}
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2022-08-17 11:27:19 +00:00
|
|
|
|
2023-10-08 12:03:08 +00:00
|
|
|
if (p_keep_line_edit && value == last_updated_text && value != line_edit->get_text()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-06-10 19:29:24 +00:00
|
|
|
line_edit->set_text_with_selection(value);
|
2023-10-08 12:03:08 +00:00
|
|
|
last_updated_text = value;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2021-06-16 16:43:34 +00:00
|
|
|
void SpinBox::_text_submitted(const String &p_string) {
|
2019-08-29 21:48:50 +00:00
|
|
|
Ref<Expression> expr;
|
2021-06-17 22:03:09 +00:00
|
|
|
expr.instantiate();
|
2020-09-03 11:22:16 +00:00
|
|
|
|
2023-08-16 18:18:22 +00:00
|
|
|
// Convert commas ',' to dots '.' for French/German etc. keyboard layouts.
|
|
|
|
String text = p_string.replace(",", ".");
|
|
|
|
text = text.replace(";", ",");
|
|
|
|
text = TS->parse_number(text);
|
2023-03-08 22:00:27 +00:00
|
|
|
// Ignore the prefix and suffix in the expression.
|
2023-08-16 18:18:22 +00:00
|
|
|
text = text.trim_prefix(prefix + " ").trim_suffix(" " + suffix);
|
|
|
|
|
|
|
|
Error err = expr->parse(text);
|
2019-08-29 21:48:50 +00:00
|
|
|
if (err != OK) {
|
2023-08-16 18:18:22 +00:00
|
|
|
// If the expression failed try without converting commas to dots - they might have been for parameter separation.
|
|
|
|
text = p_string;
|
|
|
|
text = TS->parse_number(text);
|
|
|
|
text = text.trim_prefix(prefix + " ").trim_suffix(" " + suffix);
|
|
|
|
|
|
|
|
err = expr->parse(text);
|
|
|
|
if (err != OK) {
|
|
|
|
return;
|
|
|
|
}
|
2019-08-29 21:48:50 +00:00
|
|
|
}
|
|
|
|
|
2022-06-27 20:10:04 +00:00
|
|
|
Variant value = expr->execute(Array(), nullptr, false, true);
|
2019-08-29 21:48:50 +00:00
|
|
|
if (value.get_type() != Variant::NIL) {
|
|
|
|
set_value(value);
|
|
|
|
}
|
2023-01-02 13:15:36 +00:00
|
|
|
_update_text();
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2020-04-27 10:24:27 +00:00
|
|
|
void SpinBox::_text_changed(const String &p_string) {
|
|
|
|
int cursor_pos = line_edit->get_caret_column();
|
|
|
|
|
|
|
|
_text_submitted(p_string);
|
|
|
|
|
|
|
|
// Line edit 'set_text' method resets the cursor position so we need to undo that.
|
|
|
|
line_edit->set_caret_column(cursor_pos);
|
|
|
|
}
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
LineEdit *SpinBox::get_line_edit() {
|
|
|
|
return line_edit;
|
|
|
|
}
|
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
void SpinBox::_line_edit_input(const Ref<InputEvent> &p_event) {
|
2015-08-29 04:43:21 +00:00
|
|
|
}
|
|
|
|
|
2015-12-08 18:04:56 +00:00
|
|
|
void SpinBox::_range_click_timeout() {
|
2021-08-13 21:31:57 +00:00
|
|
|
if (!drag.enabled && Input::get_singleton()->is_mouse_button_pressed(MouseButton::LEFT)) {
|
2017-09-10 13:37:49 +00:00
|
|
|
bool up = get_local_mouse_position().y < (get_size().height / 2);
|
2019-11-15 15:04:34 +00:00
|
|
|
double step = get_custom_arrow_step() != 0.0 ? get_custom_arrow_step() : get_step();
|
|
|
|
set_value(get_value() + (up ? step : -step));
|
2015-12-08 18:04:56 +00:00
|
|
|
|
|
|
|
if (range_click_timer->is_one_shot()) {
|
|
|
|
range_click_timer->set_wait_time(0.075);
|
|
|
|
range_click_timer->set_one_shot(false);
|
|
|
|
range_click_timer->start();
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
range_click_timer->stop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-06 21:22:24 +00:00
|
|
|
void SpinBox::_release_mouse() {
|
|
|
|
if (drag.enabled) {
|
|
|
|
drag.enabled = false;
|
2022-08-18 09:16:29 +00:00
|
|
|
Input::get_singleton()->set_mouse_mode(Input::MOUSE_MODE_HIDDEN);
|
2021-03-06 21:22:24 +00:00
|
|
|
warp_mouse(drag.capture_pos);
|
2022-08-18 09:16:29 +00:00
|
|
|
Input::get_singleton()->set_mouse_mode(Input::MOUSE_MODE_VISIBLE);
|
2021-03-06 21:22:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-22 15:37:22 +00:00
|
|
|
void SpinBox::gui_input(const Ref<InputEvent> &p_event) {
|
2021-04-05 06:52:21 +00:00
|
|
|
ERR_FAIL_COND(p_event.is_null());
|
|
|
|
|
2016-11-24 18:15:42 +00:00
|
|
|
if (!is_editable()) {
|
|
|
|
return;
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
Ref<InputEventMouseButton> mb = p_event;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2019-11-15 15:04:34 +00:00
|
|
|
double step = get_custom_arrow_step() != 0.0 ? get_custom_arrow_step() : get_step();
|
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
if (mb.is_valid() && mb->is_pressed()) {
|
2017-06-03 08:54:24 +00:00
|
|
|
bool up = mb->get_position().y < (get_size().height / 2);
|
2017-05-20 15:38:03 +00:00
|
|
|
|
|
|
|
switch (mb->get_button_index()) {
|
2021-08-13 21:31:57 +00:00
|
|
|
case MouseButton::LEFT: {
|
2019-10-21 23:42:17 +00:00
|
|
|
line_edit->grab_focus();
|
|
|
|
|
2019-11-15 15:04:34 +00:00
|
|
|
set_value(get_value() + (up ? step : -step));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2015-12-08 18:04:56 +00:00
|
|
|
range_click_timer->set_wait_time(0.6);
|
|
|
|
range_click_timer->set_one_shot(true);
|
|
|
|
range_click_timer->start();
|
|
|
|
|
2018-08-27 05:57:30 +00:00
|
|
|
drag.allowed = true;
|
|
|
|
drag.capture_pos = mb->get_position();
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
2021-08-13 21:31:57 +00:00
|
|
|
case MouseButton::RIGHT: {
|
2016-11-24 18:15:42 +00:00
|
|
|
line_edit->grab_focus();
|
2019-10-21 23:42:17 +00:00
|
|
|
set_value((up ? get_max() : get_min()));
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
2021-08-13 21:31:57 +00:00
|
|
|
case MouseButton::WHEEL_UP: {
|
2016-11-24 18:15:42 +00:00
|
|
|
if (line_edit->has_focus()) {
|
2019-11-15 15:04:34 +00:00
|
|
|
set_value(get_value() + step * mb->get_factor());
|
2016-11-24 18:15:42 +00:00
|
|
|
accept_event();
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
2021-08-13 21:31:57 +00:00
|
|
|
case MouseButton::WHEEL_DOWN: {
|
2016-11-24 18:15:42 +00:00
|
|
|
if (line_edit->has_focus()) {
|
2019-11-15 15:04:34 +00:00
|
|
|
set_value(get_value() - step * mb->get_factor());
|
2016-11-24 18:15:42 +00:00
|
|
|
accept_event();
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
2021-03-25 20:56:12 +00:00
|
|
|
default:
|
|
|
|
break;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
2015-08-29 04:43:21 +00:00
|
|
|
|
2021-08-13 21:31:57 +00:00
|
|
|
if (mb.is_valid() && !mb->is_pressed() && mb->get_button_index() == MouseButton::LEFT) {
|
2015-08-29 04:43:21 +00:00
|
|
|
//set_default_cursor_shape(CURSOR_ARROW);
|
2015-12-08 18:04:56 +00:00
|
|
|
range_click_timer->stop();
|
2021-03-06 21:22:24 +00:00
|
|
|
_release_mouse();
|
2018-08-27 05:57:30 +00:00
|
|
|
drag.allowed = false;
|
2022-10-16 12:37:35 +00:00
|
|
|
line_edit->clear_pending_select_all_on_focus();
|
2015-08-29 04:43:21 +00:00
|
|
|
}
|
|
|
|
|
2017-05-20 15:38:03 +00:00
|
|
|
Ref<InputEventMouseMotion> mm = p_event;
|
|
|
|
|
2023-01-07 23:55:54 +00:00
|
|
|
if (mm.is_valid() && (mm->get_button_mask().has_flag(MouseButtonMask::LEFT))) {
|
2015-08-29 04:43:21 +00:00
|
|
|
if (drag.enabled) {
|
2018-08-27 05:57:30 +00:00
|
|
|
drag.diff_y += mm->get_relative().y;
|
2022-07-14 23:33:00 +00:00
|
|
|
double diff_y = -0.01 * Math::pow(ABS(drag.diff_y), 1.8) * SIGN(drag.diff_y);
|
2019-11-15 15:04:34 +00:00
|
|
|
set_value(CLAMP(drag.base_val + step * diff_y, get_min(), get_max()));
|
2018-08-27 05:57:30 +00:00
|
|
|
} else if (drag.allowed && drag.capture_pos.distance_to(mm->get_position()) > 2) {
|
2020-04-28 13:19:37 +00:00
|
|
|
Input::get_singleton()->set_mouse_mode(Input::MOUSE_MODE_CAPTURED);
|
2015-08-29 04:43:21 +00:00
|
|
|
drag.enabled = true;
|
2017-01-04 04:16:14 +00:00
|
|
|
drag.base_val = get_value();
|
2018-08-27 05:57:30 +00:00
|
|
|
drag.diff_y = 0;
|
2015-08-29 04:43:21 +00:00
|
|
|
}
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2022-08-17 11:27:19 +00:00
|
|
|
void SpinBox::_line_edit_focus_enter() {
|
|
|
|
int col = line_edit->get_caret_column();
|
2023-01-02 13:15:36 +00:00
|
|
|
_update_text();
|
2022-08-17 11:27:19 +00:00
|
|
|
line_edit->set_caret_column(col);
|
2022-10-16 12:37:35 +00:00
|
|
|
|
|
|
|
// LineEdit text might change and it clears any selection. Have to re-select here.
|
|
|
|
if (line_edit->is_select_all_on_focus() && !Input::get_singleton()->is_mouse_button_pressed(MouseButton::LEFT)) {
|
|
|
|
line_edit->select_all();
|
|
|
|
}
|
2022-08-17 11:27:19 +00:00
|
|
|
}
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
void SpinBox::_line_edit_focus_exit() {
|
2023-01-02 13:15:36 +00:00
|
|
|
// Discontinue because the focus_exit was caused by left-clicking the arrows.
|
2023-06-02 14:57:10 +00:00
|
|
|
const Viewport *viewport = get_viewport();
|
2023-06-02 01:49:39 +00:00
|
|
|
if (!viewport || viewport->gui_get_focus_owner() == get_line_edit()) {
|
2023-01-02 13:15:36 +00:00
|
|
|
return;
|
|
|
|
}
|
2022-08-17 11:27:19 +00:00
|
|
|
// Discontinue because the focus_exit was caused by right-click context menu.
|
2021-07-16 21:36:05 +00:00
|
|
|
if (line_edit->is_menu_visible()) {
|
2019-08-12 10:39:27 +00:00
|
|
|
return;
|
2020-05-14 14:41:43 +00:00
|
|
|
}
|
2023-08-22 14:29:00 +00:00
|
|
|
// Discontinue because the focus_exit was caused by canceling.
|
|
|
|
if (Input::get_singleton()->is_action_pressed("ui_cancel")) {
|
|
|
|
_update_text();
|
|
|
|
return;
|
|
|
|
}
|
2019-08-12 10:39:27 +00:00
|
|
|
|
2021-06-16 16:43:34 +00:00
|
|
|
_text_submitted(line_edit->get_text());
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2019-06-11 18:43:37 +00:00
|
|
|
inline void SpinBox::_adjust_width_for_icon(const Ref<Texture2D> &icon) {
|
2018-02-05 21:42:30 +00:00
|
|
|
int w = icon->get_width();
|
2020-09-03 11:22:16 +00:00
|
|
|
if ((w != last_w)) {
|
2020-12-22 16:24:29 +00:00
|
|
|
line_edit->set_offset(SIDE_LEFT, 0);
|
|
|
|
line_edit->set_offset(SIDE_RIGHT, -w);
|
2018-02-05 21:42:30 +00:00
|
|
|
last_w = w;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
void SpinBox::_notification(int p_what) {
|
2022-02-15 17:06:48 +00:00
|
|
|
switch (p_what) {
|
|
|
|
case NOTIFICATION_DRAW: {
|
2023-10-08 12:03:08 +00:00
|
|
|
_update_text(true);
|
2022-08-31 12:02:40 +00:00
|
|
|
_adjust_width_for_icon(theme_cache.updown_icon);
|
2022-02-15 17:06:48 +00:00
|
|
|
|
|
|
|
RID ci = get_canvas_item();
|
|
|
|
Size2i size = get_size();
|
|
|
|
|
|
|
|
if (is_layout_rtl()) {
|
2022-08-31 12:02:40 +00:00
|
|
|
theme_cache.updown_icon->draw(ci, Point2i(0, (size.height - theme_cache.updown_icon->get_height()) / 2));
|
2022-02-15 17:06:48 +00:00
|
|
|
} else {
|
2022-08-31 12:02:40 +00:00
|
|
|
theme_cache.updown_icon->draw(ci, Point2i(size.width - theme_cache.updown_icon->get_width(), (size.height - theme_cache.updown_icon->get_height()) / 2));
|
2022-02-15 17:06:48 +00:00
|
|
|
}
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case NOTIFICATION_ENTER_TREE: {
|
2022-08-31 12:02:40 +00:00
|
|
|
_adjust_width_for_icon(theme_cache.updown_icon);
|
2023-01-02 13:15:36 +00:00
|
|
|
_update_text();
|
2022-02-15 17:06:48 +00:00
|
|
|
} break;
|
|
|
|
|
2023-06-03 12:50:03 +00:00
|
|
|
case NOTIFICATION_VISIBILITY_CHANGED:
|
|
|
|
drag.allowed = false;
|
|
|
|
[[fallthrough]];
|
2022-02-15 17:06:48 +00:00
|
|
|
case NOTIFICATION_EXIT_TREE: {
|
|
|
|
_release_mouse();
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case NOTIFICATION_TRANSLATION_CHANGED: {
|
2022-08-13 21:21:24 +00:00
|
|
|
queue_redraw();
|
2022-02-15 17:06:48 +00:00
|
|
|
} break;
|
|
|
|
|
|
|
|
case NOTIFICATION_THEME_CHANGED: {
|
2023-12-18 14:46:56 +00:00
|
|
|
callable_mp((Control *)this, &Control::update_minimum_size).call_deferred();
|
|
|
|
callable_mp((Control *)get_line_edit(), &Control::update_minimum_size).call_deferred();
|
2022-02-15 17:06:48 +00:00
|
|
|
} break;
|
|
|
|
|
|
|
|
case NOTIFICATION_LAYOUT_DIRECTION_CHANGED: {
|
2022-08-13 21:21:24 +00:00
|
|
|
queue_redraw();
|
2022-02-15 17:06:48 +00:00
|
|
|
} break;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-25 02:58:47 +00:00
|
|
|
void SpinBox::set_horizontal_alignment(HorizontalAlignment p_alignment) {
|
|
|
|
line_edit->set_horizontal_alignment(p_alignment);
|
2018-08-25 03:17:07 +00:00
|
|
|
}
|
|
|
|
|
2021-11-25 02:58:47 +00:00
|
|
|
HorizontalAlignment SpinBox::get_horizontal_alignment() const {
|
|
|
|
return line_edit->get_horizontal_alignment();
|
2018-08-25 03:17:07 +00:00
|
|
|
}
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
void SpinBox::set_suffix(const String &p_suffix) {
|
2022-03-16 07:50:48 +00:00
|
|
|
if (suffix == p_suffix) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
suffix = p_suffix;
|
2023-01-02 13:15:36 +00:00
|
|
|
_update_text();
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
String SpinBox::get_suffix() const {
|
|
|
|
return suffix;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SpinBox::set_prefix(const String &p_prefix) {
|
2022-03-16 07:50:48 +00:00
|
|
|
if (prefix == p_prefix) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
prefix = p_prefix;
|
2023-01-02 13:15:36 +00:00
|
|
|
_update_text();
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
String SpinBox::get_prefix() const {
|
|
|
|
return prefix;
|
|
|
|
}
|
|
|
|
|
2021-10-08 21:26:13 +00:00
|
|
|
void SpinBox::set_update_on_text_changed(bool p_enabled) {
|
|
|
|
if (update_on_text_changed == p_enabled) {
|
2020-04-27 10:24:27 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-10-08 21:26:13 +00:00
|
|
|
update_on_text_changed = p_enabled;
|
2020-04-27 10:24:27 +00:00
|
|
|
|
2021-10-08 21:26:13 +00:00
|
|
|
if (p_enabled) {
|
2022-07-28 20:56:41 +00:00
|
|
|
line_edit->connect("text_changed", callable_mp(this, &SpinBox::_text_changed), CONNECT_DEFERRED);
|
2020-04-27 10:24:27 +00:00
|
|
|
} else {
|
|
|
|
line_edit->disconnect("text_changed", callable_mp(this, &SpinBox::_text_changed));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SpinBox::get_update_on_text_changed() const {
|
|
|
|
return update_on_text_changed;
|
|
|
|
}
|
|
|
|
|
2022-10-16 12:37:35 +00:00
|
|
|
void SpinBox::set_select_all_on_focus(bool p_enabled) {
|
|
|
|
line_edit->set_select_all_on_focus(p_enabled);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SpinBox::is_select_all_on_focus() const {
|
|
|
|
return line_edit->is_select_all_on_focus();
|
|
|
|
}
|
|
|
|
|
2021-10-08 21:26:13 +00:00
|
|
|
void SpinBox::set_editable(bool p_enabled) {
|
|
|
|
line_edit->set_editable(p_enabled);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool SpinBox::is_editable() const {
|
|
|
|
return line_edit->is_editable();
|
|
|
|
}
|
|
|
|
|
2020-01-09 13:44:23 +00:00
|
|
|
void SpinBox::apply() {
|
2021-06-16 16:43:34 +00:00
|
|
|
_text_submitted(line_edit->get_text());
|
2020-01-09 13:44:23 +00:00
|
|
|
}
|
|
|
|
|
2019-11-15 15:04:34 +00:00
|
|
|
void SpinBox::set_custom_arrow_step(double p_custom_arrow_step) {
|
|
|
|
custom_arrow_step = p_custom_arrow_step;
|
|
|
|
}
|
|
|
|
|
|
|
|
double SpinBox::get_custom_arrow_step() const {
|
|
|
|
return custom_arrow_step;
|
|
|
|
}
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
void SpinBox::_bind_methods() {
|
2021-11-25 02:58:47 +00:00
|
|
|
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);
|
2017-02-13 11:47:24 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_suffix", "suffix"), &SpinBox::set_suffix);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_suffix"), &SpinBox::get_suffix);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_prefix", "prefix"), &SpinBox::set_prefix);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_prefix"), &SpinBox::get_prefix);
|
2021-10-08 21:26:13 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_editable", "enabled"), &SpinBox::set_editable);
|
2019-11-15 15:04:34 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_custom_arrow_step", "arrow_step"), &SpinBox::set_custom_arrow_step);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_custom_arrow_step"), &SpinBox::get_custom_arrow_step);
|
2017-02-13 11:47:24 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("is_editable"), &SpinBox::is_editable);
|
2021-10-08 21:26:13 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_update_on_text_changed", "enabled"), &SpinBox::set_update_on_text_changed);
|
2020-04-27 10:24:27 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("get_update_on_text_changed"), &SpinBox::get_update_on_text_changed);
|
2022-10-16 12:37:35 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_select_all_on_focus", "enabled"), &SpinBox::set_select_all_on_focus);
|
|
|
|
ClassDB::bind_method(D_METHOD("is_select_all_on_focus"), &SpinBox::is_select_all_on_focus);
|
2020-01-09 13:44:23 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("apply"), &SpinBox::apply);
|
2017-08-09 11:19:41 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("get_line_edit"), &SpinBox::get_line_edit);
|
2017-03-05 15:44:50 +00:00
|
|
|
|
2021-11-25 02:58:47 +00:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "alignment", PROPERTY_HINT_ENUM, "Left,Center,Right,Fill"), "set_horizontal_alignment", "get_horizontal_alignment");
|
2017-02-12 00:11:37 +00:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "editable"), "set_editable", "is_editable");
|
2020-04-27 10:24:27 +00:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "update_on_text_changed"), "set_update_on_text_changed", "get_update_on_text_changed");
|
2017-02-12 00:11:37 +00:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::STRING, "prefix"), "set_prefix", "get_prefix");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::STRING, "suffix"), "set_suffix", "get_suffix");
|
2023-01-14 19:15:52 +00:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "custom_arrow_step", PROPERTY_HINT_RANGE, "0,10000,0.0001,or_greater"), "set_custom_arrow_step", "get_custom_arrow_step");
|
2022-10-16 12:37:35 +00:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "select_all_on_focus"), "set_select_all_on_focus", "is_select_all_on_focus");
|
2023-09-08 19:00:10 +00:00
|
|
|
|
|
|
|
BIND_THEME_ITEM_CUSTOM(Theme::DATA_TYPE_ICON, SpinBox, updown_icon, "updown");
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SpinBox::SpinBox() {
|
|
|
|
line_edit = memnew(LineEdit);
|
2021-08-25 13:49:30 +00:00
|
|
|
add_child(line_edit, false, INTERNAL_MODE_FRONT);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2022-03-19 00:02:57 +00:00
|
|
|
line_edit->set_anchors_and_offsets_preset(Control::PRESET_FULL_RECT);
|
2019-05-21 12:49:53 +00:00
|
|
|
line_edit->set_mouse_filter(MOUSE_FILTER_PASS);
|
2021-11-25 02:58:47 +00:00
|
|
|
line_edit->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_LEFT);
|
2020-09-03 11:22:16 +00:00
|
|
|
|
2022-07-28 20:56:41 +00:00
|
|
|
line_edit->connect("text_submitted", callable_mp(this, &SpinBox::_text_submitted), CONNECT_DEFERRED);
|
2022-08-17 11:27:19 +00:00
|
|
|
line_edit->connect("focus_entered", callable_mp(this, &SpinBox::_line_edit_focus_enter), CONNECT_DEFERRED);
|
2022-07-28 20:56:41 +00:00
|
|
|
line_edit->connect("focus_exited", callable_mp(this, &SpinBox::_line_edit_focus_exit), CONNECT_DEFERRED);
|
2020-02-21 17:28:45 +00:00
|
|
|
line_edit->connect("gui_input", callable_mp(this, &SpinBox::_line_edit_input));
|
2015-12-08 18:04:56 +00:00
|
|
|
|
|
|
|
range_click_timer = memnew(Timer);
|
2020-02-21 17:28:45 +00:00
|
|
|
range_click_timer->connect("timeout", callable_mp(this, &SpinBox::_range_click_timeout));
|
2021-08-25 13:49:30 +00:00
|
|
|
add_child(range_click_timer, false, INTERNAL_MODE_FRONT);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|