summaryrefslogtreecommitdiff
path: root/scene/gui/range.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'scene/gui/range.cpp')
-rw-r--r--scene/gui/range.cpp33
1 files changed, 19 insertions, 14 deletions
diff --git a/scene/gui/range.cpp b/scene/gui/range.cpp
index 2d2b3e413d..e0e4ead55f 100644
--- a/scene/gui/range.cpp
+++ b/scene/gui/range.cpp
@@ -64,11 +64,6 @@ void Range::_changed_notify(const char *p_what) {
queue_redraw();
}
-void Range::_validate_values() {
- shared->max = MAX(shared->max, shared->min);
- shared->page = CLAMP(shared->page, 0, shared->max - shared->min);
-}
-
void Range::Shared::emit_changed(const char *p_what) {
for (Range *E : owners) {
Range *r = E;
@@ -80,6 +75,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 +105,6 @@ void Range::set_value(double p_val) {
}
shared->val = p_val;
-
- shared->emit_value_changed();
}
void Range::set_min(double p_min) {
@@ -111,8 +113,9 @@ void Range::set_min(double p_min) {
}
shared->min = p_min;
+ shared->max = MAX(shared->max, shared->min);
+ shared->page = CLAMP(shared->page, 0, shared->max - shared->min);
set_value(shared->val);
- _validate_values();
shared->emit_changed("min");
@@ -120,13 +123,14 @@ void Range::set_min(double p_min) {
}
void Range::set_max(double p_max) {
- if (shared->max == p_max) {
+ double max_validated = MAX(p_max, shared->min);
+ if (shared->max == max_validated) {
return;
}
- shared->max = p_max;
+ shared->max = max_validated;
+ shared->page = CLAMP(shared->page, 0, shared->max - shared->min);
set_value(shared->val);
- _validate_values();
shared->emit_changed("max");
}
@@ -141,13 +145,13 @@ void Range::set_step(double p_step) {
}
void Range::set_page(double p_page) {
- if (shared->page == p_page) {
+ double page_validated = CLAMP(p_page, 0, shared->max - shared->min);
+ if (shared->page == page_validated) {
return;
}
- shared->page = p_page;
+ shared->page = page_validated;
set_value(shared->val);
- _validate_values();
shared->emit_changed("page");
}
@@ -267,6 +271,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);