summaryrefslogtreecommitdiff
path: root/schist_desktop_gui/src/gui/components/input.rs
blob: ce4d228911b1b383c2741f76fa08110b9e5cf207 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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,
    }
}