Introduce theme::Custom::with_fn to generate completely custom themes
This commit is contained in:
parent
9b9b37e6f8
commit
832d9f1b01
1 changed files with 22 additions and 5 deletions
|
|
@ -1,8 +1,7 @@
|
||||||
//! Use the built-in theme and styles.
|
//! Use the built-in theme and styles.
|
||||||
pub mod palette;
|
pub mod palette;
|
||||||
|
|
||||||
use self::palette::Extended;
|
pub use palette::Palette;
|
||||||
pub use self::palette::Palette;
|
|
||||||
|
|
||||||
use crate::application;
|
use crate::application;
|
||||||
use crate::button;
|
use crate::button;
|
||||||
|
|
@ -40,7 +39,16 @@ pub enum Theme {
|
||||||
impl Theme {
|
impl Theme {
|
||||||
/// Creates a new custom [`Theme`] from the given [`Palette`].
|
/// Creates a new custom [`Theme`] from the given [`Palette`].
|
||||||
pub fn custom(palette: Palette) -> Self {
|
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`].
|
/// Returns the [`Palette`] of the [`Theme`].
|
||||||
|
|
@ -66,15 +74,24 @@ impl Theme {
|
||||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||||
pub struct Custom {
|
pub struct Custom {
|
||||||
palette: Palette,
|
palette: Palette,
|
||||||
extended: Extended,
|
extended: palette::Extended,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Custom {
|
impl Custom {
|
||||||
/// Creates a [`Custom`] theme from the given [`Palette`].
|
/// Creates a [`Custom`] theme from the given [`Palette`].
|
||||||
pub fn new(palette: Palette) -> Self {
|
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 {
|
Self {
|
||||||
palette,
|
palette,
|
||||||
extended: Extended::generate(palette),
|
extended: generate(palette),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue