Skip to content

Commit

Permalink
Fix PopupMenu items id range in inspector
Browse files Browse the repository at this point in the history
  • Loading branch information
rafallus committed Jan 8, 2022
1 parent 8bb1638 commit 38d578e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion scene/gui/menu_button.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ void MenuButton::_get_property_list(List<PropertyInfo> *p_list) const {
pi.usage &= ~(!popup->is_item_checked(i) ? PROPERTY_USAGE_STORAGE : 0);
p_list->push_back(pi);

pi = PropertyInfo(Variant::INT, vformat("popup/item_%d/id", i), PROPERTY_HINT_RANGE, "1,10,1,or_greater");
pi = PropertyInfo(Variant::INT, vformat("popup/item_%d/id", i), PROPERTY_HINT_RANGE, "0,10,1,or_greater");
p_list->push_back(pi);

pi = PropertyInfo(Variant::BOOL, vformat("popup/item_%d/disabled", i));
Expand Down
10 changes: 9 additions & 1 deletion scene/gui/popup_menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1275,7 +1275,15 @@ int PopupMenu::get_current_index() const {

void PopupMenu::set_item_count(int p_count) {
ERR_FAIL_COND(p_count < 0);
int prev_size = items.size();
items.resize(p_count);

if (prev_size < p_count) {
for (int i = prev_size; i < p_count; i++) {
items.write[i].id = i;
}
}

control->update();
child_controls_changed();
notify_property_list_changed();
Expand Down Expand Up @@ -1658,7 +1666,7 @@ void PopupMenu::_get_property_list(List<PropertyInfo> *p_list) const {
pi.usage &= ~(!is_item_checked(i) ? PROPERTY_USAGE_STORAGE : 0);
p_list->push_back(pi);

pi = PropertyInfo(Variant::INT, vformat("item_%d/id", i), PROPERTY_HINT_RANGE, "1,10,1,or_greater");
pi = PropertyInfo(Variant::INT, vformat("item_%d/id", i), PROPERTY_HINT_RANGE, "0,10,1,or_greater");
p_list->push_back(pi);

pi = PropertyInfo(Variant::BOOL, vformat("item_%d/disabled", i));
Expand Down

0 comments on commit 38d578e

Please sign in to comment.