use crate::style::default_colors;
use iced_core::Color;
#[derive(Debug, Clone)]
pub struct Appearance {
pub back_color: Color,
pub back_border_width: f32,
pub back_border_color: Color,
pub line_width: f32,
pub line_center_color: Color,
pub line_up_color: Color,
pub line_down_color: Color,
}
impl Default for Appearance {
fn default() -> Self {
Appearance {
back_color: default_colors::LIGHT_BACK,
back_border_width: 1.0,
back_border_color: default_colors::BORDER,
line_width: 2.0,
line_center_color: default_colors::BORDER,
line_up_color: default_colors::BORDER,
line_down_color: default_colors::BORDER,
}
}
}
pub trait StyleSheet {
type Style;
fn active(&self, style: &Self::Style) -> Appearance;
fn hovered(&self, style: &Self::Style) -> Appearance;
fn dragging(&self, style: &Self::Style) -> Appearance;
}
#[derive(Default)]
pub enum Ramp {
#[default]
Default,
Custom(Box<dyn StyleSheet<Style = iced_core::Theme>>),
}
impl<S> From<S> for Ramp
where
S: 'static + StyleSheet<Style = iced_core::Theme>,
{
fn from(val: S) -> Self {
Ramp::Custom(Box::new(val))
}
}
impl StyleSheet for iced_core::Theme {
type Style = Ramp;
fn active(&self, style: &Self::Style) -> Appearance {
match style {
Ramp::Default => Default::default(),
Ramp::Custom(custom) => custom.active(self),
}
}
fn hovered(&self, style: &Self::Style) -> Appearance {
match style {
Ramp::Default => Appearance {
back_color: default_colors::RAMP_BACK_HOVER,
..Default::default()
},
Ramp::Custom(custom) => custom.active(self),
}
}
fn dragging(&self, style: &Self::Style) -> Appearance {
self.hovered(style)
}
}