Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Range: Fix cases where max was set to or below min value #33908

Merged
merged 1 commit into from
Nov 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions editor/plugins/animation_blend_space_1d_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -702,13 +702,13 @@ AnimationNodeBlendSpace1DEditor::AnimationNodeBlendSpace1DEditor() {
bottom_hb->set_h_size_flags(SIZE_EXPAND_FILL);

min_value = memnew(SpinBox);
min_value->set_max(0);
min_value->set_min(-10000);
min_value->set_max(0);
min_value->set_step(0.01);

max_value = memnew(SpinBox);
max_value->set_max(10000);
max_value->set_min(0.01);
max_value->set_max(10000);
max_value->set_step(0.01);

label_value = memnew(LineEdit);
Expand Down
6 changes: 3 additions & 3 deletions scene/gui/item_list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -969,16 +969,16 @@ void ItemList::_notification(int p_what) {
}

if (all_fit) {
float page = size.height - bg->get_minimum_size().height;
float page = MAX(0, size.height - bg->get_minimum_size().height);
float max = MAX(page, ofs.y + max_h);
if (auto_height)
auto_height_value = ofs.y + max_h + bg->get_minimum_size().height;
scroll_bar->set_max(max);
scroll_bar->set_page(page);
if (max <= page) {
scroll_bar->set_value(0);
scroll_bar->hide();
} else {
scroll_bar->set_max(max);
scroll_bar->set_page(page);
scroll_bar->show();

if (do_autoscroll_to_bottom)
Expand Down
2 changes: 2 additions & 0 deletions scene/gui/range.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ void Range::set_value(double p_val) {
shared->emit_value_changed();
}
void Range::set_min(double p_min) {
ERR_FAIL_COND_MSG(p_min >= shared->max, "Range cannot have min value higher or equal to its max value.");
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This wasn't a very good idea as it puts too strict requirements on how to set min and max values. For example, since the default min and max are 0 and 100, this triggers an error:

set_min(256)
set_max(16384)

Since min will be higher than max temporarily. It can be worked around by setting max first, but it's not really intuitive. I'll relax the requirement as it's only a problem in get_as_ratio, which already has a check.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed with 966c68b.


shared->min = p_min;
set_value(shared->val);
Expand All @@ -109,6 +110,7 @@ void Range::set_min(double p_min) {
update_configuration_warning();
}
void Range::set_max(double p_max) {
ERR_FAIL_COND_MSG(p_max <= shared->min, "Range cannot have max value lower or equal to its min value.");

shared->max = p_max;
set_value(shared->val);
Expand Down
2 changes: 0 additions & 2 deletions scene/gui/scroll_container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,6 @@ void ScrollContainer::update_scrollbars() {
if (hide_scroll_v) {

v_scroll->hide();
v_scroll->set_max(0);
scroll.y = 0;
} else {

Expand All @@ -406,7 +405,6 @@ void ScrollContainer::update_scrollbars() {
if (hide_scroll_h) {

h_scroll->hide();
h_scroll->set_max(0);
scroll.x = 0;
} else {

Expand Down
2 changes: 0 additions & 2 deletions scene/gui/text_edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,6 @@ void TextEdit::_update_scrollbars() {
cursor.line_ofs = 0;
cursor.wrap_ofs = 0;
v_scroll->set_value(0);
v_scroll->set_max(0);
v_scroll->hide();
}

Expand All @@ -436,7 +435,6 @@ void TextEdit::_update_scrollbars() {

cursor.x_ofs = 0;
h_scroll->set_value(0);
h_scroll->set_max(0);
h_scroll->hide();
}

Expand Down