summaryrefslogtreecommitdiff
path: root/scene/gui
diff options
context:
space:
mode:
authorkobewi <kobewi4e@gmail.com>2021-05-06 14:33:44 +0200
committerkobewi <kobewi4e@gmail.com>2021-07-13 13:57:26 +0200
commit50c63bdc4ca6239d06ddf5a63557aadd0c405770 (patch)
tree8c459196f5f1295042b4884ace53e0af9c0c1d22 /scene/gui
parentdd274139073da7119dfe8801c8dd29275c5fd830 (diff)
Add set_pressed_no_signal method to BaseButton
Diffstat (limited to 'scene/gui')
-rw-r--r--scene/gui/base_button.cpp13
-rw-r--r--scene/gui/base_button.h3
2 files changed, 15 insertions, 1 deletions
diff --git a/scene/gui/base_button.cpp b/scene/gui/base_button.cpp
index c1ae0479f5..8414c4dc78 100644
--- a/scene/gui/base_button.cpp
+++ b/scene/gui/base_button.cpp
@@ -226,6 +226,18 @@ void BaseButton::set_pressed(bool p_pressed) {
update();
}
+void BaseButton::set_pressed_no_signal(bool p_pressed) {
+ if (!toggle_mode) {
+ return;
+ }
+ if (status.pressed == p_pressed) {
+ return;
+ }
+ status.pressed = p_pressed;
+
+ update();
+}
+
bool BaseButton::is_pressing() const {
return status.press_attempt;
}
@@ -399,6 +411,7 @@ void BaseButton::_bind_methods() {
ClassDB::bind_method(D_METHOD("_unhandled_key_input"), &BaseButton::_unhandled_key_input);
ClassDB::bind_method(D_METHOD("set_pressed", "pressed"), &BaseButton::set_pressed);
ClassDB::bind_method(D_METHOD("is_pressed"), &BaseButton::is_pressed);
+ ClassDB::bind_method(D_METHOD("set_pressed_no_signal", "pressed"), &BaseButton::set_pressed_no_signal);
ClassDB::bind_method(D_METHOD("is_hovered"), &BaseButton::is_hovered);
ClassDB::bind_method(D_METHOD("set_toggle_mode", "enabled"), &BaseButton::set_toggle_mode);
ClassDB::bind_method(D_METHOD("is_toggle_mode"), &BaseButton::is_toggle_mode);
diff --git a/scene/gui/base_button.h b/scene/gui/base_button.h
index 6c7a8f3433..d86b35daf0 100644
--- a/scene/gui/base_button.h
+++ b/scene/gui/base_button.h
@@ -98,7 +98,8 @@ public:
bool is_pressing() const; ///< return whether button is pressed (toggled in)
bool is_hovered() const;
- void set_pressed(bool p_pressed); ///only works in toggle mode
+ void set_pressed(bool p_pressed); // Only works in toggle mode.
+ void set_pressed_no_signal(bool p_pressed);
void set_toggle_mode(bool p_on);
bool is_toggle_mode() const;