From 34e7c6593a9e0f56cee5db18b7258717cf6bc11b Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Wed, 6 Mar 2024 20:30:58 +0100 Subject: Use `Style` struct pattern instead of trait for all widgets --- widget/src/pane_grid/content.rs | 12 ++++++------ widget/src/pane_grid/title_bar.rs | 15 ++++++++------- 2 files changed, 14 insertions(+), 13 deletions(-) (limited to 'widget/src/pane_grid') diff --git a/widget/src/pane_grid/content.rs b/widget/src/pane_grid/content.rs index 25b64e17..ce29e8d0 100644 --- a/widget/src/pane_grid/content.rs +++ b/widget/src/pane_grid/content.rs @@ -24,7 +24,7 @@ pub struct Content< { title_bar: Option>, body: Element<'a, Message, Theme, Renderer>, - style: fn(&Theme, container::Status) -> container::Appearance, + style: container::Style, } impl<'a, Message, Theme, Renderer> Content<'a, Message, Theme, Renderer> @@ -34,12 +34,12 @@ where /// Creates a new [`Content`] with the provided body. pub fn new(body: impl Into>) -> Self where - Theme: container::Style, + container::Style: Default, { Self { title_bar: None, body: body.into(), - style: Theme::style(), + style: container::Style::default(), } } @@ -57,7 +57,7 @@ where mut self, style: fn(&Theme, container::Status) -> container::Appearance, ) -> Self { - self.style = style; + self.style = style.into(); self } } @@ -114,7 +114,7 @@ where container::Status::Idle }; - (self.style)(theme, status) + self.style.resolve(theme, status) }; container::draw_background(renderer, &style, bounds); @@ -403,8 +403,8 @@ impl<'a, T, Message, Theme, Renderer> From for Content<'a, Message, Theme, Renderer> where T: Into>, - Theme: container::Style, Renderer: crate::core::Renderer, + container::Style: Default, { fn from(element: T) -> Self { Self::new(element) diff --git a/widget/src/pane_grid/title_bar.rs b/widget/src/pane_grid/title_bar.rs index 787510cc..b1cdcde3 100644 --- a/widget/src/pane_grid/title_bar.rs +++ b/widget/src/pane_grid/title_bar.rs @@ -25,7 +25,7 @@ pub struct TitleBar< controls: Option>, padding: Padding, always_show_controls: bool, - style: fn(&Theme, container::Status) -> container::Appearance, + style: container::Style, } impl<'a, Message, Theme, Renderer> TitleBar<'a, Message, Theme, Renderer> @@ -33,17 +33,18 @@ where Renderer: crate::core::Renderer, { /// Creates a new [`TitleBar`] with the given content. - pub fn new(content: E) -> Self + pub fn new( + content: impl Into>, + ) -> Self where - Theme: container::Style, - E: Into>, + container::Style: Default, { Self { content: content.into(), controls: None, padding: Padding::ZERO, always_show_controls: false, - style: Theme::style(), + style: container::Style::default(), } } @@ -67,7 +68,7 @@ where mut self, style: fn(&Theme, container::Status) -> container::Appearance, ) -> Self { - self.style = style; + self.style = style.into(); self } @@ -137,7 +138,7 @@ where container::Status::Idle }; - (self.style)(theme, status) + self.style.resolve(theme, status) }; let inherited_style = renderer::Style { -- cgit