feat: popover top position (#1403)

This commit is contained in:
Ashley Wulber 2026-08-24 20:28:46 -04:00 • committed by GitHub
parent ef490df50b
commit f8f5c7b5a6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 32 additions and 22 deletions

View file

@ -93,10 +93,10 @@ impl cosmic::Application for App {
cosmic::app::Action::Surface(action), cosmic::app::Action::Surface(action),
)); ));
} }
Message::WindowClose | Message::WindowClose
Message::ToggleHideContent | | Message::ToggleHideContent
Message::ToggleSomeAction | | Message::ToggleSomeAction
Message::WindowNew=> {} | Message::WindowNew => {}
} }
Task::none() Task::none()
@ -129,18 +129,19 @@ impl App {
menu::Item::Divider, menu::Item::Divider,
menu::Item::Folder( menu::Item::Folder(
"View", "View",
vec![menu::Item::CheckBox( vec![
"Hide content", menu::Item::CheckBox(
None, "Hide content",
self.hide_content, None,
ContextMenuAction::ToggleHideContent, self.hide_content,
), ContextMenuAction::ToggleHideContent,
menu::Item::CheckBox( ),
"Test content", menu::Item::CheckBox(
None, "Test content",
self.hide_content, None,
ContextMenuAction::ToggleSomeAction, self.hide_content,
) ContextMenuAction::ToggleSomeAction,
),
], ],
), ),
menu::Item::Divider, menu::Item::Divider,

View file

@ -650,12 +650,13 @@ impl<'b, Message: Clone + 'static> Menu<'b, Message> {
state.pressed = false; state.pressed = false;
// process close condition // process close condition
if state.open && state if state.open
.view_cursor && state
.position() .view_cursor
.unwrap_or_default() .position()
.distance(view_cursor.position().unwrap_or_default()) .unwrap_or_default()
< 2.0 .distance(view_cursor.position().unwrap_or_default())
< 2.0
{ {
let is_inside = state.menu_states[..=if self.is_overlay { let is_inside = state.menu_states[..=if self.is_overlay {
state.active_root.len().saturating_sub(1) state.active_root.len().saturating_sub(1)

View file

@ -24,6 +24,7 @@ pub enum Position {
#[default] #[default]
Center, Center,
Bottom, Bottom,
Top,
Point(Point), Point(Point),
} }
@ -260,6 +261,7 @@ where
Position::Point(relative) => { Position::Point(relative) => {
bounds.position() + Vector::new(relative.x, relative.y) 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 // 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.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.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::Bottom => {
// Position is set to the center bottom of the widget // Position is set to the center bottom of the widget
let width = node.size().width; let width = node.size().width;