diff --git a/examples/context-menu/src/main.rs b/examples/context-menu/src/main.rs index a953c8ed..50c76bfb 100644 --- a/examples/context-menu/src/main.rs +++ b/examples/context-menu/src/main.rs @@ -93,10 +93,10 @@ impl cosmic::Application for App { cosmic::app::Action::Surface(action), )); } - Message::WindowClose | - Message::ToggleHideContent | - Message::ToggleSomeAction | - Message::WindowNew=> {} + Message::WindowClose + | Message::ToggleHideContent + | Message::ToggleSomeAction + | Message::WindowNew => {} } Task::none() @@ -129,18 +129,19 @@ impl App { menu::Item::Divider, menu::Item::Folder( "View", - vec![menu::Item::CheckBox( - "Hide content", - None, - self.hide_content, - ContextMenuAction::ToggleHideContent, - ), - menu::Item::CheckBox( - "Test content", - None, - self.hide_content, - ContextMenuAction::ToggleSomeAction, - ) + vec![ + menu::Item::CheckBox( + "Hide content", + None, + self.hide_content, + ContextMenuAction::ToggleHideContent, + ), + menu::Item::CheckBox( + "Test content", + None, + self.hide_content, + ContextMenuAction::ToggleSomeAction, + ), ], ), menu::Item::Divider, diff --git a/src/widget/menu/menu_inner.rs b/src/widget/menu/menu_inner.rs index 48b0f4ea..0ec6110b 100644 --- a/src/widget/menu/menu_inner.rs +++ b/src/widget/menu/menu_inner.rs @@ -650,12 +650,13 @@ impl<'b, Message: Clone + 'static> Menu<'b, Message> { state.pressed = false; // process close condition - if state.open && state - .view_cursor - .position() - .unwrap_or_default() - .distance(view_cursor.position().unwrap_or_default()) - < 2.0 + if state.open + && state + .view_cursor + .position() + .unwrap_or_default() + .distance(view_cursor.position().unwrap_or_default()) + < 2.0 { let is_inside = state.menu_states[..=if self.is_overlay { state.active_root.len().saturating_sub(1) diff --git a/src/widget/popover.rs b/src/widget/popover.rs index c822899d..4368925e 100644 --- a/src/widget/popover.rs +++ b/src/widget/popover.rs @@ -24,6 +24,7 @@ pub enum Position { #[default] Center, Bottom, + Top, Point(Point), } @@ -260,6 +261,7 @@ where Position::Point(relative) => { bounds.position() + Vector::new(relative.x, relative.y) } + Position::Top => Point::new(bounds.x + bounds.width / 2.0, bounds.y), }; // Round position to prevent rendering issues @@ -354,6 +356,12 @@ where position.x = (position.x - width / 2.0).clamp(0.0, bounds.width - width); position.y = (position.y - height / 2.0).clamp(0.0, bounds.height - height); } + Position::Top => { + let width = node.size().width; + let height = node.size().height; + position.x = (position.x - width / 2.0).clamp(0.0, bounds.width - width); + position.y = (position.y - height).clamp(0.0, bounds.height - height); + } Position::Bottom => { // Position is set to the center bottom of the widget let width = node.size().width;