use std::sync::Arc;
use iced::{Color, Theme, border, widget::container};
pub(crate) type StyleFn = Arc<dyn Fn(&Theme) -> PlotStyle + Send + Sync>;
#[derive(Debug, Clone, Copy, PartialEq, Default)]
pub struct PlotStyle {
pub frame: container::Style,
pub plot_area: container::Style,
pub legend: container::Style,
pub controls_panel: container::Style,
pub cursor_overlay: container::Style,
pub tooltip: container::Style,
pub grid: GridStyle,
pub tick_label_color: Color,
pub axis_label_color: Color,
}
#[derive(Debug, Clone, Copy, PartialEq, Default)]
pub struct GridStyle {
pub major: Color,
pub minor: Color,
pub sub_minor: Color,
}
pub fn default_style(theme: &Theme) -> PlotStyle {
let palette = theme.extended_palette();
let grid_base = palette.background.base.text;
PlotStyle {
frame: container::background(theme.palette().background),
plot_area: container::background(theme.palette().background),
legend: container::Style {
background: Some(palette.background.weakest.color.into()),
text_color: Some(palette.background.weakest.text),
border: iced::Border {
width: 1.0,
radius: 5.0.into(),
color: palette.background.weak.color,
},
..container::Style::default()
},
controls_panel: container::Style {
background: Some(palette.background.weak.color.into()),
text_color: Some(palette.background.weak.text),
border: border::rounded(2),
..container::Style::default()
},
cursor_overlay: container::Style {
background: Some(palette.background.weak.color.into()),
text_color: Some(palette.background.weak.text),
border: border::rounded(2),
..container::Style::default()
},
tooltip: container::Style {
background: Some(palette.background.weak.color.scale_alpha(0.7).into()),
text_color: Some(palette.background.weak.text.scale_alpha(0.7)),
border: border::rounded(2),
..container::Style::default()
},
grid: GridStyle {
major: with_alpha(grid_base, 0.45),
minor: with_alpha(grid_base, 0.28),
sub_minor: with_alpha(grid_base, 0.10),
},
tick_label_color: palette.background.base.text,
axis_label_color: palette.background.strong.text,
}
}
fn with_alpha(color: Color, alpha: f32) -> Color {
Color { a: alpha, ..color }
}