Merge pull request #67660 from Rindbee/improve-setter-for-Range

Improve validation when setting `max`/`min`/`page` in `Range`
This commit is contained in:
Rémi Verschelde 2022-12-01 18:11:01 +01:00
commit e5f0a565e2
No known key found for this signature in database
GPG Key ID: C3336907360768E1
2 changed files with 9 additions and 13 deletions

View File

@ -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;
@ -118,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");
@ -127,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");
}
@ -148,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");
}

View File

@ -59,7 +59,6 @@ class Range : public Control {
void _value_changed_notify();
void _changed_notify(const char *p_what = "");
void _validate_values();
protected:
virtual void _value_changed(double p_value);