From 7a50e9e8fbb8d37e53a42c1dd5936b97463ead53 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sun, 21 Jan 2024 17:56:01 +0100 Subject: Convert `Renderer::Theme` to generic `Widget` type --- widget/src/pane_grid/content.rs | 51 ++++++++++++++++++++------------------- widget/src/pane_grid/title_bar.rs | 39 +++++++++++++++--------------- 2 files changed, 45 insertions(+), 45 deletions(-) (limited to 'widget/src/pane_grid') diff --git a/widget/src/pane_grid/content.rs b/widget/src/pane_grid/content.rs index ee00f186..415dcc3e 100644 --- a/widget/src/pane_grid/content.rs +++ b/widget/src/pane_grid/content.rs @@ -12,23 +12,27 @@ use crate::pane_grid::{Draggable, TitleBar}; /// /// [`Pane`]: super::Pane #[allow(missing_debug_implementations)] -pub struct Content<'a, Message, Renderer = crate::Renderer> -where +pub struct Content< + 'a, + Message, + Theme = crate::Theme, + Renderer = crate::Renderer, +> where + Theme: container::StyleSheet, Renderer: crate::core::Renderer, - Renderer::Theme: container::StyleSheet, { - title_bar: Option>, - body: Element<'a, Message, Renderer>, - style: ::Style, + title_bar: Option>, + body: Element<'a, Message, Theme, Renderer>, + style: Theme::Style, } -impl<'a, Message, Renderer> Content<'a, Message, Renderer> +impl<'a, Message, Theme, Renderer> Content<'a, Message, Theme, Renderer> where + Theme: container::StyleSheet, Renderer: crate::core::Renderer, - Renderer::Theme: container::StyleSheet, { /// Creates a new [`Content`] with the provided body. - pub fn new(body: impl Into>) -> Self { + pub fn new(body: impl Into>) -> Self { Self { title_bar: None, body: body.into(), @@ -39,26 +43,23 @@ where /// Sets the [`TitleBar`] of this [`Content`]. pub fn title_bar( mut self, - title_bar: TitleBar<'a, Message, Renderer>, + title_bar: TitleBar<'a, Message, Theme, Renderer>, ) -> Self { self.title_bar = Some(title_bar); self } /// Sets the style of the [`Content`]. - pub fn style( - mut self, - style: impl Into<::Style>, - ) -> Self { + pub fn style(mut self, style: impl Into) -> Self { self.style = style.into(); self } } -impl<'a, Message, Renderer> Content<'a, Message, Renderer> +impl<'a, Message, Theme, Renderer> Content<'a, Message, Theme, Renderer> where + Theme: container::StyleSheet, Renderer: crate::core::Renderer, - Renderer::Theme: container::StyleSheet, { pub(super) fn state(&self) -> Tree { let children = if let Some(title_bar) = self.title_bar.as_ref() { @@ -92,14 +93,12 @@ where &self, tree: &Tree, renderer: &mut Renderer, - theme: &Renderer::Theme, + theme: &Theme, style: &renderer::Style, layout: Layout<'_>, cursor: mouse::Cursor, viewport: &Rectangle, ) { - use container::StyleSheet; - let bounds = layout.bounds(); { @@ -331,7 +330,7 @@ where tree: &'b mut Tree, layout: Layout<'_>, renderer: &Renderer, - ) -> Option> { + ) -> Option> { if let Some(title_bar) = self.title_bar.as_mut() { let mut children = layout.children(); let title_bar_layout = children.next()?; @@ -359,10 +358,11 @@ where } } -impl<'a, Message, Renderer> Draggable for &Content<'a, Message, Renderer> +impl<'a, Message, Theme, Renderer> Draggable + for &Content<'a, Message, Theme, Renderer> where + Theme: container::StyleSheet, Renderer: crate::core::Renderer, - Renderer::Theme: container::StyleSheet, { fn can_be_dragged_at( &self, @@ -380,11 +380,12 @@ where } } -impl<'a, T, Message, Renderer> From for Content<'a, Message, Renderer> +impl<'a, T, Message, Theme, Renderer> From + for Content<'a, Message, Theme, Renderer> where - T: Into>, + T: Into>, + Theme: container::StyleSheet, Renderer: crate::core::Renderer, - Renderer::Theme: container::StyleSheet, { 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 eb21b743..3cca6b33 100644 --- a/widget/src/pane_grid/title_bar.rs +++ b/widget/src/pane_grid/title_bar.rs @@ -13,27 +13,31 @@ use crate::core::{ /// /// [`Pane`]: super::Pane #[allow(missing_debug_implementations)] -pub struct TitleBar<'a, Message, Renderer = crate::Renderer> -where +pub struct TitleBar< + 'a, + Message, + Theme = crate::Theme, + Renderer = crate::Renderer, +> where + Theme: container::StyleSheet, Renderer: crate::core::Renderer, - Renderer::Theme: container::StyleSheet, { - content: Element<'a, Message, Renderer>, - controls: Option>, + content: Element<'a, Message, Theme, Renderer>, + controls: Option>, padding: Padding, always_show_controls: bool, - style: ::Style, + style: Theme::Style, } -impl<'a, Message, Renderer> TitleBar<'a, Message, Renderer> +impl<'a, Message, Theme, Renderer> TitleBar<'a, Message, Theme, Renderer> where + Theme: container::StyleSheet, Renderer: crate::core::Renderer, - Renderer::Theme: container::StyleSheet, { /// Creates a new [`TitleBar`] with the given content. pub fn new(content: E) -> Self where - E: Into>, + E: Into>, { Self { content: content.into(), @@ -47,7 +51,7 @@ where /// Sets the controls of the [`TitleBar`]. pub fn controls( mut self, - controls: impl Into>, + controls: impl Into>, ) -> Self { self.controls = Some(controls.into()); self @@ -60,10 +64,7 @@ where } /// Sets the style of the [`TitleBar`]. - pub fn style( - mut self, - style: impl Into<::Style>, - ) -> Self { + pub fn style(mut self, style: impl Into) -> Self { self.style = style.into(); self } @@ -82,10 +83,10 @@ where } } -impl<'a, Message, Renderer> TitleBar<'a, Message, Renderer> +impl<'a, Message, Theme, Renderer> TitleBar<'a, Message, Theme, Renderer> where + Theme: container::StyleSheet, Renderer: crate::core::Renderer, - Renderer::Theme: container::StyleSheet, { pub(super) fn state(&self) -> Tree { let children = if let Some(controls) = self.controls.as_ref() { @@ -119,15 +120,13 @@ where &self, tree: &Tree, renderer: &mut Renderer, - theme: &Renderer::Theme, + theme: &Theme, inherited_style: &renderer::Style, layout: Layout<'_>, cursor: mouse::Cursor, viewport: &Rectangle, show_controls: bool, ) { - use container::StyleSheet; - let bounds = layout.bounds(); let style = theme.appearance(&self.style); let inherited_style = renderer::Style { @@ -406,7 +405,7 @@ where tree: &'b mut Tree, layout: Layout<'_>, renderer: &Renderer, - ) -> Option> { + ) -> Option> { let mut children = layout.children(); let padded = children.next()?; -- cgit