diff options
| author | Joe Carstairs <me@joeac.net> | 2026-08-29 10:21:53 +0100 |
|---|---|---|
| committer | Joe Carstairs <me@joeac.net> | 2026-08-29 10:22:20 +0100 |
| commit | aae9e194fb3275ad74323a7f6b63b6c3b99201b1 (patch) | |
| tree | 8d818214a6088917a00cd8c716f3e48fd0bfe029 /schist_desktop_gui | |
| parent | b56a9528c11ddca00dd8549a21986b453a353577 (diff) | |
task-001: adds input component
Diffstat (limited to 'schist_desktop_gui')
| -rw-r--r-- | schist_desktop_gui/src/gui/components.rs | 1 | ||||
| -rw-r--r-- | schist_desktop_gui/src/gui/components/input.rs | 59 |
2 files changed, 60 insertions, 0 deletions
diff --git a/schist_desktop_gui/src/gui/components.rs b/schist_desktop_gui/src/gui/components.rs index 8ad5caa..d8866b5 100644 --- a/schist_desktop_gui/src/gui/components.rs +++ b/schist_desktop_gui/src/gui/components.rs @@ -3,6 +3,7 @@ pub mod balances_view; pub mod bucket_navigation_entry; pub mod buckets_view; pub mod button; +pub mod input; pub mod navigation; pub mod new_transaction_form; pub mod panel; diff --git a/schist_desktop_gui/src/gui/components/input.rs b/schist_desktop_gui/src/gui/components/input.rs new file mode 100644 index 0000000..ce4d228 --- /dev/null +++ b/schist_desktop_gui/src/gui/components/input.rs @@ -0,0 +1,59 @@ +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, +) -> TextInput<'a, Message> +{ + iced::widget::text_input(placeholder, "") + .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, + } +} |
