summaryrefslogtreecommitdiffstats
path: root/native/src/layer/menu.rs
diff options
context:
space:
mode:
Diffstat (limited to 'native/src/layer/menu.rs')
-rw-r--r--native/src/layer/menu.rs24
1 files changed, 21 insertions, 3 deletions
diff --git a/native/src/layer/menu.rs b/native/src/layer/menu.rs
index 9e26767b..05026a54 100644
--- a/native/src/layer/menu.rs
+++ b/native/src/layer/menu.rs
@@ -1,6 +1,7 @@
use crate::{
container, layout, mouse, scrollable, Clipboard, Container, Element, Event,
- Hasher, Layer, Layout, Length, Point, Rectangle, Scrollable, Size, Widget,
+ Hasher, Layer, Layout, Length, Point, Rectangle, Scrollable, Size, Vector,
+ Widget,
};
use std::borrow::Cow;
@@ -8,6 +9,7 @@ pub struct Menu<'a, Message, Renderer: self::Renderer> {
container: Container<'a, Message, Renderer>,
is_open: &'a mut bool,
width: u16,
+ target_height: f32,
}
#[derive(Default)]
@@ -38,6 +40,7 @@ where
options: impl Into<Cow<'a, [T]>>,
on_selected: Box<dyn Fn(T) -> Message>,
width: u16,
+ target_height: f32,
text_size: u16,
padding: u16,
) -> Self
@@ -60,6 +63,7 @@ where
container,
is_open: &mut state.is_open,
width,
+ target_height,
}
}
}
@@ -75,15 +79,29 @@ where
bounds: Size,
position: Point,
) -> layout::Node {
+ let space_below = bounds.height - (position.y + self.target_height);
+ let space_above = position.y;
+
let limits = layout::Limits::new(
Size::ZERO,
- Size::new(bounds.width - position.x, bounds.height - position.y),
+ Size::new(
+ bounds.width - position.x,
+ if space_below > space_above {
+ space_below
+ } else {
+ space_above
+ },
+ ),
)
.width(Length::Units(self.width));
let mut node = self.container.layout(renderer, &limits);
- node.move_to(position);
+ node.move_to(if space_below > space_above {
+ position + Vector::new(0.0, self.target_height)
+ } else {
+ position - Vector::new(0.0, node.size().height)
+ });
node
}