use crate::style::default_colors;
use iced_core::Color;
#[derive(Debug, Clone)]
pub struct Appearance {
pub rail_width: f32,
pub h_rail_color: Color,
pub v_rail_color: Color,
pub handle: HandleShape,
pub back_color: Color,
pub border_width: f32,
pub border_color: Color,
pub center_line_width: f32,
pub center_line_color: Color,
}
impl Default for Appearance {
fn default() -> Self {
Appearance {
rail_width: 2.0,
h_rail_color: default_colors::XY_PAD_RAIL,
v_rail_color: default_colors::XY_PAD_RAIL,
handle: HandleShape::Circle(Default::default()),
back_color: default_colors::LIGHT_BACK,
border_width: 1.0,
border_color: default_colors::BORDER,
center_line_width: 1.0,
center_line_color: default_colors::XY_PAD_CENTER_LINE,
}
}
}
#[derive(Debug, Clone)]
pub enum HandleShape {
Circle(HandleCircle),
Square(HandleSquare),
}
#[derive(Debug, Clone)]
pub struct HandleCircle {
pub color: Color,
pub diameter: f32,
pub border_width: f32,
pub border_color: Color,
}
impl Default for HandleCircle {
fn default() -> Self {
HandleCircle {
color: default_colors::LIGHT_BACK,
diameter: 11.0,
border_width: 2.0,
border_color: default_colors::BORDER,
}
}
}
#[derive(Debug, Clone)]
pub struct HandleSquare {
pub color: Color,
pub size: u16,
pub border_width: f32,
pub border_radius: f32,
pub border_color: Color,
}
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 XYPad {
#[default]
Default,
Custom(Box<dyn StyleSheet<Style = iced_core::Theme>>),
}
impl<S> From<S> for XYPad
where
S: 'static + StyleSheet<Style = iced_core::Theme>,
{
fn from(val: S) -> Self {
XYPad::Custom(Box::new(val))
}
}
impl StyleSheet for iced_core::Theme {
type Style = XYPad;
fn active(&self, style: &Self::Style) -> Appearance {
match style {
XYPad::Default => Default::default(),
XYPad::Custom(custom) => custom.active(self),
}
}
fn hovered(&self, style: &Self::Style) -> Appearance {
match style {
XYPad::Default => Appearance {
handle: HandleShape::Circle(HandleCircle {
color: default_colors::LIGHT_BACK_HOVER,
..Default::default()
}),
..Default::default()
},
XYPad::Custom(custom) => custom.hovered(self),
}
}
fn dragging(&self, style: &Self::Style) -> Appearance {
match style {
XYPad::Default => Appearance {
handle: HandleShape::Circle(HandleCircle {
color: default_colors::LIGHT_BACK_DRAG,
diameter: 9.0,
..Default::default()
}),
..Default::default()
},
XYPad::Custom(custom) => custom.dragging(self),
}
}
}