From e1062a02d17f5748e4809b76ddcc132f1c912886 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Wed, 1 Jan 2020 14:16:10 +0100 Subject: Move styling to a brand new `iced_style` crate --- style/src/button.rs | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++ style/src/container.rs | 41 ++++++++++++++++++++++++++ style/src/lib.rs | 2 ++ 3 files changed, 122 insertions(+) create mode 100644 style/src/button.rs create mode 100644 style/src/container.rs create mode 100644 style/src/lib.rs (limited to 'style/src') diff --git a/style/src/button.rs b/style/src/button.rs new file mode 100644 index 00000000..42286897 --- /dev/null +++ b/style/src/button.rs @@ -0,0 +1,79 @@ +//! Allow your users to perform actions by pressing a button. +use iced_core::{Background, Color}; + +/// The appearance of a button. +#[derive(Debug)] +pub struct Style { + pub shadow_offset: f32, + pub background: Option, + pub border_radius: u16, + pub text_color: Color, +} + +/// A set of rules that dictate the style of a button. +pub trait StyleSheet { + fn active(&self) -> Style; + + fn hovered(&self) -> Style { + let active = self.active(); + + Style { + shadow_offset: active.shadow_offset + 1.0, + ..active + } + } + + fn pressed(&self) -> Style { + Style { + shadow_offset: 0.0, + ..self.active() + } + } + + fn disabled(&self) -> Style { + let active = self.active(); + + Style { + shadow_offset: 0.0, + background: active.background.map(|background| match background { + Background::Color(color) => Background::Color(Color { + a: color.a * 0.5, + ..color + }), + }), + text_color: Color { + a: active.text_color.a * 0.5, + ..active.text_color + }, + ..active + } + } +} + +struct Default; + +impl StyleSheet for Default { + fn active(&self) -> Style { + Style { + shadow_offset: 1.0, + background: Some(Background::Color([0.5, 0.5, 0.5].into())), + border_radius: 5, + text_color: Color::BLACK, + } + } +} + +impl std::default::Default for Box { + fn default() -> Self { + Box::new(Default) + } +} + +impl From for Box +where + T: 'static + StyleSheet, +{ + fn from(style: T) -> Self { + Box::new(style) + } +} diff --git a/style/src/container.rs b/style/src/container.rs new file mode 100644 index 00000000..756ea0f9 --- /dev/null +++ b/style/src/container.rs @@ -0,0 +1,41 @@ +//! Decorate content and apply alignment. +use iced_core::{Background, Color}; + +/// The appearance of a container. +#[derive(Debug, Clone, Copy)] +pub struct Style { + pub text_color: Option, + pub background: Option, + pub border_radius: u16, +} + +/// A set of rules that dictate the style of a container. +pub trait StyleSheet { + /// Produces the style of a container. + fn style(&self) -> Style { + Style { + text_color: None, + background: None, + border_radius: 0, + } + } +} + +struct Default; + +impl StyleSheet for Default {} + +impl std::default::Default for Box { + fn default() -> Self { + Box::new(Default) + } +} + +impl From for Box +where + T: 'static + StyleSheet, +{ + fn from(style: T) -> Self { + Box::new(style) + } +} diff --git a/style/src/lib.rs b/style/src/lib.rs new file mode 100644 index 00000000..c6f34301 --- /dev/null +++ b/style/src/lib.rs @@ -0,0 +1,2 @@ +pub mod button; +pub mod container; -- cgit From 5af4159848341b14f6ff9ae14a9a222d8d8b0fb8 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Wed, 1 Jan 2020 18:26:49 +0100 Subject: Draft basic styling for `TextInput` --- style/src/container.rs | 10 ++++--- style/src/lib.rs | 1 + style/src/text_input.rs | 72 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 79 insertions(+), 4 deletions(-) create mode 100644 style/src/text_input.rs (limited to 'style/src') diff --git a/style/src/container.rs b/style/src/container.rs index 756ea0f9..a9cd3ccc 100644 --- a/style/src/container.rs +++ b/style/src/container.rs @@ -12,6 +12,12 @@ pub struct Style { /// A set of rules that dictate the style of a container. pub trait StyleSheet { /// Produces the style of a container. + fn style(&self) -> Style; +} + +struct Default; + +impl StyleSheet for Default { fn style(&self) -> Style { Style { text_color: None, @@ -21,10 +27,6 @@ pub trait StyleSheet { } } -struct Default; - -impl StyleSheet for Default {} - impl std::default::Default for Box { fn default() -> Self { Box::new(Default) diff --git a/style/src/lib.rs b/style/src/lib.rs index c6f34301..1d7e57c4 100644 --- a/style/src/lib.rs +++ b/style/src/lib.rs @@ -1,2 +1,3 @@ pub mod button; pub mod container; +pub mod text_input; diff --git a/style/src/text_input.rs b/style/src/text_input.rs new file mode 100644 index 00000000..75f427a7 --- /dev/null +++ b/style/src/text_input.rs @@ -0,0 +1,72 @@ +//! Display fields that can be filled with text. +use iced_core::{Background, Color}; + +/// The appearance of a text input. +#[derive(Debug, Clone, Copy)] +pub struct Style { + pub background: Background, + pub border_radius: u16, + pub border_width: u16, + pub border_color: Color, +} + +/// A set of rules that dictate the style of a text input. +pub trait StyleSheet { + /// Produces the style of an active text input. + fn active(&self) -> Style; + + /// Produces the style of a focused text input. + fn focused(&self) -> Style; + + /// Produces the style of an hovered text input. + fn hovered(&self) -> Style { + self.focused() + } + + fn placeholder_color(&self) -> Color; + + fn value_color(&self) -> Color; +} + +struct Default; + +impl StyleSheet for Default { + fn active(&self) -> Style { + Style { + background: Background::Color(Color::WHITE), + border_radius: 5, + border_width: 1, + border_color: Color::from_rgb(0.7, 0.7, 0.7), + } + } + + fn focused(&self) -> Style { + Style { + border_color: Color::from_rgb(0.5, 0.5, 0.5), + ..self.active() + } + } + + fn placeholder_color(&self) -> Color { + Color::from_rgb(0.7, 0.7, 0.7) + } + + fn value_color(&self) -> Color { + Color::from_rgb(0.3, 0.3, 0.3) + } +} + +impl std::default::Default for Box { + fn default() -> Self { + Box::new(Default) + } +} + +impl From for Box +where + T: 'static + StyleSheet, +{ + fn from(style: T) -> Self { + Box::new(style) + } +} -- cgit From 2116fbb3c2412030a676c60d65784b9dfa467a0a Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sun, 5 Jan 2020 18:38:03 +0100 Subject: Add border styling to `Container` --- style/src/container.rs | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'style/src') diff --git a/style/src/container.rs b/style/src/container.rs index a9cd3ccc..484fdfda 100644 --- a/style/src/container.rs +++ b/style/src/container.rs @@ -7,6 +7,8 @@ pub struct Style { pub text_color: Option, pub background: Option, pub border_radius: u16, + pub border_width: u16, + pub border_color: Color, } /// A set of rules that dictate the style of a container. @@ -23,6 +25,8 @@ impl StyleSheet for Default { text_color: None, background: None, border_radius: 0, + border_width: 0, + border_color: Color::TRANSPARENT, } } } -- cgit From 1a0effa961344677daf17b4192243423a154f1bf Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sun, 5 Jan 2020 19:29:12 +0100 Subject: Add border and shadow styling to `Button` --- style/src/button.rs | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) (limited to 'style/src') 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, 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, } } -- cgit From 07ef59af78107db103b7a9640a660ecae95b1156 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sun, 5 Jan 2020 19:34:38 +0100 Subject: Implement `Default` for `container::Style` --- style/src/button.rs | 2 +- style/src/container.rs | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) (limited to 'style/src') diff --git a/style/src/button.rs b/style/src/button.rs index 4a9dac45..03c9ab32 100644 --- a/style/src/button.rs +++ b/style/src/button.rs @@ -14,7 +14,7 @@ pub struct Style { impl std::default::Default for Style { fn default() -> Self { - Style { + Self { shadow_offset: Vector::default(), background: None, border_radius: 0, diff --git a/style/src/container.rs b/style/src/container.rs index 484fdfda..d2247342 100644 --- a/style/src/container.rs +++ b/style/src/container.rs @@ -11,6 +11,18 @@ pub struct Style { pub border_color: Color, } +impl std::default::Default for Style { + fn default() -> Self { + Self { + text_color: None, + background: None, + border_radius: 0, + border_width: 0, + border_color: Color::TRANSPARENT, + } + } +} + /// A set of rules that dictate the style of a container. pub trait StyleSheet { /// Produces the style of a container. -- cgit From 7c4dba29c7614428041bda049924569d751cbb1a Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sun, 5 Jan 2020 19:36:44 +0100 Subject: Implement `Default` for `text_input::Style` --- style/src/text_input.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'style/src') diff --git a/style/src/text_input.rs b/style/src/text_input.rs index 75f427a7..269b28db 100644 --- a/style/src/text_input.rs +++ b/style/src/text_input.rs @@ -10,6 +10,17 @@ pub struct Style { pub border_color: Color, } +impl std::default::Default for Style { + fn default() -> Self { + Self { + background: Background::Color(Color::WHITE), + border_radius: 0, + border_width: 0, + border_color: Color::TRANSPARENT, + } + } +} + /// A set of rules that dictate the style of a text input. pub trait StyleSheet { /// Produces the style of an active text input. -- cgit From 2bbd395d5dcdf9c92ffb354b8b05444478e4b344 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Mon, 6 Jan 2020 18:44:45 +0100 Subject: Draft `styling` example --- style/src/button.rs | 2 +- style/src/text_input.rs | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'style/src') diff --git a/style/src/button.rs b/style/src/button.rs index 03c9ab32..93c27860 100644 --- a/style/src/button.rs +++ b/style/src/button.rs @@ -75,7 +75,7 @@ impl StyleSheet for Default { border_radius: 5, border_width: 0, border_color: Color::TRANSPARENT, - text_color: Color::BLACK, + text_color: Color::WHITE, } } } diff --git a/style/src/text_input.rs b/style/src/text_input.rs index 269b28db..c5123b20 100644 --- a/style/src/text_input.rs +++ b/style/src/text_input.rs @@ -29,14 +29,14 @@ pub trait StyleSheet { /// Produces the style of a focused text input. fn focused(&self) -> Style; + fn placeholder_color(&self) -> Color; + + fn value_color(&self) -> Color; + /// Produces the style of an hovered text input. fn hovered(&self) -> Style { self.focused() } - - fn placeholder_color(&self) -> Color; - - fn value_color(&self) -> Color; } struct Default; -- cgit From d0dc7cebf9c352f4d14827fe47489788f59e61a1 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Mon, 6 Jan 2020 21:01:09 +0100 Subject: Implement styling for `Scrollable` --- style/src/lib.rs | 1 + style/src/scrollable.rs | 76 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 style/src/scrollable.rs (limited to 'style/src') diff --git a/style/src/lib.rs b/style/src/lib.rs index 1d7e57c4..fb90b2b5 100644 --- a/style/src/lib.rs +++ b/style/src/lib.rs @@ -1,3 +1,4 @@ pub mod button; pub mod container; +pub mod scrollable; pub mod text_input; diff --git a/style/src/scrollable.rs b/style/src/scrollable.rs new file mode 100644 index 00000000..690c14a2 --- /dev/null +++ b/style/src/scrollable.rs @@ -0,0 +1,76 @@ +//! Navigate an endless amount of content with a scrollbar. +use iced_core::{Background, Color}; + +/// The appearance of a scrollable. +#[derive(Debug, Clone, Copy)] +pub struct Scrollbar { + pub background: Option, + pub border_radius: u16, + pub border_width: u16, + pub border_color: Color, + pub scroller: Scroller, +} + +/// The appearance of the scroller of a scrollable. +#[derive(Debug, Clone, Copy)] +pub struct Scroller { + pub color: Color, + pub border_radius: u16, + pub border_width: u16, + pub border_color: Color, +} + +/// A set of rules that dictate the style of a scrollable. +pub trait StyleSheet { + /// Produces the style of an active scrollbar. + fn active(&self) -> Scrollbar; + + /// Produces the style of an hovered scrollbar. + fn hovered(&self) -> Scrollbar; + + /// Produces the style of a scrollbar that is being dragged. + fn dragging(&self) -> Scrollbar { + self.hovered() + } +} + +struct Default; + +impl StyleSheet for Default { + fn active(&self) -> Scrollbar { + Scrollbar { + background: None, + border_radius: 5, + border_width: 0, + border_color: Color::TRANSPARENT, + scroller: Scroller { + color: [0.0, 0.0, 0.0, 0.7].into(), + border_radius: 5, + border_width: 0, + border_color: Color::TRANSPARENT, + }, + } + } + + fn hovered(&self) -> Scrollbar { + Scrollbar { + background: Some(Background::Color([0.0, 0.0, 0.0, 0.3].into())), + ..self.active() + } + } +} + +impl std::default::Default for Box { + fn default() -> Self { + Box::new(Default) + } +} + +impl From for Box +where + T: 'static + StyleSheet, +{ + fn from(style: T) -> Self { + Box::new(style) + } +} -- cgit From b329003c8fdcdc3378c8fda93af54be5686fc9ae Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 7 Jan 2020 00:28:08 +0100 Subject: Implement styling for `Slider` --- style/src/lib.rs | 1 + style/src/slider.rs | 95 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 96 insertions(+) create mode 100644 style/src/slider.rs (limited to 'style/src') diff --git a/style/src/lib.rs b/style/src/lib.rs index fb90b2b5..4b8d339e 100644 --- a/style/src/lib.rs +++ b/style/src/lib.rs @@ -1,4 +1,5 @@ pub mod button; pub mod container; pub mod scrollable; +pub mod slider; pub mod text_input; diff --git a/style/src/slider.rs b/style/src/slider.rs new file mode 100644 index 00000000..776e180c --- /dev/null +++ b/style/src/slider.rs @@ -0,0 +1,95 @@ +//! Display an interactive selector of a single value from a range of values. +use iced_core::Color; + +/// The appearance of a slider. +#[derive(Debug, Clone, Copy)] +pub struct Style { + pub rail_colors: (Color, Color), + pub handle: Handle, +} + +/// The appearance of the handle of a slider. +#[derive(Debug, Clone, Copy)] +pub struct Handle { + pub shape: HandleShape, + pub color: Color, + pub border_width: u16, + pub border_color: Color, +} + +/// The shape of the handle of a slider. +#[derive(Debug, Clone, Copy)] +pub enum HandleShape { + Circle { radius: u16 }, + Rectangle { width: u16, border_radius: u16 }, +} + +/// A set of rules that dictate the style of a slider. +pub trait StyleSheet { + /// Produces the style of an active slider. + fn active(&self) -> Style; + + /// Produces the style of an hovered slider. + fn hovered(&self) -> Style; + + /// Produces the style of a slider that is being dragged. + fn dragging(&self) -> Style; +} + +struct Default; + +impl StyleSheet for Default { + fn active(&self) -> Style { + Style { + rail_colors: ([0.6, 0.6, 0.6, 0.5].into(), Color::WHITE), + handle: Handle { + shape: HandleShape::Rectangle { + width: 8, + border_radius: 4, + }, + color: Color::from_rgb(0.95, 0.95, 0.95), + border_color: Color::from_rgb(0.6, 0.6, 0.6), + border_width: 1, + }, + } + } + + fn hovered(&self) -> Style { + let active = self.active(); + + Style { + handle: Handle { + color: Color::from_rgb(0.90, 0.90, 0.90), + ..active.handle + }, + ..active + } + } + + fn dragging(&self) -> Style { + let active = self.active(); + + Style { + handle: Handle { + color: Color::from_rgb(0.85, 0.85, 0.85), + ..active.handle + }, + ..active + } + } +} + +impl std::default::Default for Box { + fn default() -> Self { + Box::new(Default) + } +} + +impl From for Box +where + T: 'static + StyleSheet, +{ + fn from(style: T) -> Self { + Box::new(style) + } +} -- cgit From 48b3b78a3840778eef1035f4585d5ba9dd3d6291 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 7 Jan 2020 01:53:26 +0100 Subject: Implement styling for `ProgressBar` --- style/src/lib.rs | 1 + style/src/progress_bar.rs | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 style/src/progress_bar.rs (limited to 'style/src') diff --git a/style/src/lib.rs b/style/src/lib.rs index 4b8d339e..3f3dc0b0 100644 --- a/style/src/lib.rs +++ b/style/src/lib.rs @@ -1,5 +1,6 @@ pub mod button; pub mod container; +pub mod progress_bar; pub mod scrollable; pub mod slider; pub mod text_input; diff --git a/style/src/progress_bar.rs b/style/src/progress_bar.rs new file mode 100644 index 00000000..73503fa8 --- /dev/null +++ b/style/src/progress_bar.rs @@ -0,0 +1,42 @@ +//! Provide progress feedback to your users. +use iced_core::{Background, Color}; + +/// The appearance of a progress bar. +#[derive(Debug)] +pub struct Style { + pub background: Background, + pub bar: Background, + pub border_radius: u16, +} + +/// A set of rules that dictate the style of a progress bar. +pub trait StyleSheet { + fn style(&self) -> Style; +} + +struct Default; + +impl StyleSheet for Default { + fn style(&self) -> Style { + Style { + background: Background::Color(Color::from_rgb(0.6, 0.6, 0.6)), + bar: Background::Color(Color::from_rgb(0.3, 0.9, 0.3)), + border_radius: 5, + } + } +} + +impl std::default::Default for Box { + fn default() -> Self { + Box::new(Default) + } +} + +impl From for Box +where + T: 'static + StyleSheet, +{ + fn from(style: T) -> Self { + Box::new(style) + } +} -- cgit From 387fc0be26ccd1adc66c1dc80420f9b08d0c023a Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 7 Jan 2020 02:25:57 +0100 Subject: Implement styling for `Radio` --- style/src/lib.rs | 1 + style/src/radio.rs | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 style/src/radio.rs (limited to 'style/src') diff --git a/style/src/lib.rs b/style/src/lib.rs index 3f3dc0b0..991e0644 100644 --- a/style/src/lib.rs +++ b/style/src/lib.rs @@ -1,6 +1,7 @@ pub mod button; pub mod container; pub mod progress_bar; +pub mod radio; pub mod scrollable; pub mod slider; pub mod text_input; diff --git a/style/src/radio.rs b/style/src/radio.rs new file mode 100644 index 00000000..1f0689b9 --- /dev/null +++ b/style/src/radio.rs @@ -0,0 +1,53 @@ +//! Create choices using radio buttons. +use iced_core::{Background, Color}; + +/// The appearance of a radio button. +#[derive(Debug)] +pub struct Style { + pub background: Background, + pub dot_color: Color, + pub border_width: u16, + pub border_color: Color, +} + +/// A set of rules that dictate the style of a radio button. +pub trait StyleSheet { + fn active(&self) -> Style; + + fn hovered(&self) -> Style; +} + +struct Default; + +impl StyleSheet for Default { + fn active(&self) -> Style { + Style { + background: Background::Color(Color::from_rgb(0.95, 0.95, 0.95)), + dot_color: Color::from_rgb(0.3, 0.3, 0.3), + border_width: 1, + border_color: Color::from_rgb(0.6, 0.6, 0.6), + } + } + + fn hovered(&self) -> Style { + Style { + background: Background::Color(Color::from_rgb(0.90, 0.90, 0.90)), + ..self.active() + } + } +} + +impl std::default::Default for Box { + fn default() -> Self { + Box::new(Default) + } +} + +impl From for Box +where + T: 'static + StyleSheet, +{ + fn from(style: T) -> Self { + Box::new(style) + } +} -- cgit From ed30b487d649ffa0967ab8bfd66f4820ee2150fd Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 7 Jan 2020 02:54:54 +0100 Subject: Implement styling for `Checkbox` --- style/src/checkbox.rs | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++ style/src/lib.rs | 1 + 2 files changed, 56 insertions(+) create mode 100644 style/src/checkbox.rs (limited to 'style/src') diff --git a/style/src/checkbox.rs b/style/src/checkbox.rs new file mode 100644 index 00000000..e84dfd18 --- /dev/null +++ b/style/src/checkbox.rs @@ -0,0 +1,55 @@ +//! Show toggle controls using checkboxes. +use iced_core::{Background, Color}; + +/// The appearance of a checkbox. +#[derive(Debug)] +pub struct Style { + pub background: Background, + pub checkmark_color: Color, + pub border_radius: u16, + pub border_width: u16, + pub border_color: Color, +} + +/// A set of rules that dictate the style of a checkbox. +pub trait StyleSheet { + fn active(&self) -> Style; + + fn hovered(&self) -> Style; +} + +struct Default; + +impl StyleSheet for Default { + fn active(&self) -> Style { + Style { + background: Background::Color(Color::from_rgb(0.95, 0.95, 0.95)), + checkmark_color: Color::from_rgb(0.3, 0.3, 0.3), + border_radius: 5, + border_width: 1, + border_color: Color::from_rgb(0.6, 0.6, 0.6), + } + } + + fn hovered(&self) -> Style { + Style { + background: Background::Color(Color::from_rgb(0.90, 0.90, 0.90)), + ..self.active() + } + } +} + +impl std::default::Default for Box { + fn default() -> Self { + Box::new(Default) + } +} + +impl From for Box +where + T: 'static + StyleSheet, +{ + fn from(style: T) -> Self { + Box::new(style) + } +} diff --git a/style/src/lib.rs b/style/src/lib.rs index 991e0644..e0f56594 100644 --- a/style/src/lib.rs +++ b/style/src/lib.rs @@ -1,4 +1,5 @@ pub mod button; +pub mod checkbox; pub mod container; pub mod progress_bar; pub mod radio; -- cgit From cae4463e8379cddefbd8322a40ad8957bce07215 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Wed, 8 Jan 2020 03:30:15 +0100 Subject: Allow `Checkbox` style to change based on its state --- style/src/checkbox.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'style/src') diff --git a/style/src/checkbox.rs b/style/src/checkbox.rs index e84dfd18..3c645f15 100644 --- a/style/src/checkbox.rs +++ b/style/src/checkbox.rs @@ -13,15 +13,15 @@ pub struct Style { /// A set of rules that dictate the style of a checkbox. pub trait StyleSheet { - fn active(&self) -> Style; + fn active(&self, is_checked: bool) -> Style; - fn hovered(&self) -> Style; + fn hovered(&self, is_checked: bool) -> Style; } struct Default; impl StyleSheet for Default { - fn active(&self) -> Style { + fn active(&self, _is_checked: bool) -> Style { Style { background: Background::Color(Color::from_rgb(0.95, 0.95, 0.95)), checkmark_color: Color::from_rgb(0.3, 0.3, 0.3), @@ -31,10 +31,10 @@ impl StyleSheet for Default { } } - fn hovered(&self) -> Style { + fn hovered(&self, is_checked: bool) -> Style { Style { background: Background::Color(Color::from_rgb(0.90, 0.90, 0.90)), - ..self.active() + ..self.active(is_checked) } } } -- cgit