summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <remi@verschelde.fr>2021-11-18 13:02:02 +0100
committerGitHub <noreply@github.com>2021-11-18 13:02:02 +0100
commitbae15cb90ed18ea36c68c6fff47ca69f91660d8a (patch)
treeb0630087ea832192c1e1dc79368e877eb5019c81
parenta3850ba05094ce6026c6a60241e1bd82f1d3b826 (diff)
parent81c0fe836c92f5b6ae755ceed06dd5fb62b053e1 (diff)
Merge pull request #53602 from KoBeWi/mountain_range
-rw-r--r--scene/gui/range.cpp14
-rw-r--r--scene/gui/range.h1
2 files changed, 15 insertions, 0 deletions
diff --git a/scene/gui/range.cpp b/scene/gui/range.cpp
index 92d4261d8d..c4f05a7975 100644
--- a/scene/gui/range.cpp
+++ b/scene/gui/range.cpp
@@ -61,6 +61,11 @@ void Range::_changed_notify(const char *p_what) {
update();
}
+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 (Set<Range *>::Element *E = owners.front(); E; E = E->next()) {
Range *r = E->get();
@@ -100,6 +105,7 @@ void Range::set_value(double p_val) {
void Range::set_min(double p_min) {
shared->min = p_min;
set_value(shared->val);
+ _validate_values();
shared->emit_changed("min");
@@ -109,6 +115,7 @@ void Range::set_min(double p_min) {
void Range::set_max(double p_max) {
shared->max = p_max;
set_value(shared->val);
+ _validate_values();
shared->emit_changed("max");
}
@@ -121,6 +128,7 @@ void Range::set_step(double p_step) {
void Range::set_page(double p_page) {
shared->page = p_page;
set_value(shared->val);
+ _validate_values();
shared->emit_changed("page");
}
@@ -270,6 +278,12 @@ void Range::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "rounded"), "set_use_rounded_values", "is_using_rounded_values");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "allow_greater"), "set_allow_greater", "is_greater_allowed");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "allow_lesser"), "set_allow_lesser", "is_lesser_allowed");
+
+ ADD_LINKED_PROPERTY("min_value", "value");
+ ADD_LINKED_PROPERTY("min_value", "max_value");
+ ADD_LINKED_PROPERTY("min_value", "page");
+ ADD_LINKED_PROPERTY("max_value", "value");
+ ADD_LINKED_PROPERTY("max_value", "page");
}
void Range::set_use_rounded_values(bool p_enable) {
diff --git a/scene/gui/range.h b/scene/gui/range.h
index 7a129e88d6..0dc702b19c 100644
--- a/scene/gui/range.h
+++ b/scene/gui/range.h
@@ -59,6 +59,7 @@ class Range : public Control {
void _value_changed_notify();
void _changed_notify(const char *p_what = "");
+ void _validate_values();
protected:
virtual void _value_changed(double) {}