use std::fmt::{self, Display, Formatter};
#[derive(Debug, Clone, Copy, PartialEq, Default)]
pub struct Position {
pub x: f32,
pub y: f32,
}
impl Position {
pub const FLAG: &'static str = "--transition-pos";
pub const CENTER: Self = Self { x: 0.5, y: 0.5 };
pub const TOP_LEFT: Self = Self { x: 0.0, y: 0.0 };
pub const TOP_RIGHT: Self = Self { x: 1.0, y: 0.0 };
pub const BOTTOM_LEFT: Self = Self { x: 0.0, y: 1.0 };
pub const BOTTOM_RIGHT: Self = Self { x: 1.0, y: 1.0 };
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub struct WaveDimensions {
pub width: u32,
pub height: u32,
}
impl WaveDimensions {
pub const FLAG: &'static str = "--transition-wave";
pub const DEFAULT: Self = Self {
width: 20,
height: 20,
};
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct BezierCurve {
pub x1: f32,
pub y1: f32,
pub x2: f32,
pub y2: f32,
}
impl Default for BezierCurve {
fn default() -> Self {
Self::DEFAULT
}
}
impl BezierCurve {
pub const FLAG: &'static str = "--transition-bezier";
pub const DEFAULT: Self = Self {
x1: 0.54,
y1: 0.0,
x2: 0.34,
y2: 0.99,
};
pub const LINEAR: Self = Self {
x1: 0.0,
y1: 0.0,
x2: 1.0,
y2: 1.0,
};
pub const EASE_OUT: Self = Self {
x1: 0.0,
y1: 0.0,
x2: 0.2,
y2: 1.0,
};
pub const EASE_IN_OUT: Self = Self {
x1: 0.42,
y1: 0.0,
x2: 0.58,
y2: 1.0,
};
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct TransitionDuration(pub f32);
impl TransitionDuration {
pub const FLAG: &'static str = "--transition-duration";
}
impl Default for TransitionDuration {
fn default() -> Self {
Self(0.7)
}
}
impl Display for TransitionDuration {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
Display::fmt(&self.0, f)
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct TransitionFps(pub u32);
impl TransitionFps {
pub const FLAG: &'static str = "--transition-fps";
}
impl Default for TransitionFps {
fn default() -> Self {
Self(60)
}
}
impl Display for TransitionFps {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
Display::fmt(&self.0, f)
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct TransitionStep(pub u8);
impl TransitionStep {
pub const FLAG: &'static str = "--transition-step";
}
impl Display for TransitionStep {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
Display::fmt(&self.0, f)
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct TransitionAngle(pub u16);
impl TransitionAngle {
pub const FLAG: &'static str = "--transition-angle";
}
impl Default for TransitionAngle {
fn default() -> Self {
Self(45)
}
}
impl Display for TransitionAngle {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
Display::fmt(&self.0, f)
}
}
#[derive(Debug, Clone, Copy, PartialEq, Default)]
pub enum TransitionType {
None,
#[default]
Simple,
Fade {
bezier: BezierCurve,
},
Left,
Right,
Top,
Bottom,
Wipe {
angle: TransitionAngle,
},
Wave {
angle: TransitionAngle,
dimensions: WaveDimensions,
},
Grow {
position: Position,
},
Center,
Outer {
position: Position,
},
Any,
Random,
}
impl TransitionType {
pub const FLAG: &'static str = "--transition-type";
pub(super) fn type_name(&self) -> &'static str {
match self {
Self::None => "none",
Self::Simple => "simple",
Self::Fade { .. } => "fade",
Self::Left => "left",
Self::Right => "right",
Self::Top => "top",
Self::Bottom => "bottom",
Self::Wipe { .. } => "wipe",
Self::Wave { .. } => "wave",
Self::Grow { .. } => "grow",
Self::Center => "center",
Self::Outer { .. } => "outer",
Self::Any => "any",
Self::Random => "random",
}
}
pub(super) fn cli_args(&self) -> Vec<(&'static str, String)> {
match self {
Self::None => vec![(TransitionStep::FLAG, "255".to_string())],
Self::Fade { bezier } => vec![(
BezierCurve::FLAG,
format!("{},{},{},{}", bezier.x1, bezier.y1, bezier.x2, bezier.y2),
)],
Self::Wipe { angle } => vec![(TransitionAngle::FLAG, angle.to_string())],
Self::Wave { angle, dimensions } => vec![
(TransitionAngle::FLAG, angle.to_string()),
(
WaveDimensions::FLAG,
format!("{},{}", dimensions.width, dimensions.height),
),
],
Self::Grow { position } | Self::Outer { position } => {
vec![(Position::FLAG, format!("{},{}", position.x, position.y))]
}
Self::Simple
| Self::Left
| Self::Right
| Self::Top
| Self::Bottom
| Self::Center
| Self::Any
| Self::Random => vec![],
}
}
pub fn as_str(&self) -> &'static str {
match self {
Self::None => "None",
Self::Simple => "Simple",
Self::Fade { .. } => "Fade",
Self::Left => "Left",
Self::Right => "Right",
Self::Top => "Top",
Self::Bottom => "Bottom",
Self::Wipe { .. } => "Wipe",
Self::Wave { .. } => "Wave",
Self::Grow { .. } => "Grow",
Self::Center => "Center",
Self::Outer { .. } => "Outer",
Self::Any => "Any",
Self::Random => "Random",
}
}
}
impl Display for TransitionType {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
f.write_str(self.as_str())
}
}
#[derive(Debug, Clone, Copy, PartialEq, Default)]
pub struct TransitionConfig {
pub transition_type: TransitionType,
pub duration: TransitionDuration,
pub fps: TransitionFps,
pub step: Option<TransitionStep>,
}