diff options
author | RĂ©mi Verschelde <remi@verschelde.fr> | 2022-08-29 07:55:46 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-29 07:55:46 +0200 |
commit | 93cf2598348ab356658b8a53463c3ac1ba64086d (patch) | |
tree | 52f3ef216bb7438dbc0ebec579788c760f7abeeb /scene/gui | |
parent | 17825573399e141fbc92b3ef3022c04205c16468 (diff) | |
parent | 44c64b912fd9bc7adb1dd1ef2a829ae4803b6634 (diff) |
Merge pull request #64972 from YeldhamDev/you_too_menubar
Diffstat (limited to 'scene/gui')
-rw-r--r-- | scene/gui/menu_bar.cpp | 15 | ||||
-rw-r--r-- | scene/gui/menu_bar.h | 2 |
2 files changed, 13 insertions, 4 deletions
diff --git a/scene/gui/menu_bar.cpp b/scene/gui/menu_bar.cpp index 9eba2feaf7..9b7b67d83e 100644 --- a/scene/gui/menu_bar.cpp +++ b/scene/gui/menu_bar.cpp @@ -60,7 +60,7 @@ void MenuBar::gui_input(const Ref<InputEvent> &p_event) { if (active_menu >= 0) { get_menu_popup(active_menu)->hide(); } - _open_popup(selected_menu); + _open_popup(selected_menu, true); } return; } else if (p_event->is_action("ui_right") && p_event->is_pressed()) { @@ -82,7 +82,7 @@ void MenuBar::gui_input(const Ref<InputEvent> &p_event) { if (active_menu >= 0) { get_menu_popup(active_menu)->hide(); } - _open_popup(selected_menu); + _open_popup(selected_menu, true); } return; } @@ -110,7 +110,7 @@ void MenuBar::gui_input(const Ref<InputEvent> &p_event) { } } -void MenuBar::_open_popup(int p_index) { +void MenuBar::_open_popup(int p_index, bool p_focus_item) { ERR_FAIL_INDEX(p_index, menu_cache.size()); PopupMenu *pm = get_menu_popup(p_index); @@ -134,6 +134,15 @@ void MenuBar::_open_popup(int p_index) { pm->set_parent_rect(Rect2(Point2(screen_pos - pm->get_position()), Size2(screen_size.x, screen_pos.y))); pm->popup(); + if (p_focus_item) { + for (int i = 0; i < pm->get_item_count(); i++) { + if (!pm->is_item_disabled(i)) { + pm->set_current_index(i); + break; + } + } + } + update(); } diff --git a/scene/gui/menu_bar.h b/scene/gui/menu_bar.h index 3c4a25fd06..b7d9933ab2 100644 --- a/scene/gui/menu_bar.h +++ b/scene/gui/menu_bar.h @@ -84,7 +84,7 @@ class MenuBar : public Control { Vector<PopupMenu *> _get_popups() const; int get_menu_idx_from_control(PopupMenu *p_child) const; - void _open_popup(int p_index); + void _open_popup(int p_index, bool p_focus_item = false); void _popup_visibility_changed(bool p_visible); void _update_submenu(const String &p_menu_name, PopupMenu *p_child); void _clear_menu(); |