From 29326215ccf13e1d1e25bf3bf5ada007856bff69 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 5 Mar 2024 03:48:08 +0100 Subject: Simplify theming for `Container` widget --- widget/src/pane_grid/content.rs | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) (limited to 'widget/src/pane_grid/content.rs') diff --git a/widget/src/pane_grid/content.rs b/widget/src/pane_grid/content.rs index dfe0fdcf..78a4f347 100644 --- a/widget/src/pane_grid/content.rs +++ b/widget/src/pane_grid/content.rs @@ -20,25 +20,26 @@ pub struct Content< Theme = crate::Theme, Renderer = crate::Renderer, > where - Theme: container::StyleSheet, Renderer: crate::core::Renderer, { title_bar: Option>, body: Element<'a, Message, Theme, Renderer>, - style: Theme::Style, + style: fn(&Theme, container::Status) -> container::Appearance, } impl<'a, Message, Theme, Renderer> Content<'a, Message, Theme, Renderer> where - Theme: container::StyleSheet, Renderer: crate::core::Renderer, { /// Creates a new [`Content`] with the provided body. - pub fn new(body: impl Into>) -> Self { + pub fn new(body: impl Into>) -> Self + where + Theme: container::Style, + { Self { title_bar: None, body: body.into(), - style: Default::default(), + style: Theme::default(), } } @@ -52,15 +53,17 @@ where } /// Sets the style of the [`Content`]. - pub fn style(mut self, style: impl Into) -> Self { - self.style = style.into(); + pub fn style( + mut self, + style: fn(&Theme, container::Status) -> container::Appearance, + ) -> Self { + self.style = style; self } } impl<'a, Message, Theme, Renderer> Content<'a, Message, Theme, Renderer> where - Theme: container::StyleSheet, Renderer: crate::core::Renderer, { pub(super) fn state(&self) -> Tree { @@ -104,7 +107,15 @@ where let bounds = layout.bounds(); { - let style = theme.appearance(&self.style); + let style = { + let status = if cursor.is_over(bounds) { + container::Status::Hovered + } else { + container::Status::Idle + }; + + (self.style)(theme, status) + }; container::draw_background(renderer, &style, bounds); } @@ -370,7 +381,6 @@ where impl<'a, Message, Theme, Renderer> Draggable for &Content<'a, Message, Theme, Renderer> where - Theme: container::StyleSheet, Renderer: crate::core::Renderer, { fn can_be_dragged_at( @@ -393,7 +403,7 @@ impl<'a, T, Message, Theme, Renderer> From for Content<'a, Message, Theme, Renderer> where T: Into>, - Theme: container::StyleSheet, + Theme: container::Style, Renderer: crate::core::Renderer, { fn from(element: T) -> Self { -- cgit From 597a41cea73f078eda04eb3ff40cfda5d37d6135 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Wed, 6 Mar 2024 17:08:28 +0100 Subject: Simplify theming for `PickList`, `ComboBox`, and `Menu` widgets --- widget/src/pane_grid/content.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'widget/src/pane_grid/content.rs') diff --git a/widget/src/pane_grid/content.rs b/widget/src/pane_grid/content.rs index 78a4f347..25b64e17 100644 --- a/widget/src/pane_grid/content.rs +++ b/widget/src/pane_grid/content.rs @@ -39,7 +39,7 @@ where Self { title_bar: None, body: body.into(), - style: Theme::default(), + style: Theme::style(), } } -- cgit 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 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'widget/src/pane_grid/content.rs') 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) -- cgit 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/pane_grid/content.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'widget/src/pane_grid/content.rs') diff --git a/widget/src/pane_grid/content.rs b/widget/src/pane_grid/content.rs index ce29e8d0..aecec777 100644 --- a/widget/src/pane_grid/content.rs +++ b/widget/src/pane_grid/content.rs @@ -34,12 +34,12 @@ where /// Creates a new [`Content`] with the provided body. pub fn new(body: impl Into>) -> Self where - container::Style: Default, + Theme: container::DefaultStyle, { Self { title_bar: None, body: body.into(), - style: container::Style::default(), + style: Theme::default_style(), } } @@ -114,7 +114,7 @@ where container::Status::Idle }; - self.style.resolve(theme, status) + (self.style)(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::DefaultStyle, Renderer: crate::core::Renderer, - container::Style: Default, { fn from(element: T) -> Self { Self::new(element) -- cgit