[MenuBar] Make menu start index more consistent.

This commit is contained in:
bruvzg 2024-09-02 22:48:58 +03:00
parent 05d985496c
commit 3da43ebec4
No known key found for this signature in database
GPG Key ID: 7960FCF39844EC38
2 changed files with 15 additions and 10 deletions

View File

@ -1,10 +1,10 @@
<?xml version="1.0" encoding="UTF-8" ?> <?xml version="1.0" encoding="UTF-8" ?>
<class name="MenuBar" inherits="Control" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd"> <class name="MenuBar" inherits="Control" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd">
<brief_description> <brief_description>
A horizontal menu bar that creates a [MenuButton] for each [PopupMenu] child. A horizontal menu bar that creates a menu for each [PopupMenu] child.
</brief_description> </brief_description>
<description> <description>
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.
</description> </description>
<tutorials> <tutorials>
</tutorials> </tutorials>
@ -105,9 +105,11 @@
</member> </member>
<member name="prefer_global_menu" type="bool" setter="set_prefer_global_menu" getter="is_prefer_global_menu" default="true"> <member name="prefer_global_menu" type="bool" setter="set_prefer_global_menu" getter="is_prefer_global_menu" default="true">
If [code]true[/code], [MenuBar] will use system global menu when supported. 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.
</member> </member>
<member name="start_index" type="int" setter="set_start_index" getter="get_start_index" default="-1"> <member name="start_index" type="int" setter="set_start_index" getter="get_start_index" default="-1">
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.
</member> </member>
<member name="switch_on_hover" type="bool" setter="set_switch_on_hover" getter="is_switch_on_hover" default="true"> <member name="switch_on_hover" type="bool" setter="set_switch_on_hover" getter="is_switch_on_hover" default="true">
If [code]true[/code], when the cursor hovers above menu item, it will close the current [PopupMenu] and open the other one. If [code]true[/code], when the cursor hovers above menu item, it will close the current [PopupMenu] and open the other one.

View File

@ -218,15 +218,18 @@ void MenuBar::bind_global_menu() {
int global_start_idx = -1; int global_start_idx = -1;
int count = nmenu->get_item_count(main_menu); int count = nmenu->get_item_count(main_menu);
String prev_tag; String prev_tag;
for (int i = 0; i < count; i++) { if (start_index >= 0) {
String tag = nmenu->get_item_tag(main_menu, i).operator String().get_slice("#", 1); for (int i = 0; i < count; i++) {
if (!tag.is_empty() && tag != prev_tag) { String tag = nmenu->get_item_tag(main_menu, i).operator String().get_slice("#", 1);
if (i >= start_index) { if (!tag.is_empty() && tag != prev_tag) {
global_start_idx = i; MenuBar *mb = Object::cast_to<MenuBar>(ObjectDB::get_instance(ObjectID(static_cast<uint64_t>(tag.to_int()))));
break; if (mb && mb->get_start_index() >= start_index) {
global_start_idx = i;
break;
}
} }
prev_tag = tag;
} }
prev_tag = tag;
} }
if (global_start_idx == -1) { if (global_start_idx == -1) {
global_start_idx = count; global_start_idx = count;