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/text_input.rs | 72 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 style/src/text_input.rs (limited to 'style/src/text_input.rs') 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 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/text_input.rs') 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/text_input.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'style/src/text_input.rs') 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