From 664251f3f5c7b76f69a97683af1468094bba887f Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sat, 14 May 2022 01:47:55 +0200 Subject: Draft first-class `Theme` support RFC: https://github.com/iced-rs/rfcs/pull/6 --- pure/src/widget/container.rs | 2 ++ 1 file changed, 2 insertions(+) (limited to 'pure/src/widget/container.rs') diff --git a/pure/src/widget/container.rs b/pure/src/widget/container.rs index 91db1f3f..0ec2351a 100644 --- a/pure/src/widget/container.rs +++ b/pure/src/widget/container.rs @@ -201,6 +201,7 @@ where &self, tree: &Tree, renderer: &mut Renderer, + theme: &Renderer::Theme, renderer_style: &renderer::Style, layout: Layout<'_>, cursor_position: Point, @@ -213,6 +214,7 @@ where self.content.as_widget().draw( &tree.children[0], renderer, + theme, &renderer::Style { text_color: style .text_color -- cgit 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` --- pure/src/widget/container.rs | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'pure/src/widget/container.rs') diff --git a/pure/src/widget/container.rs b/pure/src/widget/container.rs index 0ec2351a..8ea9ca72 100644 --- a/pure/src/widget/container.rs +++ b/pure/src/widget/container.rs @@ -15,13 +15,17 @@ use iced_native::{ use std::u32; -pub use iced_style::container::{Style, StyleSheet}; +pub use iced_style::container::{Appearance, StyleSheet}; /// An element decorating some content. /// /// It is normally used for alignment purposes. #[allow(missing_debug_implementations)] -pub struct Container<'a, Message, Renderer> { +pub struct Container<'a, Message, Renderer> +where + Renderer: iced_native::Renderer, + Renderer::Theme: container::StyleSheet, +{ padding: Padding, width: Length, height: Length, @@ -29,13 +33,14 @@ pub struct Container<'a, Message, Renderer> { max_height: u32, horizontal_alignment: alignment::Horizontal, vertical_alignment: alignment::Vertical, - style_sheet: Box, + style: ::Style, content: Element<'a, Message, Renderer>, } impl<'a, Message, Renderer> Container<'a, Message, Renderer> where Renderer: iced_native::Renderer, + Renderer::Theme: container::StyleSheet, { /// Creates an empty [`Container`]. pub fn new(content: T) -> Self @@ -50,7 +55,7 @@ where max_height: u32::MAX, horizontal_alignment: alignment::Horizontal::Left, vertical_alignment: alignment::Vertical::Top, - style_sheet: Default::default(), + style: Default::default(), content: content.into(), } } @@ -112,9 +117,9 @@ where /// Sets the style of the [`Container`]. 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 } } @@ -123,6 +128,7 @@ impl<'a, Message, Renderer> Widget for Container<'a, Message, Renderer> where Renderer: iced_native::Renderer, + Renderer::Theme: StyleSheet, { fn children(&self) -> Vec { vec![Tree::new(&self.content)] @@ -207,7 +213,7 @@ where cursor_position: Point, viewport: &Rectangle, ) { - let style = self.style_sheet.style(); + let style = theme.appearance(self.style); container::draw_background(renderer, &style, layout.bounds()); @@ -243,8 +249,9 @@ where impl<'a, Message, Renderer> From> for Element<'a, Message, Renderer> where - Renderer: 'a + iced_native::Renderer, Message: 'a, + Renderer: 'a + iced_native::Renderer, + Renderer::Theme: StyleSheet, { fn from( column: Container<'a, Message, Renderer>, -- cgit