use crate::theme::{Rgb, Theme};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
#[non_exhaustive]
pub enum TypeScale {
#[default]
Compact,
Large,
XLarge,
}
impl TypeScale {
#[must_use]
pub const fn compact() -> Self {
Self::Compact
}
#[must_use]
pub const fn large() -> Self {
Self::Large
}
#[must_use]
pub const fn xlarge() -> Self {
Self::XLarge
}
#[must_use]
pub const fn pixel(self) -> u32 {
match self {
Self::Compact => 1,
Self::Large => 2,
Self::XLarge => 3,
}
}
#[must_use]
pub const fn advance(self) -> u32 {
6 * self.pixel()
}
#[must_use]
pub const fn row_height(self) -> u32 {
match self {
Self::Compact => 18,
Self::Large => 28,
Self::XLarge => 40,
}
}
#[must_use]
pub const fn header_height(self) -> u32 {
match self {
Self::Compact => 20,
Self::Large => 32,
Self::XLarge => 44,
}
}
#[must_use]
pub const fn pad(self) -> u32 {
match self {
Self::Compact => 8,
Self::Large => 12,
Self::XLarge => 16,
}
}
#[must_use]
pub const fn cell_pad_x(self) -> u32 {
match self {
Self::Compact => 8,
Self::Large => 12,
Self::XLarge => 16,
}
}
#[must_use]
pub const fn min_col(self) -> u32 {
match self {
Self::Compact => 56,
Self::Large => 88,
Self::XLarge => 120,
}
}
#[must_use]
pub const fn max_col(self) -> u32 {
match self {
Self::Compact => 240,
Self::Large => 360,
Self::XLarge => 480,
}
}
#[must_use]
pub const fn plot_left(self) -> u32 {
self.advance().saturating_mul(7).saturating_add(self.pad())
}
#[must_use]
pub const fn plot_bottom(self) -> u32 {
self.row_height().saturating_add(4)
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
#[non_exhaustive]
pub enum MarkerStyle {
None,
Last,
#[default]
Hover,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub struct ChartStyle {
pub stroke_px: u8,
pub area_fill: bool,
pub area_alpha: u8,
pub tick_count: u8,
pub nice_ticks: bool,
pub series: [Rgb; 4],
pub plot_background: Rgb,
pub markers: MarkerStyle,
}
impl Default for ChartStyle {
fn default() -> Self {
Self::from_theme(&Theme::default())
}
}
impl ChartStyle {
#[must_use]
pub fn from_theme(theme: &Theme) -> Self {
Self {
stroke_px: 2,
area_fill: true,
area_alpha: 48,
tick_count: 5,
nice_ticks: true,
series: [
theme.series,
Rgb::new(0x3e, 0xc8, 0xbf),
theme.crosshair,
Rgb::new(0xc0, 0x84, 0xfc),
],
plot_background: Rgb::new(
theme.background.r.saturating_add(14),
theme.background.g.saturating_add(16),
theme.background.b.saturating_add(22),
),
markers: MarkerStyle::Hover,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub struct Appearance {
pub theme: Theme,
pub type_scale: TypeScale,
pub chart: ChartStyle,
}
impl Default for Appearance {
fn default() -> Self {
let theme = Theme::default();
Self {
chart: ChartStyle::from_theme(&theme),
theme,
type_scale: TypeScale::Compact,
}
}
}
impl Appearance {
#[must_use]
pub fn compact() -> Self {
Self::default()
}
#[must_use]
pub fn light() -> Self {
let theme = Theme::light();
Self {
chart: ChartStyle::from_theme(&theme),
theme,
type_scale: TypeScale::Compact,
}
}
#[must_use]
pub fn high_contrast() -> Self {
let theme = Theme::high_contrast();
Self {
chart: ChartStyle::from_theme(&theme),
theme,
type_scale: TypeScale::Compact,
}
}
#[must_use]
pub fn large() -> Self {
Self {
type_scale: TypeScale::Large,
..Self::default()
}
}
#[must_use]
pub fn xlarge() -> Self {
Self {
type_scale: TypeScale::XLarge,
..Self::default()
}
}
}