From 6a07e341caa2a56390eb76171e44081281391b6c Mon Sep 17 00:00:00 2001 From: Ashley Wulber Date: Mon, 28 Aug 2023 12:05:31 -0400 Subject: [PATCH] chore: custom text input style --- src/widget/text_input/style.rs | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/widget/text_input/style.rs b/src/widget/text_input/style.rs index 1a3f3b8d..77cdb4ad 100644 --- a/src/widget/text_input/style.rs +++ b/src/widget/text_input/style.rs @@ -50,13 +50,21 @@ pub trait StyleSheet { fn disabled(&self, style: &Self::Style) -> Appearance; } -#[derive(Copy, Clone, Default)] +#[derive(Default)] pub enum TextInput { #[default] Default, ExpandableSearch, Search, Inline, + Custom { + active: Box Appearance>, + error: Box Appearance>, + hovered: Box Appearance>, + focused: Box Appearance>, + disabled: Box Appearance>, + placeholder_color: Box Color>, + }, } impl StyleSheet for crate::Theme { @@ -113,6 +121,7 @@ impl StyleSheet for crate::Theme { selected_fill: palette.accent_color().into(), label_color: label_color.into(), }, + TextInput::Custom { active, .. } => active(self), } } @@ -157,6 +166,7 @@ impl StyleSheet for crate::Theme { selected_fill: palette.accent_color().into(), label_color: label_color.into(), }, + TextInput::Custom { error, .. } => error(self), } } @@ -212,6 +222,7 @@ impl StyleSheet for crate::Theme { selected_fill: palette.accent_color().into(), label_color: label_color.into(), }, + TextInput::Custom { hovered, .. } => hovered(self), } } @@ -258,10 +269,17 @@ impl StyleSheet for crate::Theme { selected_fill: palette.accent_color().into(), label_color: label_color.into(), }, + TextInput::Custom { focused, .. } => focused(self), } } - fn placeholder_color(&self, _style: &Self::Style) -> Color { + fn placeholder_color(&self, style: &Self::Style) -> Color { + if let TextInput::Custom { + placeholder_color, .. + } = style + { + return placeholder_color(self); + } let palette = self.cosmic(); let mut neutral_9 = palette.palette.neutral_9; neutral_9.alpha = 0.7; @@ -269,6 +287,9 @@ impl StyleSheet for crate::Theme { } fn disabled(&self, style: &Self::Style) -> Appearance { + if let TextInput::Custom { disabled, .. } = style { + return disabled(self); + } self.active(style) } }