Skip to content

Commit

Permalink
Revert "Changed logic for submenus closing (#3055)"
Browse files Browse the repository at this point in the history
This reverts commit 128afdd.
  • Loading branch information
emilk committed Mar 13, 2024
1 parent f019032 commit f2ff868
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions crates/egui/src/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,8 @@ 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,6 +644,16 @@ 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 @@ -673,4 +685,8 @@ impl MenuState {
self.sub_menu = Some((id, Arc::new(RwLock::new(Self::new(pos)))));
}
}

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

0 comments on commit f2ff868

Please sign in to comment.