cosmic/widget/text_input/style.rs
1// Copyright 2019 H�ctor Ram�n, Iced contributors
2// Copyright 2023 System76 <info@system76.com>
3// SPDX-License-Identifier: MIT
4
5//! Change the appearance of a text input.
6
7use iced_core::{Background, Color, border::Radius};
8
9/// The appearance of a text input.
10#[derive(Debug, Clone, Copy)]
11pub struct Appearance {
12 /// The [`Background`] of the text input.
13 pub background: Background,
14 /// The border radius of the text input.
15 pub border_radius: Radius,
16 /// The border offset
17 pub border_offset: Option<f32>,
18 /// The border width of the text input.
19 pub border_width: f32,
20 /// The border [`Color`] of the text input.
21 pub border_color: Color,
22 /// The label [`Color`] of the text input.
23 pub label_color: Color,
24 /// The placeholder text [`Color`].
25 pub placeholder_color: Color,
26 /// The text [`Color`] of the text input.
27 pub selected_text_color: Color,
28 /// The icon [`Color`] of the text input.
29 pub icon_color: Option<Color>,
30 /// The text [`Color`] of the text input.
31 pub text_color: Option<Color>,
32 /// The selected fill [`Color`] of the text input.
33 pub selected_fill: Color,
34}
35
36/// A set of rules that dictate the style of a text input.
37pub trait StyleSheet {
38 /// The supported style of the [`StyleSheet`].
39 type Style: Default;
40
41 /// Produces the style of an active text input.
42 fn active(&self, style: &Self::Style) -> Appearance;
43
44 /// Produces the style of an errored text input.
45 fn error(&self, style: &Self::Style) -> Appearance;
46
47 /// Produces the style of a focused text input.
48 fn focused(&self, style: &Self::Style) -> Appearance;
49
50 /// Produces the style of an hovered text input.
51 fn hovered(&self, style: &Self::Style) -> Appearance {
52 self.focused(style)
53 }
54
55 /// Produces the style of a disabled text input.
56 fn disabled(&self, style: &Self::Style) -> Appearance;
57}