diff options
author | 2024-03-12 13:25:06 +0100 | |
---|---|---|
committer | 2024-03-12 13:31:16 +0100 | |
commit | 2088e5d66117dd481e4c60ba6afe9ab8f3a2d4c1 (patch) | |
tree | 37659caf787c56ccb35c53965abeff2cb8366cb2 /widget/src/tooltip.rs | |
parent | 34317bba5db0a0f9e3ffdbbac0d7136a32bd0f95 (diff) | |
download | iced-2088e5d66117dd481e4c60ba6afe9ab8f3a2d4c1.tar.gz iced-2088e5d66117dd481e4c60ba6afe9ab8f3a2d4c1.tar.bz2 iced-2088e5d66117dd481e4c60ba6afe9ab8f3a2d4c1.zip |
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.
Diffstat (limited to '')
-rw-r--r-- | widget/src/tooltip.rs | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/widget/src/tooltip.rs b/widget/src/tooltip.rs index 8c8ee983..8e11ca98 100644 --- a/widget/src/tooltip.rs +++ b/widget/src/tooltip.rs @@ -28,7 +28,7 @@ pub struct Tooltip< gap: f32, padding: f32, snap_within_viewport: bool, - style: container::Style<Theme>, + style: container::Style<'a, Theme>, } impl<'a, Message, Theme, Renderer> Tooltip<'a, Message, Theme, Renderer> @@ -47,7 +47,7 @@ where position: Position, ) -> Self where - Theme: container::DefaultStyle, + Theme: container::DefaultStyle + 'a, { Tooltip { content: content.into(), @@ -56,7 +56,7 @@ where gap: 0.0, padding: Self::DEFAULT_PADDING, snap_within_viewport: true, - style: Theme::default_style(), + style: Box::new(Theme::default_style), } } @@ -81,9 +81,9 @@ where /// Sets the style of the [`Tooltip`]. 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 } } @@ -239,7 +239,7 @@ where positioning: self.position, gap: self.gap, padding: self.padding, - style: self.style, + style: &self.style, }))) } else { None @@ -309,7 +309,8 @@ where positioning: Position, gap: f32, padding: f32, - style: container::Style<Theme>, + style: + &'b (dyn Fn(&Theme, container::Status) -> container::Appearance + 'a), } impl<'a, 'b, Message, Theme, Renderer> |