summaryrefslogtreecommitdiffstats
path: root/native/src/widget/combo_box.rs
diff options
context:
space:
mode:
Diffstat (limited to 'native/src/widget/combo_box.rs')
-rw-r--r--native/src/widget/combo_box.rs42
1 files changed, 17 insertions, 25 deletions
diff --git a/native/src/widget/combo_box.rs b/native/src/widget/combo_box.rs
index f2dc86e8..f6da076a 100644
--- a/native/src/widget/combo_box.rs
+++ b/native/src/widget/combo_box.rs
@@ -10,7 +10,8 @@ pub struct ComboBox<'a, T, Message, Renderer: self::Renderer>
where
[T]: ToOwned<Owned = Vec<T>>,
{
- internal: Internal<'a, T, Message>,
+ menu: &'a mut menu::State,
+ on_selected: Box<dyn Fn(T) -> Message>,
options: Cow<'a, [T]>,
selected: Option<T>,
width: Length,
@@ -24,11 +25,6 @@ pub struct State {
menu: menu::State,
}
-pub struct Internal<'a, T, Message> {
- menu: &'a mut menu::State,
- on_selected: Box<dyn Fn(T) -> Message>,
-}
-
impl<'a, T: 'a, Message, Renderer: self::Renderer>
ComboBox<'a, T, Message, Renderer>
where
@@ -42,10 +38,8 @@ where
on_selected: impl Fn(T) -> Message + 'static,
) -> Self {
Self {
- internal: Internal {
- menu: &mut state.menu,
- on_selected: Box::new(on_selected),
- },
+ menu: &mut state.menu,
+ on_selected: Box::new(on_selected),
options: options.into(),
selected,
width: Length::Shrink,
@@ -183,7 +177,7 @@ where
if layout.bounds().contains(cursor_position) {
let selected = self.selected.as_ref();
- self.internal.menu.open(
+ self.menu.open(
self.options
.iter()
.position(|option| Some(option) == selected),
@@ -216,22 +210,20 @@ where
&mut self,
layout: Layout<'_>,
) -> Option<Overlay<'_, Message, Renderer>> {
- if self.internal.menu.is_open() {
+ if self.menu.is_open() {
let bounds = layout.bounds();
- Some(Overlay::new(
- layout.position(),
- Box::new(Menu::new(
- self.internal.menu,
- &self.options,
- &self.internal.on_selected,
- bounds.width.round() as u16,
- bounds.height,
- self.text_size,
- self.padding,
- Renderer::menu_style(&self.style),
- )),
- ))
+ let mut menu =
+ Menu::new(&mut self.menu, &self.options, &self.on_selected)
+ .width(bounds.width.round() as u16)
+ .padding(self.padding)
+ .style(Renderer::menu_style(&self.style));
+
+ if let Some(text_size) = self.text_size {
+ menu = menu.text_size(text_size);
+ }
+
+ Some(menu.overlay(layout.position(), bounds.height))
} else {
None
}