From 3da43ebec475d71071b907c0c8c5ded2575adb92 Mon Sep 17 00:00:00 2001 From: bruvzg <7645683+bruvzg@users.noreply.github.com> Date: Mon, 2 Sep 2024 22:48:58 +0300 Subject: [PATCH] [MenuBar] Make menu start index more consistent. --- doc/classes/MenuBar.xml | 8 +++++--- scene/gui/menu_bar.cpp | 17 ++++++++++------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/doc/classes/MenuBar.xml b/doc/classes/MenuBar.xml index 9e4287331c6..bcf63f06103 100644 --- a/doc/classes/MenuBar.xml +++ b/doc/classes/MenuBar.xml @@ -1,10 +1,10 @@ - A horizontal menu bar that creates a [MenuButton] for each [PopupMenu] child. + A horizontal menu bar that creates a menu for each [PopupMenu] child. - A horizontal menu bar that creates a [MenuButton] for each [PopupMenu] child. New items are created by adding [PopupMenu]s to this node. + A horizontal menu bar that creates a menu for each [PopupMenu] child. New items are created by adding [PopupMenu]s to this node. @@ -105,9 +105,11 @@ If [code]true[/code], [MenuBar] will use system global menu when supported. + [b]Note:[/b] If [code]true[/code] and global menu is supported, this node is not displayed, has zero size, and all its child nodes except [PopupMenu]s are inaccessible. + [b]Note:[/b] This property overrides the value of the [member PopupMenu.prefer_native_menu] property of the child nodes. - Position in the global menu to insert first [MenuBar] item at. + Position order in the global menu to insert [MenuBar] items at. All menu items in the [MenuBar] are always inserted as a continuous range. Menus with lower [member start_index] are inserted first. Menus with [member start_index] equal to [code]-1[/code] are inserted last. If [code]true[/code], when the cursor hovers above menu item, it will close the current [PopupMenu] and open the other one. diff --git a/scene/gui/menu_bar.cpp b/scene/gui/menu_bar.cpp index c8b022d622d..46c9c7cccca 100644 --- a/scene/gui/menu_bar.cpp +++ b/scene/gui/menu_bar.cpp @@ -218,15 +218,18 @@ void MenuBar::bind_global_menu() { int global_start_idx = -1; int count = nmenu->get_item_count(main_menu); String prev_tag; - for (int i = 0; i < count; i++) { - String tag = nmenu->get_item_tag(main_menu, i).operator String().get_slice("#", 1); - if (!tag.is_empty() && tag != prev_tag) { - if (i >= start_index) { - global_start_idx = i; - break; + if (start_index >= 0) { + for (int i = 0; i < count; i++) { + String tag = nmenu->get_item_tag(main_menu, i).operator String().get_slice("#", 1); + if (!tag.is_empty() && tag != prev_tag) { + MenuBar *mb = Object::cast_to(ObjectDB::get_instance(ObjectID(static_cast(tag.to_int())))); + if (mb && mb->get_start_index() >= start_index) { + global_start_idx = i; + break; + } } + prev_tag = tag; } - prev_tag = tag; } if (global_start_idx == -1) { global_start_idx = count;