diff --git a/src/ui/window/row_menu.rs b/src/ui/window/row_menu.rs index fc8ec518a..4f3f5a121 100644 --- a/src/ui/window/row_menu.rs +++ b/src/ui/window/row_menu.rs @@ -16,7 +16,7 @@ const FLYOUT_GAP: f32 = 2.0; pub(crate) struct RowMenu<'a> { underlay: Element<'a, Message>, main: Element<'a, Message>, - /// Per entry of the menu's column: a submenu entry (pressing it keeps the menu open). + /// Per child of the menu's column: a submenu entry or a separator (a click on it keeps the menu open). keep_open: Vec, /// The open fly-out: its entry's index in the column, and its content. flyout: Option<(usize, Element<'a, Message>)>, @@ -259,11 +259,13 @@ impl overlay::Overlay for MenuOverlay<'_, '_> { flyout.as_widget_mut().update(tree, event, fly, cursor, renderer, shell, &viewport); } if let Event::Mouse(mouse::Event::ButtonReleased(mouse::Button::Left)) = event { - // A chosen entry closes the menu; a submenu entry opens its fly-out instead. - let on_submenu = entries(main) - .zip(self.keep_open.iter()) - .any(|(e, keep)| *keep && cursor.is_over(e.bounds())); - if over && !on_submenu { + // Only a chosen entry closes the menu: a submenu entry opens its + // fly-out, and separators, gaps and padding do nothing. + let chosen = match entries(main).zip(self.keep_open.iter()).find(|(e, _)| cursor.is_over(e.bounds())) { + Some((_, keep)) => !keep, + None => fly.is_some_and(|f| entries(f).any(|e| cursor.is_over(e.bounds()))), + }; + if chosen { self.close(shell); } } diff --git a/src/ui/window/sheet_set.rs b/src/ui/window/sheet_set.rs index 72aabdc39..d136db048 100644 --- a/src/ui/window/sheet_set.rs +++ b/src/ui/window/sheet_set.rs @@ -653,7 +653,7 @@ fn menu_box<'b>(items: Vec>) -> Element<'b, Message> { .into() } -/// A row menu: the menu box, which of its entries open a fly-out, and the +/// A row menu: the menu box, which children keep it open when clicked (submenu entries, separators), and the /// open fly-out (its entry index and items). Hovering, pressing or right /// pressing a submenu entry opens its fly-out. fn menu_panel(menu: &[Mi], open: Option<&str>) -> (Element<'static, Message>, Vec, Option<(usize, Element<'static, Message>)>) { @@ -676,7 +676,7 @@ fn menu_panel(menu: &[Mi], open: Option<&str>) -> (Element<'static, Message>, Ve items.push(mouse_area(entry).on_enter(open_msg.clone()).on_right_press(open_msg).into()); } } - keep_open.push(matches!(item, Mi::Sub(..))); + keep_open.push(matches!(item, Mi::Sub(..) | Mi::Sep)); } (menu_box(items), keep_open, flyout) }