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/container.rs | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 style/src/container.rs (limited to 'style/src/container.rs') 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) + } +} -- 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 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'style/src/container.rs') 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) -- 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/container.rs') 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 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/container.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'style/src/container.rs') 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