Skip to content

Commit 250ef8d

Browse files
committed
Merge pull request #112095 from YeldhamDev/subpop_hl_fix
Fix `PopupMenu` losing item highlight when hovering submenus
2 parents 64b1828 + c5fe5d4 commit 250ef8d

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

scene/gui/popup_menu.cpp

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -709,6 +709,9 @@ void PopupMenu::_input_from_window_internal(const Ref<InputEvent> &p_event) {
709709
if (!minimum_lifetime_timer->is_stopped()) {
710710
// The mouse left the safe area, but came back again, so cancel the auto-closing.
711711
minimum_lifetime_timer->stop();
712+
if (PopupMenu *parent_pum = Object::cast_to<PopupMenu>(get_parent())) {
713+
parent_pum->_hover_active_submenu_item();
714+
}
712715
}
713716

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

767770
if (id < 0) {
768-
mouse_over = -1;
769-
queue_accessibility_update();
770-
control->queue_redraw();
771+
// Only remove the hover if there's no open submenu, or the mouse is in an item that can't be hovered.
772+
if (over >= 0 || !(mouse_over >= 0 && items[mouse_over].submenu && items[mouse_over].submenu->is_visible())) {
773+
mouse_over = -1;
774+
queue_accessibility_update();
775+
control->queue_redraw();
776+
}
771777
return;
772778
}
773779

@@ -1083,6 +1089,19 @@ Rect2i PopupMenu::_popup_adjust_rect() const {
10831089
return current;
10841090
}
10851091

1092+
void PopupMenu::_hover_active_submenu_item() {
1093+
for (int i = 0; i < items.size(); i++) {
1094+
if (items[i].submenu && items[i].submenu->is_visible()) {
1095+
if (mouse_over != i) {
1096+
mouse_over = i;
1097+
queue_accessibility_update();
1098+
control->queue_redraw();
1099+
}
1100+
return;
1101+
}
1102+
}
1103+
}
1104+
10861105
void PopupMenu::add_child_notify(Node *p_child) {
10871106
Window::add_child_notify(p_child);
10881107

@@ -1271,7 +1290,7 @@ void PopupMenu::_notification(int p_what) {
12711290
} break;
12721291

12731292
case NOTIFICATION_WM_MOUSE_EXIT: {
1274-
if (mouse_over >= 0 && (!items[mouse_over].submenu || submenu_over != -1)) {
1293+
if (mouse_over >= 0 && (!items[mouse_over].submenu || !items[mouse_over].submenu->is_visible())) {
12751294
mouse_over = -1;
12761295
queue_accessibility_update();
12771296
control->queue_redraw();

scene/gui/popup_menu.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,8 @@ class PopupMenu : public Popup {
228228
String _atr(int p_idx, const String &p_text) const;
229229

230230
protected:
231+
void _hover_active_submenu_item();
232+
231233
virtual void _pre_popup() override;
232234
virtual Rect2i _popup_adjust_rect() const override;
233235

0 commit comments

Comments
 (0)