forked from 1b-agent/opencadstudio-upstream
Sheet set row menus: clicks on separators, gaps and padding keep the menu open
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
582e0980d9
commit
74df837d6c
2 files changed
+10
-8
No files matched your search
@@ -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<bool>,
|
||||
/// 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<Message, Theme, Renderer> 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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -653,7 +653,7 @@ fn menu_box<'b>(items: Vec<Element<'b, Message>>) -> 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<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());
|
||||
}
|
||||
}
|
||||
keep_open.push(matches!(item, Mi::Sub(..)));
|
||||
keep_open.push(matches!(item, Mi::Sub(..) | Mi::Sep));
|
||||
}
|
||||
(menu_box(items), keep_open, flyout)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user