use crate::compat::Rc;
use crate::core::Color;
use crate::style::WidgetStyle;
#[derive(Debug, Clone, Copy, PartialEq)]
pub(crate) struct Palette {
pub(crate) background: Color,
pub(crate) foreground: Color,
pub(crate) accent: Color,
pub(crate) primary: Color,
pub(crate) secondary: Color,
pub(crate) surface_container_high: Color,
}
pub(crate) struct ThemeSnapshot {
pub(crate) style: Option<Rc<WidgetStyle>>,
pub(crate) palette: Option<Palette>,
}
impl ThemeSnapshot {
pub(crate) fn capture(widget_name: &str) -> Self {
let style = crate::style::resolved_theme_style_shared(widget_name);
let palette = {
let manager = crate::style::theme_manager();
manager.current_theme().map(|theme| Palette {
background: theme.colors.background,
foreground: theme.colors.foreground,
accent: theme.colors.accent,
primary: theme.colors.primary,
secondary: theme.colors.secondary,
surface_container_high: theme.colors.surface_container_high,
})
};
Self { style, palette }
}
pub(crate) fn window_fill(&self) -> Color {
self.palette.map_or(Color::WHITE, |palette| palette.background)
}
pub(crate) fn accent(&self) -> Option<Color> {
self.palette.map(|palette| palette.accent)
}
pub(crate) fn surface_container_high(&self) -> Option<Color> {
self.palette.map(|palette| palette.surface_container_high)
}
}