use iced::{Border, Theme, widget::TextInput}; use crate::style::{BORDER_WIDTH, BORDER_WIDTH_THICK, TEXT_SIZE_SM}; pub fn input<'a, Message: Clone>( placeholder: &'a str, content: &'a str, ) -> TextInput<'a, Message> { iced::widget::text_input(placeholder, content) .style(move |theme, status| match status { iced::widget::text_input::Status::Active => hovered_input_style(theme), iced::widget::text_input::Status::Disabled => disabled_input_style(theme), iced::widget::text_input::Status::Hovered => base_input_style(theme), iced::widget::text_input::Status::Focused { is_hovered } => focused_input_style(theme, is_hovered), }) .size(u32::from(TEXT_SIZE_SM)) .width(iced::Length::Fill) } fn hovered_input_style(theme: &Theme) -> iced::widget::text_input::Style { base_input_style(theme) } fn disabled_input_style(theme: &Theme) -> iced::widget::text_input::Style { let base_input_style = base_input_style(theme); iced::widget::text_input::Style { value: theme.extended_palette().primary.weak.text, icon: theme.extended_palette().primary.weak.text, ..base_input_style } } fn focused_input_style(theme: &Theme, _is_hovered: bool) -> iced::widget::text_input::Style { let base_input_style = base_input_style(theme); iced::widget::text_input::Style { border: Border { width: f32::from(BORDER_WIDTH_THICK), ..base_input_style.border }, ..base_input_style } } fn base_input_style(theme: &Theme) -> iced::widget::text_input::Style { iced::widget::text_input::Style { background: iced::Background::Color( theme.extended_palette().primary.weak.color, ), border: iced::Border { color: theme.extended_palette().primary.base.text, width: f32::from(BORDER_WIDTH), ..Default::default() }, value: theme.extended_palette().primary.base.text, placeholder: theme.extended_palette().primary.weak.text, icon: theme.extended_palette().primary.base.text, selection: theme.extended_palette().secondary.base.color, } }