use crate::style::Color;
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct ColorStop {
pub position: f32,
pub color: Color,
}
impl ColorStop {
pub fn new(position: f32, color: Color) -> Self {
Self {
position: position.clamp(0.0, 1.0),
color,
}
}
pub fn start(color: Color) -> Self {
Self::new(0.0, color)
}
pub fn end(color: Color) -> Self {
Self::new(1.0, color)
}
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub enum InterpolationMode {
#[default]
Rgb,
Hsl,
HslShort,
HslLong,
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub enum SpreadMode {
#[default]
Clamp,
Repeat,
Reflect,
}
#[derive(Clone, Copy, Debug, Default, PartialEq)]
pub enum GradientDirection {
#[default]
ToRight,
ToLeft,
ToBottom,
ToTop,
ToBottomRight,
ToTopRight,
Angle(f32),
}
impl GradientDirection {
pub fn to_radians(&self) -> f32 {
match self {
Self::ToRight => 0.0,
Self::ToLeft => std::f32::consts::PI,
Self::ToBottom => std::f32::consts::FRAC_PI_2,
Self::ToTop => -std::f32::consts::FRAC_PI_2,
Self::ToBottomRight => std::f32::consts::FRAC_PI_4,
Self::ToTopRight => -std::f32::consts::FRAC_PI_4,
Self::Angle(deg) => deg.to_radians(),
}
}
}