use crate::style::default_colors;
use iced_core::{Color, Theme};
#[derive(Debug, Clone)]
pub enum Appearance {
Circle(CircleAppearance),
Square(SquareAppearance),
Invisible,
}
#[derive(Debug, Clone)]
pub struct CircleAppearance {
pub color: Color,
pub border_width: f32,
pub border_color: Color,
}
impl Default for CircleAppearance {
fn default() -> Self {
CircleAppearance {
color: default_colors::LIGHT_BACK,
border_width: 1.0,
border_color: default_colors::BORDER,
}
}
}
#[derive(Debug, Clone)]
pub struct SquareAppearance {
pub color: Color,
pub border_width: f32,
pub border_radius: f32,
pub border_color: Color,
}
pub trait StyleSheet {
type Style;
fn idle(&self, style: &Self::Style) -> Appearance;
fn hovered(&self, style: &Self::Style) -> Appearance {
self.idle(style)
}
fn gesturing(&self, style: &Self::Style) -> Appearance {
self.hovered(style)
}
fn disabled(&self, style: &Self::Style) -> Appearance {
self.idle(style)
}
}
pub struct InvisibleStyle;
impl StyleSheet for InvisibleStyle {
type Style = iced_core::Theme;
fn idle(&self, _style: &Self::Style) -> Appearance {
Appearance::Invisible
}
fn hovered(&self, _style: &Self::Style) -> Appearance {
Appearance::Invisible
}
fn gesturing(&self, _style: &Self::Style) -> Appearance {
Appearance::Invisible
}
fn disabled(&self, _style: &Self::Style) -> Appearance {
Appearance::Invisible
}
}
#[derive(Default)]
pub enum ModRangeInput {
#[default]
Default,
Invisible,
Custom(Box<dyn StyleSheet<Style = Theme>>),
}
impl<S> From<S> for ModRangeInput
where
S: 'static + StyleSheet<Style = Theme>,
{
fn from(val: S) -> Self {
ModRangeInput::Custom(Box::new(val))
}
}
impl StyleSheet for Theme {
type Style = ModRangeInput;
fn idle(&self, style: &Self::Style) -> Appearance {
match style {
ModRangeInput::Default => Appearance::Circle(Default::default()),
ModRangeInput::Invisible => Appearance::Invisible,
ModRangeInput::Custom(custom) => custom.idle(self),
}
}
fn hovered(&self, style: &Self::Style) -> Appearance {
match style {
ModRangeInput::Default => Appearance::Circle(CircleAppearance {
color: default_colors::KNOB_BACK_HOVER,
..Default::default()
}),
ModRangeInput::Invisible => self.idle(style),
ModRangeInput::Custom(custom) => custom.idle(self),
}
}
fn gesturing(&self, style: &Self::Style) -> Appearance {
match style {
ModRangeInput::Default => self.hovered(style),
ModRangeInput::Invisible => self.idle(style),
ModRangeInput::Custom(custom) => custom.idle(self),
}
}
fn disabled(&self, style: &Self::Style) -> Appearance {
match style {
ModRangeInput::Default => Appearance::Circle(Default::default()),
ModRangeInput::Invisible => Appearance::Invisible,
ModRangeInput::Custom(custom) => custom.disabled(self),
}
}
}