diff options
author | RĂ©mi Verschelde <remi@verschelde.fr> | 2022-01-16 13:05:05 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-16 13:05:05 +0100 |
commit | 887898ba04a53a348b26ba4e7f8300fe60959bd2 (patch) | |
tree | 3a0d28fc64556c0e2608a73d1c8fcda12f6b49fc | |
parent | e527687e1eaefd711b60cfdd0d4bd064a01dde80 (diff) | |
parent | 4562106cbf1bbb7ae86a49fdee2ba9eeb69bd15e (diff) |
Merge pull request #42843 from rburing/optionbutton_focus
-rw-r--r-- | scene/gui/option_button.cpp | 1 | ||||
-rw-r--r-- | scene/gui/popup_menu.cpp | 7 | ||||
-rw-r--r-- | scene/gui/popup_menu.h | 1 |
3 files changed, 9 insertions, 0 deletions
diff --git a/scene/gui/option_button.cpp b/scene/gui/option_button.cpp index e955fde43a..90bb316448 100644 --- a/scene/gui/option_button.cpp +++ b/scene/gui/option_button.cpp @@ -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(); } diff --git a/scene/gui/popup_menu.cpp b/scene/gui/popup_menu.cpp index f4d45fe1fa..d7139d0140 100644 --- a/scene/gui/popup_menu.cpp +++ b/scene/gui/popup_menu.cpp @@ -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; } diff --git a/scene/gui/popup_menu.h b/scene/gui/popup_menu.h index 5d6b75cbf5..7c2212d82d 100644 --- a/scene/gui/popup_menu.h +++ b/scene/gui/popup_menu.h @@ -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); |