feat: popover top position (#1403)
This commit is contained in:
parent
ef490df50b
commit
f8f5c7b5a6
3 changed files with 32 additions and 22 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue