From 6448429103c9c82b90040ac5a5a097bdded23f82 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 12 Sep 2023 14:51:00 +0200 Subject: Draft `Editor` API and `TextEditor` widget --- style/src/text_editor.rs | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 style/src/text_editor.rs (limited to 'style/src/text_editor.rs') diff --git a/style/src/text_editor.rs b/style/src/text_editor.rs new file mode 100644 index 00000000..45c9bad8 --- /dev/null +++ b/style/src/text_editor.rs @@ -0,0 +1,47 @@ +//! Change the appearance of a text editor. +use iced_core::{Background, BorderRadius, Color}; + +/// The appearance of a text input. +#[derive(Debug, Clone, Copy)] +pub struct Appearance { + /// The [`Background`] of the text input. + pub background: Background, + /// The border radius of the text input. + pub border_radius: BorderRadius, + /// The border width of the text input. + pub border_width: f32, + /// The border [`Color`] of the text input. + pub border_color: Color, +} + +/// A set of rules that dictate the style of a text input. +pub trait StyleSheet { + /// The supported style of the [`StyleSheet`]. + type Style: Default; + + /// Produces the style of an active text input. + fn active(&self, style: &Self::Style) -> Appearance; + + /// Produces the style of a focused text input. + fn focused(&self, style: &Self::Style) -> Appearance; + + /// Produces the [`Color`] of the placeholder of a text input. + fn placeholder_color(&self, style: &Self::Style) -> Color; + + /// Produces the [`Color`] of the value of a text input. + fn value_color(&self, style: &Self::Style) -> Color; + + /// Produces the [`Color`] of the value of a disabled text input. + fn disabled_color(&self, style: &Self::Style) -> Color; + + /// Produces the [`Color`] of the selection of a text input. + fn selection_color(&self, style: &Self::Style) -> Color; + + /// Produces the style of an hovered text input. + fn hovered(&self, style: &Self::Style) -> Appearance { + self.focused(style) + } + + /// Produces the style of a disabled text input. + fn disabled(&self, style: &Self::Style) -> Appearance; +} -- cgit From 76dc82e8e8b5201ec10f8d00d851c1decf998583 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Sun, 17 Sep 2023 15:29:14 +0200 Subject: Draft `Highlighter` API --- style/src/text_editor.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'style/src/text_editor.rs') diff --git a/style/src/text_editor.rs b/style/src/text_editor.rs index 45c9bad8..f1c31287 100644 --- a/style/src/text_editor.rs +++ b/style/src/text_editor.rs @@ -1,5 +1,6 @@ //! Change the appearance of a text editor. -use iced_core::{Background, BorderRadius, Color}; +use crate::core::text::highlighter; +use crate::core::{self, Background, BorderRadius, Color}; /// The appearance of a text input. #[derive(Debug, Clone, Copy)] @@ -45,3 +46,16 @@ pub trait StyleSheet { /// Produces the style of a disabled text input. fn disabled(&self, style: &Self::Style) -> Appearance; } + +pub trait Highlight { + fn format(&self, theme: &Theme) -> highlighter::Format; +} + +impl Highlight for () { + fn format(&self, _theme: &Theme) -> highlighter::Format { + highlighter::Format { + color: None, + font: None, + } + } +} -- cgit From f806d001e6fb44b5a45029ca257261e6e0d4d4b2 Mon Sep 17 00:00:00 2001 From: Héctor Ramón Jiménez Date: Tue, 19 Sep 2023 20:48:50 +0200 Subject: Introduce new `iced_highlighter` subcrate --- style/src/text_editor.rs | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) (limited to 'style/src/text_editor.rs') diff --git a/style/src/text_editor.rs b/style/src/text_editor.rs index f1c31287..f6bae7e6 100644 --- a/style/src/text_editor.rs +++ b/style/src/text_editor.rs @@ -1,6 +1,5 @@ //! Change the appearance of a text editor. -use crate::core::text::highlighter; -use crate::core::{self, Background, BorderRadius, Color}; +use crate::core::{Background, BorderRadius, Color}; /// The appearance of a text input. #[derive(Debug, Clone, Copy)] @@ -46,16 +45,3 @@ pub trait StyleSheet { /// Produces the style of a disabled text input. fn disabled(&self, style: &Self::Style) -> Appearance; } - -pub trait Highlight { - fn format(&self, theme: &Theme) -> highlighter::Format; -} - -impl Highlight for () { - fn format(&self, _theme: &Theme) -> highlighter::Format { - highlighter::Format { - color: None, - font: None, - } - } -} -- cgit