diff options
author | 2023-09-03 01:32:47 +0200 | |
---|---|---|
committer | 2023-09-03 01:34:13 +0200 | |
commit | 832d9f1b01de5a1128f5adcd128f405718c72736 (patch) | |
tree | 3e8965cf326f9b80b2aa1ccd9897b6bc30fe9560 /style/src/theme.rs | |
parent | 9b9b37e6f83b5e5a8811feb17b484c6b11fa3b8b (diff) | |
download | iced-832d9f1b01de5a1128f5adcd128f405718c72736.tar.gz iced-832d9f1b01de5a1128f5adcd128f405718c72736.tar.bz2 iced-832d9f1b01de5a1128f5adcd128f405718c72736.zip |
Introduce `theme::Custom::with_fn` to generate completely custom themes
Diffstat (limited to 'style/src/theme.rs')
-rw-r--r-- | style/src/theme.rs | 27 |
1 files changed, 22 insertions, 5 deletions
diff --git a/style/src/theme.rs b/style/src/theme.rs index 64497181..893d7202 100644 --- a/style/src/theme.rs +++ b/style/src/theme.rs @@ -1,8 +1,7 @@ //! Use the built-in theme and styles. pub mod palette; -use self::palette::Extended; -pub use self::palette::Palette; +pub use palette::Palette; use crate::application; use crate::button; @@ -40,7 +39,16 @@ pub enum Theme { impl Theme { /// Creates a new custom [`Theme`] from the given [`Palette`]. pub fn custom(palette: Palette) -> Self { - Self::Custom(Box::new(Custom::new(palette))) + Self::custom_with_fn(palette, palette::Extended::generate) + } + + /// Creates a new custom [`Theme`] from the given [`Palette`], with + /// a custom generator of a [`palette::Extended`]. + pub fn custom_with_fn( + palette: Palette, + generate: impl FnOnce(Palette) -> palette::Extended, + ) -> Self { + Self::Custom(Box::new(Custom::with_fn(palette, generate))) } /// Returns the [`Palette`] of the [`Theme`]. @@ -66,15 +74,24 @@ impl Theme { #[derive(Debug, Clone, Copy, PartialEq)] pub struct Custom { palette: Palette, - extended: Extended, + extended: palette::Extended, } impl Custom { /// Creates a [`Custom`] theme from the given [`Palette`]. pub fn new(palette: Palette) -> Self { + Self::with_fn(palette, palette::Extended::generate) + } + + /// Creates a [`Custom`] theme from the given [`Palette`] with + /// a custom generator of a [`palette::Extended`]. + pub fn with_fn( + palette: Palette, + generate: impl FnOnce(Palette) -> palette::Extended, + ) -> Self { Self { palette, - extended: Extended::generate(palette), + extended: generate(palette), } } } |