Changed logic for submenus closing (#3055)
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 <https://github.com/emilk/egui/issues/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>
This commit is contained in:
parent
bfed2b4195
commit
128afdde0a
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -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() {
|
||||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue