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

@ -6,7 +6,7 @@ use crate::{theme::Theme, widget::segmented_button::ItemStatusAppearance};
use iced_core::{Background, BorderRadius};
use palette::{rgb::Rgb, Alpha};
#[derive(Clone, Copy, Default)]
#[derive(Default)]
pub enum SegmentedButton {
/// A tabbed widget for switching between views in an interface.
#[default]
@ -14,7 +14,7 @@ pub enum SegmentedButton {
/// A widget for multiple choice selection.
Selection,
/// Or implement any custom theme of your liking.
Custom(fn(&Theme) -> Appearance),
Custom(Box<dyn Fn(&Theme) -> Appearance>),
}
impl StyleSheet for Theme {