From 833538ee7f3a60a839304762dfc29b0881d19094 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Thu, 7 Mar 2024 20:11:32 +0100 Subject: Leverage `DefaultStyle` traits instead of `Default` --- widget/src/combo_box.rs | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) (limited to 'widget/src/combo_box.rs') diff --git a/widget/src/combo_box.rs b/widget/src/combo_box.rs index 62c19137..44830d8a 100644 --- a/widget/src/combo_box.rs +++ b/widget/src/combo_box.rs @@ -62,9 +62,9 @@ where on_selected: impl Fn(T) -> Message + 'static, ) -> Self where - Style: Default, + Theme: DefaultStyle, { - let style = Style::::default(); + let style = Theme::default_style(); let text_input = TextInput::with_style( placeholder, @@ -762,7 +762,7 @@ where .collect() } -/// The appearance of a [`ComboBox`]. +/// The style of a [`ComboBox`]. #[derive(Debug, PartialEq, Eq)] pub struct Style { /// The style of the [`TextInput`] of the [`ComboBox`]. @@ -772,6 +772,14 @@ pub struct Style { menu: menu::Style, } +impl Style { + /// The default style of a [`ComboBox`]. + pub const DEFAULT: Self = Self { + text_input: text_input::default, + menu: menu::Style::::DEFAULT, + }; +} + impl Clone for Style { fn clone(&self) -> Self { *self @@ -780,16 +788,14 @@ impl Clone for Style { impl Copy for Style {} -impl Default for Style { - fn default() -> Self { - default() - } +/// The default style of a [`ComboBox`]. +pub trait DefaultStyle: Sized { + /// Returns the default style of a [`ComboBox`]. + fn default_style() -> Style; } -/// The default style of a [`ComboBox`]. -pub fn default() -> Style { - Style { - text_input: text_input::default, - menu: menu::Style::default(), +impl DefaultStyle for Theme { + fn default_style() -> Style { + Style::::DEFAULT } } -- cgit