diff options
author | 2020-01-05 19:29:12 +0100 | |
---|---|---|
committer | 2020-01-05 19:29:12 +0100 | |
commit | 1a0effa961344677daf17b4192243423a154f1bf (patch) | |
tree | 954d2431d69004c1037d19c3bb930273347df8d4 /style | |
parent | 2116fbb3c2412030a676c60d65784b9dfa467a0a (diff) | |
download | iced-1a0effa961344677daf17b4192243423a154f1bf.tar.gz iced-1a0effa961344677daf17b4192243423a154f1bf.tar.bz2 iced-1a0effa961344677daf17b4192243423a154f1bf.zip |
Add border and shadow styling to `Button`
Diffstat (limited to 'style')
-rw-r--r-- | style/src/button.rs | 29 |
1 files changed, 23 insertions, 6 deletions
diff --git a/style/src/button.rs b/style/src/button.rs index 42286897..4a9dac45 100644 --- a/style/src/button.rs +++ b/style/src/button.rs @@ -1,15 +1,30 @@ //! Allow your users to perform actions by pressing a button. -use iced_core::{Background, Color}; +use iced_core::{Background, Color, Vector}; /// The appearance of a button. #[derive(Debug)] pub struct Style { - pub shadow_offset: f32, + pub shadow_offset: Vector, pub background: Option<Background>, pub border_radius: u16, + pub border_width: u16, + pub border_color: Color, pub text_color: Color, } +impl std::default::Default for Style { + fn default() -> Self { + Style { + shadow_offset: Vector::default(), + background: None, + border_radius: 0, + border_width: 0, + border_color: Color::TRANSPARENT, + text_color: Color::BLACK, + } + } +} + /// A set of rules that dictate the style of a button. pub trait StyleSheet { fn active(&self) -> Style; @@ -18,14 +33,14 @@ pub trait StyleSheet { let active = self.active(); Style { - shadow_offset: active.shadow_offset + 1.0, + shadow_offset: active.shadow_offset + Vector::new(0.0, 1.0), ..active } } fn pressed(&self) -> Style { Style { - shadow_offset: 0.0, + shadow_offset: Vector::default(), ..self.active() } } @@ -34,7 +49,7 @@ pub trait StyleSheet { let active = self.active(); Style { - shadow_offset: 0.0, + shadow_offset: Vector::default(), background: active.background.map(|background| match background { Background::Color(color) => Background::Color(Color { a: color.a * 0.5, @@ -55,9 +70,11 @@ struct Default; impl StyleSheet for Default { fn active(&self) -> Style { Style { - shadow_offset: 1.0, + shadow_offset: Vector::new(0.0, 1.0), background: Some(Background::Color([0.5, 0.5, 0.5].into())), border_radius: 5, + border_width: 0, + border_color: Color::TRANSPARENT, text_color: Color::BLACK, } } |