diff options
Diffstat (limited to 'style')
| -rw-r--r-- | style/src/lib.rs | 1 | ||||
| -rw-r--r-- | style/src/text_editor.rs | 47 | ||||
| -rw-r--r-- | style/src/theme.rs | 113 | 
3 files changed, 161 insertions, 0 deletions
| diff --git a/style/src/lib.rs b/style/src/lib.rs index 30f17a44..e4097434 100644 --- a/style/src/lib.rs +++ b/style/src/lib.rs @@ -29,6 +29,7 @@ pub mod rule;  pub mod scrollable;  pub mod slider;  pub mod svg; +pub mod text_editor;  pub mod text_input;  pub mod theme;  pub mod toggler; diff --git a/style/src/text_editor.rs b/style/src/text_editor.rs new file mode 100644 index 00000000..f6bae7e6 --- /dev/null +++ b/style/src/text_editor.rs @@ -0,0 +1,47 @@ +//! Change the appearance of a text editor. +use crate::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; +} diff --git a/style/src/theme.rs b/style/src/theme.rs index 3c1f2de6..47010728 100644 --- a/style/src/theme.rs +++ b/style/src/theme.rs @@ -17,6 +17,7 @@ use crate::rule;  use crate::scrollable;  use crate::slider;  use crate::svg; +use crate::text_editor;  use crate::text_input;  use crate::toggler; @@ -1174,3 +1175,115 @@ impl text_input::StyleSheet for Theme {          self.placeholder_color(style)      }  } + +/// The style of a text input. +#[derive(Default)] +pub enum TextEditor { +    /// The default style. +    #[default] +    Default, +    /// A custom style. +    Custom(Box<dyn text_editor::StyleSheet<Style = Theme>>), +} + +impl text_editor::StyleSheet for Theme { +    type Style = TextEditor; + +    fn active(&self, style: &Self::Style) -> text_editor::Appearance { +        if let TextEditor::Custom(custom) = style { +            return custom.active(self); +        } + +        let palette = self.extended_palette(); + +        text_editor::Appearance { +            background: palette.background.base.color.into(), +            border_radius: 2.0.into(), +            border_width: 1.0, +            border_color: palette.background.strong.color, +        } +    } + +    fn hovered(&self, style: &Self::Style) -> text_editor::Appearance { +        if let TextEditor::Custom(custom) = style { +            return custom.hovered(self); +        } + +        let palette = self.extended_palette(); + +        text_editor::Appearance { +            background: palette.background.base.color.into(), +            border_radius: 2.0.into(), +            border_width: 1.0, +            border_color: palette.background.base.text, +        } +    } + +    fn focused(&self, style: &Self::Style) -> text_editor::Appearance { +        if let TextEditor::Custom(custom) = style { +            return custom.focused(self); +        } + +        let palette = self.extended_palette(); + +        text_editor::Appearance { +            background: palette.background.base.color.into(), +            border_radius: 2.0.into(), +            border_width: 1.0, +            border_color: palette.primary.strong.color, +        } +    } + +    fn placeholder_color(&self, style: &Self::Style) -> Color { +        if let TextEditor::Custom(custom) = style { +            return custom.placeholder_color(self); +        } + +        let palette = self.extended_palette(); + +        palette.background.strong.color +    } + +    fn value_color(&self, style: &Self::Style) -> Color { +        if let TextEditor::Custom(custom) = style { +            return custom.value_color(self); +        } + +        let palette = self.extended_palette(); + +        palette.background.base.text +    } + +    fn selection_color(&self, style: &Self::Style) -> Color { +        if let TextEditor::Custom(custom) = style { +            return custom.selection_color(self); +        } + +        let palette = self.extended_palette(); + +        palette.primary.weak.color +    } + +    fn disabled(&self, style: &Self::Style) -> text_editor::Appearance { +        if let TextEditor::Custom(custom) = style { +            return custom.disabled(self); +        } + +        let palette = self.extended_palette(); + +        text_editor::Appearance { +            background: palette.background.weak.color.into(), +            border_radius: 2.0.into(), +            border_width: 1.0, +            border_color: palette.background.strong.color, +        } +    } + +    fn disabled_color(&self, style: &Self::Style) -> Color { +        if let TextEditor::Custom(custom) = style { +            return custom.disabled_color(self); +        } + +        self.placeholder_color(style) +    } +} | 
