Skip to main content

zest_theme/
component.rs

1//! [`Component`]: per-state colors for an interactive element.
2//!
3//! Embedded-trimmed: no `hovered` state (touch screens have no pointer-over
4//! phase).
5
6use embedded_graphics::pixelcolor::PixelColor;
7
8/// Colors for an interactive UI element (button, tab, link).
9///
10/// The five fields cover the four visual states in
11/// [`Status`](crate::Status): `base` is used for `Active` and `Focused`,
12/// `pressed` for `Pressed`, and `disabled` for `Disabled`. The remaining
13/// fields carry the foreground (`on_base`) and border stroke.
14#[derive(Copy, Clone, Debug, PartialEq, Eq)]
15pub struct Component<C: PixelColor> {
16    /// Resting background color.
17    pub base: C,
18    /// Background while being pressed.
19    pub pressed: C,
20    /// Background when no `on_press` is bound.
21    pub disabled: C,
22    /// Color of content (text, icons) drawn on top of the background.
23    pub on_base: C,
24    /// Border stroke color.
25    pub border: C,
26}
27
28impl<C: PixelColor> Component<C> {
29    /// Construct a component.
30    #[must_use]
31    pub const fn new(base: C, pressed: C, disabled: C, on_base: C, border: C) -> Self {
32        Self {
33            base,
34            pressed,
35            disabled,
36            on_base,
37            border,
38        }
39    }
40}