#[doc(inline)]
#[allow(unused_imports)]
use super::cellgrid::CellGrid;
use crate::core::{Color, Theme};
#[derive(Clone, Copy, PartialEq)]
pub struct Style {
pub background: Color,
pub grid_line: Color,
pub page_break: Color,
pub resizing: Color,
pub scrollbar: Color,
pub rail: Color,
pub rail_ends: EndStyle,
pub scroller: Color,
pub scroller_ends: EndStyle,
pub scroller_hover: Color,
}
impl Default for Style {
fn default() -> Self {
Self {
background: Color::default(),
grid_line: Color::default(),
page_break: Color::default(),
resizing: Color::default(),
scrollbar: Color::default(),
rail: Color::default(),
rail_ends: EndStyle::default(),
scroller: Color::default(),
scroller_ends: EndStyle::default(),
scroller_hover: Color::default(),
}
}
}
#[derive(Default, Clone, Copy, PartialEq)]
pub(crate) struct StyleOptions {
pub background: Option<Color>,
pub grid_line: Option<Color>,
pub page_break: Option<Color>,
pub resizing: Option<Color>,
pub scrollbar: Option<Color>,
pub rail: Option<Color>,
pub rail_ends: Option<EndStyle>,
pub scroller: Option<Color>,
pub scroller_ends: Option<EndStyle>,
pub scroller_hover: Option<Color>,
}
#[derive(Clone, Copy, PartialEq)]
pub enum EndStyle {
Sharp,
Round,
BluntCorners(f32),
}
impl Default for EndStyle {
fn default() -> Self {
EndStyle::Sharp
}
}
pub enum Component {
Background,
GridLines,
PageBreak,
Scrollbar,
Rail,
Scroller,
ScrollerHover,
Resizing,
}
pub trait Catalog {
type Class<'a>;
fn default<'a>() -> <Self as Catalog>::Class<'a>;
fn style(&self, class: &<Self as Catalog>::Class<'_>) -> Style;
}
pub type StyleFn<'a, Theme> = Box<dyn Fn(&Theme) -> Style + 'a>;
impl Catalog for Theme {
type Class<'a> = StyleFn<'a, Self>;
fn default<'a>() -> StyleFn<'a, Self> {
Box::new(default)
}
fn style(&self, class: &StyleFn<'_, Self>) -> Style {
class(self)
}
}
pub fn default(theme: &Theme) -> Style {
let palette = theme.extended_palette();
Style {
background: palette.background.weak.color,
grid_line: palette.primary.base.text,
page_break: palette.primary.strong.color,
resizing: palette.primary.base.text,
scrollbar: palette.background.weakest.color,
rail: palette.secondary.base.color,
rail_ends: EndStyle::Sharp,
scroller: palette.background.weak.color,
scroller_ends: EndStyle::Sharp,
scroller_hover: palette.primary.strong.color,
}
}