diff options
| author | 2021-06-03 20:55:50 +0700 | |
|---|---|---|
| committer | 2021-06-03 20:55:50 +0700 | |
| commit | 397a5c06ec4911ffe397098be99480aaa1df66f7 (patch) | |
| tree | 00182b32b48a2584aceafd3c9ad1947535ed1893 /style/src | |
| parent | 1dce929dfcfd3f9acc06e3b55157d40eb06b1324 (diff) | |
| parent | d3d6f3efb33f601ff3fca4a6496cfeef052501ee (diff) | |
| download | iced-397a5c06ec4911ffe397098be99480aaa1df66f7.tar.gz iced-397a5c06ec4911ffe397098be99480aaa1df66f7.tar.bz2 iced-397a5c06ec4911ffe397098be99480aaa1df66f7.zip  | |
Merge pull request #535 from Kaiden42/toggler
Implement `Toggler` widget for iced_native
Diffstat (limited to 'style/src')
| -rw-r--r-- | style/src/lib.rs | 1 | ||||
| -rw-r--r-- | style/src/toggler.rs | 57 | 
2 files changed, 58 insertions, 0 deletions
diff --git a/style/src/lib.rs b/style/src/lib.rs index f09b5f9d..08d9f044 100644 --- a/style/src/lib.rs +++ b/style/src/lib.rs @@ -18,3 +18,4 @@ pub mod rule;  pub mod scrollable;  pub mod slider;  pub mod text_input; +pub mod toggler; diff --git a/style/src/toggler.rs b/style/src/toggler.rs new file mode 100644 index 00000000..5a155123 --- /dev/null +++ b/style/src/toggler.rs @@ -0,0 +1,57 @@ +//! Show toggle controls using togglers. +use iced_core::Color; + +/// The appearance of a toggler. +#[derive(Debug)] +pub struct Style { +    pub background: Color, +    pub background_border: Option<Color>, +    pub foreground: Color, +    pub foreground_border: Option<Color>, +} + +/// A set of rules that dictate the style of a toggler. +pub trait StyleSheet { +    fn active(&self, is_active: bool) -> Style; + +    fn hovered(&self, is_active: bool) -> Style; +} + +struct Default; + +impl StyleSheet for Default { +    fn active(&self, is_active: bool) -> Style { +        Style { +            background: if is_active { +                Color::from_rgb(0.0, 1.0, 0.0) +            } else { +                Color::from_rgb(0.7, 0.7, 0.7) +            }, +            background_border: None, +            foreground: Color::WHITE, +            foreground_border: None, +        } +    } + +    fn hovered(&self, is_active: bool) -> Style { +        Style { +            foreground: Color::from_rgb(0.95, 0.95, 0.95), +            ..self.active(is_active) +        } +    } +} + +impl std::default::Default for Box<dyn StyleSheet> { +    fn default() -> Self { +        Box::new(Default) +    } +} + +impl<T> From<T> for Box<dyn StyleSheet> +where +    T: 'static + StyleSheet, +{ +    fn from(style: T) -> Self { +        Box::new(style) +    } +}  | 
