summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2022-11-04 10:48:47 +0100
committerRémi Verschelde <rverschelde@gmail.com>2022-11-04 10:48:47 +0100
commit4e47324b3f1d91d98ee4daf12acc16163e441318 (patch)
tree35743507cc8b5ab898a3b072720f6ceaec4e66b1
parentd48ba545ef469d9caf08f74f3e99f750dad2fb8c (diff)
parent4aa1efb0febd0256931b36b51bc223a130995dc7 (diff)
Merge pull request #68097 from KoBeWi/no_signal🔕
Add `set_value_no_signal()` to Range
-rw-r--r--doc/classes/Range.xml9
-rw-r--r--scene/gui/base_button.cpp11
-rw-r--r--scene/gui/range.cpp12
-rw-r--r--scene/gui/range.h1
4 files changed, 23 insertions, 10 deletions
diff --git a/doc/classes/Range.xml b/doc/classes/Range.xml
index 16e6e86f9e..9764318ee4 100644
--- a/doc/classes/Range.xml
+++ b/doc/classes/Range.xml
@@ -16,6 +16,13 @@
Called when the [Range]'s value is changed (following the same conditions as [signal value_changed]).
</description>
</method>
+ <method name="set_value_no_signal">
+ <return type="void" />
+ <param index="0" name="value" type="float" />
+ <description>
+ Sets the [Range]'s current value to the specified [param value], without emitting the [signal value_changed] signal.
+ </description>
+ </method>
<method name="share">
<return type="void" />
<param index="0" name="with" type="Node" />
@@ -59,7 +66,7 @@
If greater than 0, [code]value[/code] will always be rounded to a multiple of [code]step[/code]. If [code]rounded[/code] is also [code]true[/code], [code]value[/code] will first be rounded to a multiple of [code]step[/code] then rounded to the nearest integer.
</member>
<member name="value" type="float" setter="set_value" getter="get_value">
- Range's current value.
+ Range's current value. Changing this property (even via code) will trigger [signal value_changed] signal. Use [method set_value_no_signal] if you want to avoid it.
</member>
</members>
<signals>
diff --git a/scene/gui/base_button.cpp b/scene/gui/base_button.cpp
index 1082fc4d6d..ac9034c6fd 100644
--- a/scene/gui/base_button.cpp
+++ b/scene/gui/base_button.cpp
@@ -222,13 +222,12 @@ bool BaseButton::is_disabled() const {
}
void BaseButton::set_pressed(bool p_pressed) {
- if (!toggle_mode) {
- return;
- }
- if (status.pressed == p_pressed) {
+ bool prev_pressed = status.pressed;
+ set_pressed_no_signal(p_pressed);
+
+ if (status.pressed == prev_pressed) {
return;
}
- status.pressed = p_pressed;
if (p_pressed) {
_unpress_group();
@@ -237,8 +236,6 @@ void BaseButton::set_pressed(bool p_pressed) {
}
}
_toggled(status.pressed);
-
- queue_redraw();
}
void BaseButton::set_pressed_no_signal(bool p_pressed) {
diff --git a/scene/gui/range.cpp b/scene/gui/range.cpp
index 2d2b3e413d..27002fad38 100644
--- a/scene/gui/range.cpp
+++ b/scene/gui/range.cpp
@@ -80,6 +80,15 @@ void Range::Shared::emit_changed(const char *p_what) {
}
void Range::set_value(double p_val) {
+ double prev_val = shared->val;
+ set_value_no_signal(p_val);
+
+ if (shared->val != prev_val) {
+ shared->emit_value_changed();
+ }
+}
+
+void Range::set_value_no_signal(double p_val) {
if (shared->step > 0) {
p_val = Math::round(p_val / shared->step) * shared->step;
}
@@ -101,8 +110,6 @@ void Range::set_value(double p_val) {
}
shared->val = p_val;
-
- shared->emit_value_changed();
}
void Range::set_min(double p_min) {
@@ -267,6 +274,7 @@ void Range::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_page"), &Range::get_page);
ClassDB::bind_method(D_METHOD("get_as_ratio"), &Range::get_as_ratio);
ClassDB::bind_method(D_METHOD("set_value", "value"), &Range::set_value);
+ ClassDB::bind_method(D_METHOD("set_value_no_signal", "value"), &Range::set_value_no_signal);
ClassDB::bind_method(D_METHOD("set_min", "minimum"), &Range::set_min);
ClassDB::bind_method(D_METHOD("set_max", "maximum"), &Range::set_max);
ClassDB::bind_method(D_METHOD("set_step", "step"), &Range::set_step);
diff --git a/scene/gui/range.h b/scene/gui/range.h
index 19452243cf..f804155dec 100644
--- a/scene/gui/range.h
+++ b/scene/gui/range.h
@@ -72,6 +72,7 @@ protected:
public:
void set_value(double p_val);
+ void set_value_no_signal(double p_val);
void set_min(double p_min);
void set_max(double p_max);
void set_step(double p_step);