Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 23 additions & 4 deletions scene/gui/popup_menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,9 @@ void PopupMenu::_input_from_window_internal(const Ref<InputEvent> &p_event) {
if (!minimum_lifetime_timer->is_stopped()) {
// The mouse left the safe area, but came back again, so cancel the auto-closing.
minimum_lifetime_timer->stop();
if (PopupMenu *parent_pum = Object::cast_to<PopupMenu>(get_parent())) {
parent_pum->_hover_active_submenu_item();
}
}

if (mouse_over == -1 && !item_clickable_area.has_point(m->get_position())) {
Expand Down Expand Up @@ -765,9 +768,12 @@ void PopupMenu::_mouse_over_update(const Point2 &p_over) {
int id = (over < 0 || items[over].separator || items[over].disabled) ? -1 : (items[over].id >= 0 ? items[over].id : over);

if (id < 0) {
mouse_over = -1;
queue_accessibility_update();
control->queue_redraw();
// Only remove the hover if there's no open submenu, or the mouse is in an item that can't be hovered.
if (over >= 0 || !(mouse_over >= 0 && items[mouse_over].submenu && items[mouse_over].submenu->is_visible())) {
mouse_over = -1;
queue_accessibility_update();
control->queue_redraw();
}
return;
}

Expand Down Expand Up @@ -1083,6 +1089,19 @@ Rect2i PopupMenu::_popup_adjust_rect() const {
return current;
}

void PopupMenu::_hover_active_submenu_item() {
for (int i = 0; i < items.size(); i++) {
if (items[i].submenu && items[i].submenu->is_visible()) {
if (mouse_over != i) {
mouse_over = i;
queue_accessibility_update();
control->queue_redraw();
}
return;
}
}
}

void PopupMenu::add_child_notify(Node *p_child) {
Window::add_child_notify(p_child);

Expand Down Expand Up @@ -1271,7 +1290,7 @@ void PopupMenu::_notification(int p_what) {
} break;

case NOTIFICATION_WM_MOUSE_EXIT: {
if (mouse_over >= 0 && (!items[mouse_over].submenu || submenu_over != -1)) {
if (mouse_over >= 0 && (!items[mouse_over].submenu || !items[mouse_over].submenu->is_visible())) {
mouse_over = -1;
queue_accessibility_update();
control->queue_redraw();
Expand Down
2 changes: 2 additions & 0 deletions scene/gui/popup_menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,8 @@ class PopupMenu : public Popup {
String _atr(int p_idx, const String &p_text) const;

protected:
void _hover_active_submenu_item();

virtual void _pre_popup() override;
virtual Rect2i _popup_adjust_rect() const override;

Expand Down