theme: Use boxed functions instead fn pointers (#99)

This is more general, and necessary if the custom theming is dynamically
generated.

Iced's builtin theme also uses `Box`ed `Fn`, or `Rc` where clone is
required, so this seems reasonable.

Only `Text` is left using `fn`, since it needs to be `Copy`. Hopefully
that can be changed in Iced at some point.

`::custom` methods are added to make these variants a little more
convenient to construct. This replaces a couple `From` implementations,
which are potentially problematic with a generic.
This commit is contained in:
Ian Douglas Scott 2023-04-28 16:04:57 -07:00 committed by GitHub
parent c878e24465
commit b85c504d72
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 65 additions and 63 deletions

View file

@ -207,7 +207,7 @@ impl<'a> Icon<'a> {
fn svg_element<Message: 'static>(&self, handle: svg::Handle) -> Element<'static, Message> {
svg::Svg::<Renderer>::new(handle)
.style(self.style)
.style(self.style.clone())
.width(self.width.unwrap_or(Length::Units(self.size)))
.height(self.height.unwrap_or(Length::Units(self.size)))
.content_fit(self.content_fit)

View file

@ -45,7 +45,7 @@ impl<'a, Message: 'static> ListColumn<'a, Message> {
.spacing(12)
.apply(iced::widget::container)
.padding([16, 6])
.style(theme::Container::Custom(style))
.style(theme::Container::custom(style))
.into()
}
}

View file

@ -36,7 +36,7 @@ where
.apply(container)
.height(Length::Fill)
.padding(11)
.style(theme::Container::Custom(nav_bar_style))
.style(theme::Container::custom(nav_bar_style))
}
#[must_use]

View file

@ -58,7 +58,7 @@ impl<'a, Message: 'static + Clone> Field<'a, Message> {
.spacing(8)
.align_items(iced::Alignment::Center)
.apply(container)
.style(crate::theme::Container::Custom(active_style))
.style(crate::theme::Container::custom(active_style))
.into()
}
}

View file

@ -83,7 +83,7 @@ impl<'a, Message: 'static> SpinButton<'a, Message> {
.align_y(Vertical::Center)
.width(Length::Units(95))
.height(Length::Units(32))
.style(theme::Container::Custom(container_style))
.style(theme::Container::custom(container_style))
.apply(Element::from)
.map(on_change)
}

View file

@ -51,7 +51,7 @@ impl<'a, Message: 'static + Clone> Warning<'a, Message> {
])
.align_items(Alignment::Center),
)
.style(theme::Container::Custom(warning_container))
.style(theme::Container::custom(warning_container))
.padding(10)
.align_y(alignment::Vertical::Center)
.width(Length::Fill)