Skip to main content

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::border::Radius;
8use iced_core::{Background, Color};
9
10/// The appearance of a text input.
11#[derive(Debug, Clone, Copy)]
12pub struct Appearance {
13    /// The [`Background`] of the text input.
14    pub background: Background,
15    /// The border radius of the text input.
16    pub border_radius: Radius,
17    /// The border offset
18    pub border_offset: Option<f32>,
19    /// The border width of the text input.
20    pub border_width: f32,
21    /// The border [`Color`] of the text input.
22    pub border_color: Color,
23    /// The label [`Color`] of the text input.
24    pub label_color: Color,
25    /// The placeholder text [`Color`].
26    pub placeholder_color: Color,
27    /// The text [`Color`] of the text input.
28    pub selected_text_color: Color,
29    /// The icon [`Color`] of the text input.
30    pub icon_color: Option<Color>,
31    /// The text [`Color`] of the text input.
32    pub text_color: Option<Color>,
33    /// The selected fill [`Color`] of the text input.
34    pub selected_fill: Color,
35}
36
37/// A set of rules that dictate the style of a text input.
38pub trait StyleSheet {
39    /// The supported style of the [`StyleSheet`].
40    type Style: Default;
41
42    /// Produces the style of an active text input.
43    fn active(&self, style: &Self::Style) -> Appearance;
44
45    /// Produces the style of an errored text input.
46    fn error(&self, style: &Self::Style) -> Appearance;
47
48    /// Produces the style of a focused text input.
49    fn focused(&self, style: &Self::Style) -> Appearance;
50
51    /// Produces the style of an hovered text input.
52    fn hovered(&self, style: &Self::Style) -> Appearance {
53        self.focused(style)
54    }
55
56    /// Produces the style of a disabled text input.
57    fn disabled(&self, style: &Self::Style) -> Appearance;
58}