Sheet set row menus: clicks on separators, gaps and padding keep the menu open

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
ramox81andClaude Opus 5.5 committed 2026-10-05 16:35:49 +03:00
1 parent 582e0980d9
commit 74df837d6c
2 files changed
+10 -8

No files matched your search

+8 -6
View File
@@ -16,7 +16,7 @@ const FLYOUT_GAP: f32 = 2.0;
pub(crate) struct RowMenu<'a> { pub(crate) struct RowMenu<'a> {
underlay: Element<'a, Message>, underlay: Element<'a, Message>,
main: 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<bool>, keep_open: Vec<bool>,
/// The open fly-out: its entry's index in the column, and its content. /// The open fly-out: its entry's index in the column, and its content.
flyout: Option<(usize, Element<'a, Message>)>, flyout: Option<(usize, Element<'a, Message>)>,
@@ -259,11 +259,13 @@ impl overlay::Overlay<Message, Theme, Renderer> for MenuOverlay<'_, '_> {
flyout.as_widget_mut().update(tree, event, fly, cursor, renderer, shell, &viewport); flyout.as_widget_mut().update(tree, event, fly, cursor, renderer, shell, &viewport);
} }
if let Event::Mouse(mouse::Event::ButtonReleased(mouse::Button::Left)) = event { 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. // Only a chosen entry closes the menu: a submenu entry opens its
let on_submenu = entries(main) // fly-out, and separators, gaps and padding do nothing.
.zip(self.keep_open.iter()) let chosen = match entries(main).zip(self.keep_open.iter()).find(|(e, _)| cursor.is_over(e.bounds())) {
.any(|(e, keep)| *keep && cursor.is_over(e.bounds())); Some((_, keep)) => !keep,
if over && !on_submenu { None => fly.is_some_and(|f| entries(f).any(|e| cursor.is_over(e.bounds()))),
};
if chosen {
self.close(shell); self.close(shell);
} }
} }
+2 -2
View File
@@ -653,7 +653,7 @@ fn menu_box<'b>(items: Vec<Element<'b, Message>>) -> Element<'b, Message> {
.into() .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 /// open fly-out (its entry index and items). Hovering, pressing or right
/// pressing a submenu entry opens its fly-out. /// pressing a submenu entry opens its fly-out.
fn menu_panel(menu: &[Mi], open: Option<&str>) -> (Element<'static, Message>, Vec<bool>, Option<(usize, Element<'static, Message>)>) { fn menu_panel(menu: &[Mi], open: Option<&str>) -> (Element<'static, Message>, Vec<bool>, 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()); 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) (menu_box(items), keep_open, flyout)
} }