1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-21 14:57:09 +00:00

Fix some corner cases in the Menu/OptionButton item auto-highlight

This commit is contained in:
Michael Alexsander
2022-08-27 13:41:58 -03:00
parent 5beec641b6
commit 1e80b17a8d
6 changed files with 41 additions and 11 deletions

View File

@@ -62,9 +62,14 @@ void MenuButton::pressed() {
popup->set_scale(get_global_transform().get_scale());
popup->set_parent_rect(Rect2(Point2(gp - popup->get_global_position()), get_size()));
// If not triggered by the mouse, start the popup with its first item selected.
if (popup->get_item_count() > 0 && !_was_pressed_by_mouse()) {
popup->set_current_index(0);
// If not triggered by the mouse, start the popup with its first enabled item focused.
if (!_was_pressed_by_mouse()) {
for (int i = 0; i < popup->get_item_count(); i++) {
if (!popup->is_item_disabled(i)) {
popup->set_current_index(i);
break;
}
}
}
popup->popup();