From 2088e5d66117dd481e4c60ba6afe9ab8f3a2d4c1 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 12 Mar 2024 13:25:06 +0100 Subject: Try using closures for `Container::style` `Box` should not allocate for zero-sized types; so we should not be incurring much overhead. Just a bit of indirection. --- widget/src/pane_grid/title_bar.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'widget/src/pane_grid/title_bar.rs') diff --git a/widget/src/pane_grid/title_bar.rs b/widget/src/pane_grid/title_bar.rs index 37f0f160..8dfea6e3 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: container::Style, + style: container::Style<'a, Theme>, } impl<'a, Message, Theme, Renderer> TitleBar<'a, Message, Theme, Renderer> @@ -37,14 +37,14 @@ where content: impl Into>, ) -> Self where - Theme: container::DefaultStyle, + Theme: container::DefaultStyle + 'a, { Self { content: content.into(), controls: None, padding: Padding::ZERO, always_show_controls: false, - style: Theme::default_style(), + style: Box::new(Theme::default_style), } } @@ -66,9 +66,9 @@ where /// Sets the style of the [`TitleBar`]. pub fn style( mut self, - style: fn(&Theme, container::Status) -> container::Appearance, + style: impl Fn(&Theme, container::Status) -> container::Appearance + 'a, ) -> Self { - self.style = style.into(); + self.style = Box::new(style); self } -- cgit