Skip to content

Commit

Permalink
Changed logic for submenus closing (#3055)
Browse files Browse the repository at this point in the history
This tiny change removes the trigger for a submenu to close if the mouse
is no longer hovering over it or one of its children. Now, the menu
stays open until a different menu item is selected. This aims to address
<#2853>.

I suspected that a new trigger would need to be implemented so that
multiple menu items don't remain open simultaneously, but after some
testing, this does not appear to occur.

This change leaves `MenuState::hovering_current_submenu` and
`MenuState::close_submenu` as dead code in case they might be useful
later.

---------

Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
  • Loading branch information
DannyStoll1 and emilk committed Jan 7, 2024
1 parent bfed2b4 commit 128afdd
Showing 1 changed file with 0 additions and 16 deletions.
16 changes: 0 additions & 16 deletions crates/egui/src/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -616,8 +616,6 @@ impl MenuState {
} else if !open && button.hovered() {
let pos = button.rect.right_top();
self.open_submenu(sub_id, pos);
} else if open && !button.hovered() && !self.hovering_current_submenu(&pointer) {
self.close_submenu();
}
}

Expand All @@ -642,16 +640,6 @@ impl MenuState {
false
}

/// Check if pointer is hovering current submenu.
fn hovering_current_submenu(&self, pointer: &PointerState) -> bool {
if let Some(sub_menu) = self.current_submenu() {
if let Some(pos) = pointer.hover_pos() {
return sub_menu.read().area_contains(pos);
}
}
false
}

/// Cascade close response to menu root.
fn cascade_close_response(&mut self, response: MenuResponse) {
if response.is_close() {
Expand Down Expand Up @@ -683,8 +671,4 @@ impl MenuState {
self.sub_menu = Some((id, Arc::new(RwLock::new(MenuState::new(pos)))));
}
}

fn close_submenu(&mut self) {
self.sub_menu = None;
}
}

0 comments on commit 128afdd

Please sign in to comment.