Make popup menus focus items automatically when not using the mouse

This commit is contained in:
Michael Alexsander
2022-01-20 08:44:27 -03:00
parent 203e07aa39
commit 73c225838f
4 changed files with 47 additions and 17 deletions

View File

@ -98,7 +98,13 @@ void MenuButton::pressed() {
popup->set_position(gp);
popup->set_parent_rect(Rect2(Point2(gp - popup->get_position()), size));
popup->take_mouse_focus();
// If not triggered by the mouse, start the popup with its first item selected.
if (popup->get_item_count() > 0 &&
((get_action_mode() == ActionMode::ACTION_MODE_BUTTON_PRESS && Input::get_singleton()->is_action_just_pressed("ui_accept")) ||
(get_action_mode() == ActionMode::ACTION_MODE_BUTTON_RELEASE && Input::get_singleton()->is_action_just_released("ui_accept")))) {
popup->set_current_index(0);
}
popup->popup();
}