cosmic/theme/style/
menu_bar.rsuse crate::Theme;
use iced_widget::core::Color;
#[derive(Debug, Clone, Copy)]
pub struct Appearance {
pub background: Color,
pub border_width: f32,
pub bar_border_radius: [f32; 4],
pub menu_border_radius: [f32; 4],
pub border_color: Color,
pub background_expand: [u16; 4],
pub path: Color,
}
pub trait StyleSheet {
type Style: Default;
fn appearance(&self, style: &Self::Style) -> Appearance;
}
#[derive(Default)]
#[allow(missing_debug_implementations)]
pub enum MenuBarStyle {
#[default]
Default,
Custom(Box<dyn StyleSheet<Style = Theme>>),
}
impl From<fn(&Theme) -> Appearance> for MenuBarStyle {
fn from(f: fn(&Theme) -> Appearance) -> Self {
Self::Custom(Box::new(f))
}
}
impl StyleSheet for fn(&Theme) -> Appearance {
type Style = Theme;
fn appearance(&self, style: &Self::Style) -> Appearance {
(self)(style)
}
}
impl StyleSheet for Theme {
type Style = MenuBarStyle;
fn appearance(&self, style: &Self::Style) -> Appearance {
let cosmic = self.cosmic();
let component = &cosmic.background.component;
match style {
MenuBarStyle::Default => Appearance {
background: component.base.into(),
border_width: 1.0,
bar_border_radius: cosmic.corner_radii.radius_xl,
menu_border_radius: cosmic.corner_radii.radius_s.map(|x| x + 2.0),
border_color: component.divider.into(),
background_expand: [1; 4],
path: component.hover.into(),
},
MenuBarStyle::Custom(c) => c.appearance(self),
}
}
}