OptionButton::pressed(): give focus to selected

This commit is contained in:
Ricardo Buring 2020-10-16 01:04:30 +02:00
parent c99c5a1cae
commit 4562106cbf
3 changed files with 9 additions and 0 deletions

View file

@ -179,6 +179,7 @@ void OptionButton::pressed() {
Size2 size = get_size() * get_viewport()->get_canvas_transform().get_scale();
popup->set_position(get_screen_position() + Size2(0, size.height * get_global_transform().get_scale().y));
popup->set_size(Size2(size.width, 0));
popup->set_current_index(current);
popup->popup();
}

View file

@ -1269,6 +1269,13 @@ bool PopupMenu::is_item_shortcut_disabled(int p_idx) const {
return items[p_idx].shortcut_is_disabled;
}
void PopupMenu::set_current_index(int p_idx) {
ERR_FAIL_INDEX(p_idx, items.size());
mouse_over = p_idx;
_scroll_to_item(mouse_over);
control->update();
}
int PopupMenu::get_current_index() const {
return mouse_over;
}

View file

@ -212,6 +212,7 @@ public:
Ref<Shortcut> get_item_shortcut(int p_idx) const;
int get_item_state(int p_idx) const;
void set_current_index(int p_idx);
int get_current_index() const;
void set_item_count(int p_count);