summaryrefslogtreecommitdiff
path: root/scene/gui/menu_bar.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'scene/gui/menu_bar.cpp')
-rw-r--r--scene/gui/menu_bar.cpp22
1 files changed, 14 insertions, 8 deletions
diff --git a/scene/gui/menu_bar.cpp b/scene/gui/menu_bar.cpp
index f450222130..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();
}
@@ -276,10 +285,7 @@ void MenuBar::_update_submenu(const String &p_menu_name, PopupMenu *p_child) {
}
bool MenuBar::is_native_menu() const {
- if (!is_visible_in_tree()) {
- return false;
- }
- if (Engine::get_singleton()->is_editor_hint() && get_tree()->get_edited_scene_root() && (get_tree()->get_edited_scene_root()->is_ancestor_of(this) || get_tree()->get_edited_scene_root() == this)) {
+ if (Engine::get_singleton()->is_editor_hint() && is_inside_tree() && get_tree()->get_edited_scene_root() && (get_tree()->get_edited_scene_root()->is_ancestor_of(this) || get_tree()->get_edited_scene_root() == this)) {
return false;
}
@@ -308,7 +314,7 @@ void MenuBar::_clear_menu() {
void MenuBar::_update_menu() {
_clear_menu();
- if (!is_inside_tree()) {
+ if (!is_visible_in_tree()) {
return;
}