diff options
Diffstat (limited to 'native/src/widget')
-rw-r--r-- | native/src/widget/column.rs | 2 | ||||
-rw-r--r-- | native/src/widget/combo_box.rs | 68 | ||||
-rw-r--r-- | native/src/widget/container.rs | 2 | ||||
-rw-r--r-- | native/src/widget/row.rs | 2 | ||||
-rw-r--r-- | native/src/widget/scrollable.rs | 8 |
5 files changed, 36 insertions, 46 deletions
diff --git a/native/src/widget/column.rs b/native/src/widget/column.rs index 9a6dbdb3..e83ef93d 100644 --- a/native/src/widget/column.rs +++ b/native/src/widget/column.rs @@ -208,7 +208,7 @@ where fn overlay( &mut self, layout: Layout<'_>, - ) -> Option<Overlay<'a, Message, Renderer>> { + ) -> Option<Overlay<'_, Message, Renderer>> { self.children .iter_mut() .zip(layout.children()) diff --git a/native/src/widget/combo_box.rs b/native/src/widget/combo_box.rs index df2a530a..4a509354 100644 --- a/native/src/widget/combo_box.rs +++ b/native/src/widget/combo_box.rs @@ -10,7 +10,7 @@ pub struct ComboBox<'a, T, Message, Renderer: self::Renderer> where [T]: ToOwned<Owned = Vec<T>>, { - internal: Option<Internal<'a, T, Message>>, + internal: Internal<'a, T, Message>, options: Cow<'a, [T]>, selected: Option<T>, width: Length, @@ -42,10 +42,10 @@ where on_selected: impl Fn(T) -> Message + 'static, ) -> Self { Self { - internal: Some(Internal { + internal: Internal { menu: &mut state.menu, on_selected: Box::new(on_selected), - }), + }, options: options.into(), selected, width: Length::Shrink, @@ -180,16 +180,14 @@ where ) { match event { Event::Mouse(mouse::Event::ButtonPressed(mouse::Button::Left)) => { - if let Some(internal) = &mut self.internal { - if layout.bounds().contains(cursor_position) { - let selected = self.selected.as_ref(); - - internal.menu.open( - self.options - .iter() - .position(|option| Some(option) == selected), - ); - } + if layout.bounds().contains(cursor_position) { + let selected = self.selected.as_ref(); + + self.internal.menu.open( + self.options + .iter() + .position(|option| Some(option) == selected), + ); } } _ => {} @@ -217,33 +215,23 @@ where fn overlay( &mut self, layout: Layout<'_>, - ) -> Option<Overlay<'a, Message, Renderer>> { - let is_open = self - .internal - .as_ref() - .map(|internal| internal.menu.is_open()) - .unwrap_or(false); - - if is_open { - if let Some(Internal { menu, on_selected }) = self.internal.take() { - let bounds = layout.bounds(); - - Some(Overlay::new( - layout.position(), - Box::new(Menu::new( - menu, - self.options.clone(), - on_selected, - bounds.width.round() as u16, - bounds.height, - self.text_size.unwrap_or(20), - self.padding, - Renderer::menu_style(&self.style), - )), - )) - } else { - None - } + ) -> Option<Overlay<'_, Message, Renderer>> { + if self.internal.menu.is_open() { + let bounds = layout.bounds(); + + Some(Overlay::new( + layout.position(), + Box::new(Menu::new( + self.internal.menu, + self.options.clone(), + &self.internal.on_selected, + bounds.width.round() as u16, + bounds.height, + self.text_size, + self.padding, + Renderer::menu_style(&self.style), + )), + )) } else { None } diff --git a/native/src/widget/container.rs b/native/src/widget/container.rs index 3bdb1a27..4ab10837 100644 --- a/native/src/widget/container.rs +++ b/native/src/widget/container.rs @@ -218,7 +218,7 @@ where fn overlay( &mut self, layout: Layout<'_>, - ) -> Option<Overlay<'a, Message, Renderer>> { + ) -> Option<Overlay<'_, Message, Renderer>> { self.content.overlay(layout.children().next().unwrap()) } } diff --git a/native/src/widget/row.rs b/native/src/widget/row.rs index 25bd641f..1cfe2d66 100644 --- a/native/src/widget/row.rs +++ b/native/src/widget/row.rs @@ -210,7 +210,7 @@ where fn overlay( &mut self, layout: Layout<'_>, - ) -> Option<Overlay<'a, Message, Renderer>> { + ) -> Option<Overlay<'_, Message, Renderer>> { self.children .iter_mut() .zip(layout.children()) diff --git a/native/src/widget/scrollable.rs b/native/src/widget/scrollable.rs index 92e5265a..87871e28 100644 --- a/native/src/widget/scrollable.rs +++ b/native/src/widget/scrollable.rs @@ -319,14 +319,16 @@ where fn overlay( &mut self, layout: Layout<'_>, - ) -> Option<Overlay<'a, Message, Renderer>> { - self.content + ) -> Option<Overlay<'_, Message, Renderer>> { + let Self { content, state, .. } = self; + + content .overlay(layout.children().next().unwrap()) .map(|overlay| { let bounds = layout.bounds(); let content_layout = layout.children().next().unwrap(); let content_bounds = content_layout.bounds(); - let offset = self.state.offset(bounds, content_bounds); + let offset = state.offset(bounds, content_bounds); overlay.translate(Vector::new(0.0, -(offset as f32))) }) |