Improve validation when setting `max`/`min`/`page` in `Range`
The incoming value is validated first and then compared. Previously, when the ScrollContainer was scrolled, the ScrollBar of the other axis of the ScrollContainer would emit the changed signal. This commit avoids that.
This commit is contained in:
parent
a8c805be29
commit
075e79bf04
|
@ -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;
|
||||
|
@ -111,8 +106,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 +116,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 +138,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");
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue