Skip to main content

ravenrs_widgets/
fill.rs

1use ravenrs_core::Color;
2use ravenrs_style::{Semantic, Theme};
3
4/// A color given either as a theme role (preferred, follows theme changes) or
5/// as a literal color.
6#[derive(Clone, Copy, Debug, PartialEq)]
7#[cfg_attr(feature = "live", ravenrs_live::expose(part = "variants"))]
8pub enum Fill {
9    /// A theme color role, resolved against the current theme.
10    Semantic(Semantic),
11    /// A fixed color.
12    Color(Color),
13}
14
15#[cfg_attr(feature = "live", ravenrs_live::expose)]
16impl Fill {
17    /// The concrete color under `theme`.
18    pub fn resolve(self, theme: &Theme) -> Color {
19        match self {
20            Self::Semantic(role) => theme.color(role),
21            Self::Color(c) => c,
22        }
23    }
24}
25
26impl From<Semantic> for Fill {
27    fn from(s: Semantic) -> Self {
28        Self::Semantic(s)
29    }
30}
31
32impl From<Color> for Fill {
33    fn from(c: Color) -> Self {
34        Self::Color(c)
35    }
36}