You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-04 12:00:25 +00:00
Fix PopupMenu losing item highlight when hovering submenus
This commit is contained in:
@@ -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())) {
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user