Use closures for PickList::style

This commit is contained in:
Héctor Ramón Jiménez 2024-03-12 16:40:56 +01:00
parent 3e190b9ee0
commit b721fd935c
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
3 changed files with 42 additions and 96 deletions

View file

@ -42,7 +42,7 @@ pub struct ComboBox<
on_option_hovered: Option<Box<dyn Fn(T) -> Message>>,
on_close: Option<Message>,
on_input: Option<Box<dyn Fn(String) -> Message>>,
menu_style: menu::Style<Theme>,
menu_style: menu::Style<'a, Theme>,
padding: Padding,
size: Option<f32>,
}
@ -125,7 +125,7 @@ where
}
/// Sets the style of the [`ComboBox`].
pub fn style(mut self, style: impl Into<Style<Theme>>) -> Self
pub fn style(mut self, style: impl Into<Style<'a, Theme>>) -> Self
where
Theme: 'a,
{
@ -672,7 +672,7 @@ where
self.state.sync_filtered_options(filtered_options);
let mut menu = menu::Menu::with_style(
let mut menu = menu::Menu::new(
menu,
&filtered_options.options,
hovered_option,
@ -686,7 +686,7 @@ where
(self.on_selected)(x)
},
self.on_option_hovered.as_deref(),
self.menu_style,
&self.menu_style,
)
.width(bounds.width)
.padding(self.padding);
@ -765,27 +765,27 @@ where
/// The style of a [`ComboBox`].
#[allow(missing_debug_implementations)]
pub struct Style<Theme> {
pub struct Style<'a, Theme> {
/// The style of the [`TextInput`] of the [`ComboBox`].
pub text_input: text_input::Style<'static, Theme>,
pub text_input: text_input::Style<'a, Theme>,
/// The style of the [`Menu`] of the [`ComboBox`].
///
/// [`Menu`]: menu::Menu
pub menu: menu::Style<Theme>,
pub menu: menu::Style<'a, Theme>,
}
/// The default style of a [`ComboBox`].
pub trait DefaultStyle: Sized {
/// Returns the default style of a [`ComboBox`].
fn default_style() -> Style<Self>;
fn default_style() -> Style<'static, Self>;
}
impl DefaultStyle for Theme {
fn default_style() -> Style<Self> {
fn default_style() -> Style<'static, Self> {
Style {
text_input: Box::new(text_input::default),
menu: menu::Style::DEFAULT,
menu: menu::DefaultStyle::default_style(),
}
}
}