From 97555e67af8b4bcc77df69c5e72156e14948150e Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 7 Jun 2022 04:11:24 +0200 Subject: Implement theme styling for `Container` --- native/src/widget/pane_grid/content.rs | 22 ++++++++++++++++------ native/src/widget/pane_grid/title_bar.rs | 20 ++++++++++++++------ 2 files changed, 30 insertions(+), 12 deletions(-) (limited to 'native/src/widget/pane_grid') diff --git a/native/src/widget/pane_grid/content.rs b/native/src/widget/pane_grid/content.rs index 6b3ff680..4c9e65c9 100644 --- a/native/src/widget/pane_grid/content.rs +++ b/native/src/widget/pane_grid/content.rs @@ -11,22 +11,27 @@ use crate::{Clipboard, Element, Layout, Point, Rectangle, Shell, Size}; /// /// [`Pane`]: crate::widget::pane_grid::Pane #[allow(missing_debug_implementations)] -pub struct Content<'a, Message, Renderer> { +pub struct Content<'a, Message, Renderer> +where + Renderer: crate::Renderer, + Renderer::Theme: container::StyleSheet, +{ title_bar: Option>, body: Element<'a, Message, Renderer>, - style_sheet: Box, + style: ::Style, } impl<'a, Message, Renderer> Content<'a, Message, Renderer> where Renderer: crate::Renderer, + Renderer::Theme: container::StyleSheet, { /// Creates a new [`Content`] with the provided body. pub fn new(body: impl Into>) -> Self { Self { title_bar: None, body: body.into(), - style_sheet: Default::default(), + style: Default::default(), } } @@ -42,9 +47,9 @@ where /// Sets the style of the [`Content`]. pub fn style( mut self, - style_sheet: impl Into>, + style: impl Into<::Style>, ) -> Self { - self.style_sheet = style_sheet.into(); + self.style = style.into(); self } } @@ -52,6 +57,7 @@ where impl<'a, Message, Renderer> Content<'a, Message, Renderer> where Renderer: crate::Renderer, + Renderer::Theme: container::StyleSheet, { /// Draws the [`Content`] with the provided [`Renderer`] and [`Layout`]. /// @@ -65,10 +71,12 @@ where cursor_position: Point, viewport: &Rectangle, ) { + use container::StyleSheet; + let bounds = layout.bounds(); { - let style = self.style_sheet.style(); + let style = theme.appearance(self.style); container::draw_background(renderer, &style, bounds); } @@ -248,6 +256,7 @@ where impl<'a, Message, Renderer> Draggable for &Content<'a, Message, Renderer> where Renderer: crate::Renderer, + Renderer::Theme: container::StyleSheet, { fn can_be_dragged_at( &self, @@ -269,6 +278,7 @@ impl<'a, T, Message, Renderer> From for Content<'a, Message, Renderer> where T: Into>, Renderer: crate::Renderer, + Renderer::Theme: container::StyleSheet, { fn from(element: T) -> Self { Self::new(element) diff --git a/native/src/widget/pane_grid/title_bar.rs b/native/src/widget/pane_grid/title_bar.rs index 1392d505..2a028dd5 100644 --- a/native/src/widget/pane_grid/title_bar.rs +++ b/native/src/widget/pane_grid/title_bar.rs @@ -12,17 +12,22 @@ use crate::{ /// /// [`Pane`]: crate::widget::pane_grid::Pane #[allow(missing_debug_implementations)] -pub struct TitleBar<'a, Message, Renderer> { +pub struct TitleBar<'a, Message, Renderer> +where + Renderer: crate::Renderer, + Renderer::Theme: container::StyleSheet, +{ content: Element<'a, Message, Renderer>, controls: Option>, padding: Padding, always_show_controls: bool, - style_sheet: Box, + style: ::Style, } impl<'a, Message, Renderer> TitleBar<'a, Message, Renderer> where Renderer: crate::Renderer, + Renderer::Theme: container::StyleSheet, { /// Creates a new [`TitleBar`] with the given content. pub fn new(content: E) -> Self @@ -34,7 +39,7 @@ where controls: None, padding: Padding::ZERO, always_show_controls: false, - style_sheet: Default::default(), + style: Default::default(), } } @@ -56,9 +61,9 @@ where /// Sets the style of the [`TitleBar`]. pub fn style( mut self, - style: impl Into>, + style: impl Into<::Style>, ) -> Self { - self.style_sheet = style.into(); + self.style = style.into(); self } @@ -79,6 +84,7 @@ where impl<'a, Message, Renderer> TitleBar<'a, Message, Renderer> where Renderer: crate::Renderer, + Renderer::Theme: container::StyleSheet, { /// Draws the [`TitleBar`] with the provided [`Renderer`] and [`Layout`]. /// @@ -93,8 +99,10 @@ where viewport: &Rectangle, show_controls: bool, ) { + use container::StyleSheet; + let bounds = layout.bounds(); - let style = self.style_sheet.style(); + let style = theme.appearance(self.style); let inherited_style = renderer::Style { text_color: style.text_color.unwrap_or(inherited_style.text_color), }; -- cgit