summaryrefslogtreecommitdiffstats
path: root/widget/src/pane_grid
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-03-12 13:25:06 +0100
committerLibravatar Héctor Ramón Jiménez <hector@hecrj.dev>2024-03-12 13:31:16 +0100
commit2088e5d66117dd481e4c60ba6afe9ab8f3a2d4c1 (patch)
tree37659caf787c56ccb35c53965abeff2cb8366cb2 /widget/src/pane_grid
parent34317bba5db0a0f9e3ffdbbac0d7136a32bd0f95 (diff)
downloadiced-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 'widget/src/pane_grid')
-rw-r--r--widget/src/pane_grid/content.rs12
-rw-r--r--widget/src/pane_grid/title_bar.rs10
2 files changed, 11 insertions, 11 deletions
diff --git a/widget/src/pane_grid/content.rs b/widget/src/pane_grid/content.rs
index aecec777..98f4f99a 100644
--- a/widget/src/pane_grid/content.rs
+++ b/widget/src/pane_grid/content.rs
@@ -24,7 +24,7 @@ pub struct Content<
{
title_bar: Option<TitleBar<'a, Message, Theme, Renderer>>,
body: Element<'a, Message, Theme, Renderer>,
- style: container::Style<Theme>,
+ style: container::Style<'a, Theme>,
}
impl<'a, Message, Theme, Renderer> Content<'a, Message, Theme, Renderer>
@@ -34,12 +34,12 @@ where
/// Creates a new [`Content`] with the provided body.
pub fn new(body: impl Into<Element<'a, Message, Theme, Renderer>>) -> Self
where
- Theme: container::DefaultStyle,
+ Theme: container::DefaultStyle + 'a,
{
Self {
title_bar: None,
body: body.into(),
- style: Theme::default_style(),
+ style: Box::new(Theme::default_style),
}
}
@@ -55,9 +55,9 @@ where
/// Sets the style of the [`Content`].
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
}
}
@@ -403,7 +403,7 @@ impl<'a, T, Message, Theme, Renderer> From<T>
for Content<'a, Message, Theme, Renderer>
where
T: Into<Element<'a, Message, Theme, Renderer>>,
- Theme: container::DefaultStyle,
+ Theme: container::DefaultStyle + 'a,
Renderer: crate::core::Renderer,
{
fn from(element: T) -> Self {
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<Element<'a, Message, Theme, Renderer>>,
padding: Padding,
always_show_controls: bool,
- style: container::Style<Theme>,
+ style: container::Style<'a, Theme>,
}
impl<'a, Message, Theme, Renderer> TitleBar<'a, Message, Theme, Renderer>
@@ -37,14 +37,14 @@ where
content: impl Into<Element<'a, Message, Theme, Renderer>>,
) -> 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
}