use crate::enums::SchemeColor;
#[derive(Debug, Clone)]
pub enum Coord {
Inches(f64),
Emu(i64),
Percent(f64),
}
impl Coord {
pub fn to_emu(&self, layout_dim: i64) -> i64 {
use crate::enums::EMU;
match self {
Coord::Inches(in_val) => {
if *in_val > 100.0 {
*in_val as i64 } else {
(EMU as f64 * in_val).round() as i64
}
}
Coord::Emu(v) => *v,
Coord::Percent(pct) => ((pct / 100.0) * layout_dim as f64).round() as i64,
}
}
}
#[derive(Debug, Clone, Default)]
pub struct ThemeColorMod {
pub lum_mod: Option<i32>,
pub lum_off: Option<i32>,
pub tint: Option<i32>,
pub shade: Option<i32>,
pub sat_mod: Option<i32>,
}
impl ThemeColorMod {
pub fn lum(lum_mod: i32, lum_off: i32) -> Self {
ThemeColorMod { lum_mod: Some(lum_mod), lum_off: Some(lum_off), ..Default::default() }
}
pub fn tint(t: i32) -> Self {
ThemeColorMod { tint: Some(t), ..Default::default() }
}
pub fn shade(s: i32) -> Self {
ThemeColorMod { shade: Some(s), ..Default::default() }
}
}
#[derive(Debug, Clone)]
pub enum Color {
Hex(String),
Theme(SchemeColor),
ThemedWith(SchemeColor, ThemeColorMod),
}
impl Color {
pub fn from_str(s: &str) -> Self {
let clean = s.trim_start_matches('#');
if crate::enums::is_hex_color(clean) {
Color::Hex(clean.to_uppercase())
} else if let Some(sc) = SchemeColor::from_str(clean) {
Color::Theme(sc)
} else {
Color::Hex(crate::enums::DEF_FONT_COLOR.to_string())
}
}
pub fn as_ooxml_val(&self) -> String {
match self {
Color::Hex(h) => h.to_uppercase(),
Color::Theme(sc) => sc.as_str().to_string(),
Color::ThemedWith(sc, _) => sc.as_str().to_string(),
}
}
pub fn is_hex(&self) -> bool {
matches!(self, Color::Hex(_))
}
}
#[derive(Debug, Clone)]
pub enum CustomGeomPoint {
MoveTo(f64, f64),
LineTo(f64, f64),
ArcTo { w_r: f64, h_r: f64, start_angle: f64, swing_angle: f64 },
CubicBezTo(f64, f64, f64, f64, f64, f64),
QuadBezTo(f64, f64, f64, f64),
Close,
}
#[derive(Debug, Clone)]
pub enum Margin {
Uniform(f64),
Trbl([f64; 4]),
}
impl Default for Margin {
fn default() -> Self {
Margin::Trbl(crate::enums::DEF_CELL_MARGIN_IN)
}
}
impl Margin {
pub fn top(&self) -> f64 {
match self {
Margin::Uniform(v) => *v,
Margin::Trbl(a) => a[0],
}
}
pub fn right(&self) -> f64 {
match self {
Margin::Uniform(v) => *v,
Margin::Trbl(a) => a[1],
}
}
pub fn bottom(&self) -> f64 {
match self {
Margin::Uniform(v) => *v,
Margin::Trbl(a) => a[2],
}
}
pub fn left(&self) -> f64 {
match self {
Margin::Uniform(v) => *v,
Margin::Trbl(a) => a[3],
}
}
}
impl From<f64> for Margin {
fn from(v: f64) -> Self {
Margin::Uniform(v)
}
}
impl From<[f64; 4]> for Margin {
fn from(arr: [f64; 4]) -> Self {
Margin::Trbl(arr)
}
}
#[derive(Debug, Clone, Default)]
pub struct PositionProps {
pub x: Option<Coord>,
pub y: Option<Coord>,
pub w: Option<Coord>,
pub h: Option<Coord>,
}
#[derive(Debug, Clone)]
pub struct PresLayout {
pub name: String,
pub width: i64,
pub height: i64,
}
impl PresLayout {
pub fn layout_16x9() -> Self {
PresLayout { name: "screen16x9".to_string(), width: 9_144_000, height: 5_143_500 }
}
pub fn layout_4x3() -> Self {
PresLayout { name: "screen4x3".to_string(), width: 9_144_000, height: 6_858_000 }
}
pub fn layout_16x10() -> Self {
PresLayout { name: "screen16x10".to_string(), width: 9_144_000, height: 5_715_000 }
}
pub fn layout_wide() -> Self {
PresLayout { name: "custom".to_string(), width: 12_192_000, height: 6_858_000 }
}
}
impl Default for PresLayout {
fn default() -> Self {
PresLayout::layout_16x9()
}
}
#[derive(Debug, Clone)]
pub struct BorderProps {
pub border_type: BorderType,
pub color: Option<String>,
pub pt: f64,
}
#[derive(Debug, Clone, PartialEq, Default)]
pub enum BorderType {
#[default]
Solid,
Dash,
None,
}
impl Default for BorderProps {
fn default() -> Self {
BorderProps { border_type: BorderType::Solid, color: Some("666666".to_string()), pt: 1.0 }
}
}
#[derive(Debug, Clone)]
pub struct ShadowProps {
pub shadow_type: ShadowType,
pub opacity: Option<f64>,
pub blur: Option<f64>,
pub offset: Option<f64>,
pub angle: Option<f64>,
pub color: Option<String>,
pub rotate_with_shape: bool,
}
#[derive(Debug, Clone, PartialEq)]
pub enum ShadowType {
Outer,
Inner,
None,
}
impl Default for ShadowProps {
fn default() -> Self {
ShadowProps {
shadow_type: ShadowType::Outer,
blur: Some(3.0),
offset: Some(23000.0 / 12700.0),
angle: Some(90.0),
color: Some("000000".to_string()),
opacity: Some(0.35),
rotate_with_shape: true,
}
}
}
impl ShadowProps {
pub fn outer() -> Self {
ShadowProps::default()
}
pub fn inner() -> Self {
ShadowProps { shadow_type: ShadowType::Inner, ..ShadowProps::default() }
}
pub fn with_color(mut self, c: impl Into<String>) -> Self {
self.color = Some(c.into().trim_start_matches('#').to_uppercase());
self
}
pub fn with_blur(mut self, pt: f64) -> Self {
self.blur = Some(pt);
self
}
pub fn with_offset(mut self, pt: f64) -> Self {
self.offset = Some(pt);
self
}
pub fn with_angle(mut self, deg: f64) -> Self {
self.angle = Some(deg);
self
}
pub fn with_opacity(mut self, v: f64) -> Self {
self.opacity = Some(v);
self
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum BevelPreset {
Circle,
RelaxedInset,
Angle,
SoftRound,
Convex,
Slope,
Divot,
Riblet,
HardEdge,
ArtDeco,
Cross,
CoolSlant,
}
impl BevelPreset {
pub fn as_str(&self) -> &'static str {
match self {
BevelPreset::Circle => "circle",
BevelPreset::RelaxedInset => "relaxedInset",
BevelPreset::Angle => "angle",
BevelPreset::SoftRound => "softRound",
BevelPreset::Convex => "convex",
BevelPreset::Slope => "slope",
BevelPreset::Divot => "divot",
BevelPreset::Riblet => "riblet",
BevelPreset::HardEdge => "hardEdge",
BevelPreset::ArtDeco => "artDeco",
BevelPreset::Cross => "cross",
BevelPreset::CoolSlant => "coolSlant",
}
}
}
#[derive(Debug, Clone)]
pub struct BevelProps {
pub preset: BevelPreset,
pub width: Option<i64>,
pub height: Option<i64>,
}
impl BevelProps {
pub fn new(preset: BevelPreset) -> Self {
BevelProps { preset, width: None, height: None }
}
pub fn with_size(mut self, w: i64, h: i64) -> Self {
self.width = Some(w);
self.height = Some(h);
self
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum MaterialPreset {
Matte,
WarmMatte,
Plastic,
Metal,
DarkEdge,
SoftEdge,
Flat,
SoftMetal,
Powder,
TranslucentPowder,
Clear,
}
impl MaterialPreset {
pub fn as_str(&self) -> &'static str {
match self {
MaterialPreset::Matte => "matte",
MaterialPreset::WarmMatte => "warmMatte",
MaterialPreset::Plastic => "plastic",
MaterialPreset::Metal => "metal",
MaterialPreset::DarkEdge => "dkEdge",
MaterialPreset::SoftEdge => "softEdge",
MaterialPreset::Flat => "flat",
MaterialPreset::SoftMetal => "softmetal",
MaterialPreset::Powder => "powder",
MaterialPreset::TranslucentPowder => "translucentPowder",
MaterialPreset::Clear => "clear",
}
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum CameraPreset {
OrthographicFront,
PerspectiveFront,
IsometricTopUp,
IsometricTopDown,
IsometricLeftDown,
IsometricRightUp,
ObliqueTopLeft,
ObliqueTop,
ObliqueTopRight,
}
impl CameraPreset {
pub fn as_str(&self) -> &'static str {
match self {
CameraPreset::OrthographicFront => "orthographicFront",
CameraPreset::PerspectiveFront => "perspectiveFront",
CameraPreset::IsometricTopUp => "isometricTopUp",
CameraPreset::IsometricTopDown => "isometricTopDown",
CameraPreset::IsometricLeftDown => "isometricLeftDown",
CameraPreset::IsometricRightUp => "isometricRightUp",
CameraPreset::ObliqueTopLeft => "obliqueTopLeft",
CameraPreset::ObliqueTop => "obliqueTop",
CameraPreset::ObliqueTopRight => "obliqueTopRight",
}
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum LightRigType {
ThreePt,
Balanced,
Harsh,
Flood,
Flat,
Soft,
Morning,
Sunrise,
Sunset,
Chilly,
Freezing,
Glow,
BrightRoom,
TwoPt,
Contrasting,
}
impl LightRigType {
pub fn as_str(&self) -> &'static str {
match self {
LightRigType::ThreePt => "threePt",
LightRigType::Balanced => "balanced",
LightRigType::Harsh => "harsh",
LightRigType::Flood => "flood",
LightRigType::Flat => "flat",
LightRigType::Soft => "soft",
LightRigType::Morning => "morning",
LightRigType::Sunrise => "sunrise",
LightRigType::Sunset => "sunset",
LightRigType::Chilly => "chilly",
LightRigType::Freezing => "freezing",
LightRigType::Glow => "glow",
LightRigType::BrightRoom => "brightRoom",
LightRigType::TwoPt => "twoPt",
LightRigType::Contrasting => "contrasting",
}
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum LightDirection {
Top,
TopLeft,
TopRight,
Left,
Right,
Bottom,
BottomLeft,
BottomRight,
}
impl LightDirection {
pub fn as_str(&self) -> &'static str {
match self {
LightDirection::Top => "t",
LightDirection::TopLeft => "tl",
LightDirection::TopRight => "tr",
LightDirection::Left => "l",
LightDirection::Right => "r",
LightDirection::Bottom => "b",
LightDirection::BottomLeft => "bl",
LightDirection::BottomRight => "br",
}
}
}
#[derive(Debug, Clone, Copy)]
pub struct Rotation3D {
pub lat: i64,
pub lon: i64,
pub rev: i64,
}
impl Rotation3D {
pub fn from_degrees(lat: f64, lon: f64, rev: f64) -> Self {
Rotation3D {
lat: (lat * 60_000.0).round() as i64,
lon: (lon * 60_000.0).round() as i64,
rev: (rev * 60_000.0).round() as i64,
}
}
}
#[derive(Debug, Clone)]
pub struct Shape3DProps {
pub bevel_top: Option<BevelProps>,
pub bevel_bottom: Option<BevelProps>,
pub extrusion_height: Option<i64>,
pub contour_width: Option<i64>,
pub contour_color: Option<String>,
pub material: Option<MaterialPreset>,
}
impl Default for Shape3DProps {
fn default() -> Self {
Shape3DProps {
bevel_top: None, bevel_bottom: None,
extrusion_height: None, contour_width: None,
contour_color: None, material: None,
}
}
}
#[derive(Debug, Clone)]
pub struct Camera3D {
pub preset: CameraPreset,
pub fov: Option<i64>,
pub rotation: Option<Rotation3D>,
}
#[derive(Debug, Clone)]
pub struct LightRig3D {
pub rig_type: LightRigType,
pub direction: LightDirection,
pub rotation: Option<Rotation3D>,
}
#[derive(Debug, Clone)]
pub struct Scene3DProps {
pub camera: Camera3D,
pub light_rig: LightRig3D,
}
#[derive(Debug, Clone)]
pub struct GradientStop {
pub color: Color,
pub position: f64,
pub transparency: Option<f64>,
}
impl GradientStop {
pub fn new(color: impl Into<String>, position: f64) -> Self {
GradientStop { color: Color::Hex(color.into().trim_start_matches('#').to_uppercase()), position, transparency: None }
}
pub fn from_color(color: Color, position: f64) -> Self {
GradientStop { color, position, transparency: None }
}
pub fn with_transparency(mut self, t: f64) -> Self { self.transparency = Some(t); self }
}
#[derive(Debug, Clone, PartialEq, Default)]
pub enum GradientType {
#[default]
Linear,
Radial,
}
#[derive(Debug, Clone)]
pub struct GradientFill {
pub stops: Vec<GradientStop>,
pub angle: f64,
pub gradient_type: GradientType,
}
impl GradientFill {
pub fn two_color(angle: f64, from: impl Into<String>, to: impl Into<String>) -> Self {
GradientFill {
stops: vec![GradientStop::new(from, 0.0), GradientStop::new(to, 100.0)],
angle,
gradient_type: GradientType::Linear,
}
}
pub fn linear(angle: f64, stops: Vec<GradientStop>) -> Self {
GradientFill { stops, angle, gradient_type: GradientType::Linear }
}
pub fn radial(stops: Vec<GradientStop>) -> Self {
GradientFill { stops, angle: 0.0, gradient_type: GradientType::Radial }
}
pub fn radial_two_color(inner: impl Into<String>, outer: impl Into<String>) -> Self {
GradientFill::radial(vec![
GradientStop::new(inner, 0.0),
GradientStop::new(outer, 100.0),
])
}
}
#[derive(Debug, Clone, PartialEq)]
pub enum PatternType {
Cross,
DarkDnDiag,
DarkHorz,
DarkUpDiag,
DarkVert,
DnDiag,
DotDmnd,
DotGrid,
Horz,
HorzBrick,
LgCheck,
LgConfetti,
LgGrid,
LtDnDiag,
LtHorz,
LtUpDiag,
LtVert,
NarHorz,
NarVert,
OpenDmnd,
Pct5,
Pct10,
Pct20,
Pct25,
Pct30,
Pct40,
Pct50,
Pct60,
Pct70,
Pct75,
Pct80,
Pct90,
Shingle,
SmCheck,
SmConfetti,
SmGrid,
SolidDmnd,
Sphere,
Trellis,
UpDiag,
Vert,
Wave,
WdDnDiag,
WdUpDiag,
ZigZag,
}
impl PatternType {
pub fn as_str(&self) -> &'static str {
match self {
PatternType::Cross => "cross",
PatternType::DarkDnDiag => "darkDnDiag",
PatternType::DarkHorz => "darkHorz",
PatternType::DarkUpDiag => "darkUpDiag",
PatternType::DarkVert => "darkVert",
PatternType::DnDiag => "dnDiag",
PatternType::DotDmnd => "dotDmnd",
PatternType::DotGrid => "dotGrid",
PatternType::Horz => "horz",
PatternType::HorzBrick => "horzBrick",
PatternType::LgCheck => "lgCheck",
PatternType::LgConfetti => "lgConfetti",
PatternType::LgGrid => "lgGrid",
PatternType::LtDnDiag => "ltDnDiag",
PatternType::LtHorz => "ltHorz",
PatternType::LtUpDiag => "ltUpDiag",
PatternType::LtVert => "ltVert",
PatternType::NarHorz => "narHorz",
PatternType::NarVert => "narVert",
PatternType::OpenDmnd => "openDmnd",
PatternType::Pct5 => "pct5",
PatternType::Pct10 => "pct10",
PatternType::Pct20 => "pct20",
PatternType::Pct25 => "pct25",
PatternType::Pct30 => "pct30",
PatternType::Pct40 => "pct40",
PatternType::Pct50 => "pct50",
PatternType::Pct60 => "pct60",
PatternType::Pct70 => "pct70",
PatternType::Pct75 => "pct75",
PatternType::Pct80 => "pct80",
PatternType::Pct90 => "pct90",
PatternType::Shingle => "shingle",
PatternType::SmCheck => "smCheck",
PatternType::SmConfetti => "smConfetti",
PatternType::SmGrid => "smGrid",
PatternType::SolidDmnd => "solidDmnd",
PatternType::Sphere => "sphere",
PatternType::Trellis => "trellis",
PatternType::UpDiag => "upDiag",
PatternType::Vert => "vert",
PatternType::Wave => "wave",
PatternType::WdDnDiag => "wdDnDiag",
PatternType::WdUpDiag => "wdUpDiag",
PatternType::ZigZag => "zigZag",
}
}
}
#[derive(Debug, Clone)]
pub struct PatternFill {
pub pattern: PatternType,
pub fg_color: String,
pub bg_color: String,
}
#[derive(Debug, Clone)]
pub struct ShapeFillProps {
pub fill_type: FillType,
pub color: Option<Color>,
pub transparency: Option<f64>,
pub gradient: Option<GradientFill>,
pub pattern: Option<PatternFill>,
}
#[derive(Debug, Clone, PartialEq, Default)]
pub enum FillType {
#[default]
Solid,
Gradient,
Pattern,
None,
}
impl Default for ShapeFillProps {
fn default() -> Self {
ShapeFillProps { fill_type: FillType::Solid, color: None, transparency: None, gradient: None, pattern: None }
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum LineCap {
Flat,
Round,
Square,
}
impl LineCap {
pub fn as_str(&self) -> &'static str {
match self {
LineCap::Flat => "flat",
LineCap::Round => "rnd",
LineCap::Square => "sq",
}
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum LineJoin {
Round,
Bevel,
Miter,
}
#[derive(Debug, Clone, Default)]
pub struct ShapeLineProps {
pub color: Option<String>,
pub transparency: Option<f64>,
pub width: Option<f64>,
pub dash_type: Option<String>,
pub begin_arrow_type: Option<String>,
pub end_arrow_type: Option<String>,
pub cap: Option<LineCap>,
pub join: Option<LineJoin>,
}
#[derive(Debug, Clone, Default)]
pub struct SlideNumberProps {
pub x: Option<Coord>,
pub y: Option<Coord>,
pub w: Option<Coord>,
pub h: Option<Coord>,
pub font_face: Option<String>,
pub font_size: Option<f64>,
pub color: Option<String>,
pub bold: bool,
pub align: Option<String>,
pub valign: Option<String>,
pub margin: Option<Margin>,
}
#[derive(Debug, Clone, PartialEq)]
pub enum HyperlinkAction {
NextSlide,
PrevSlide,
FirstSlide,
LastSlide,
EndShow,
}
impl HyperlinkAction {
pub fn as_ppaction(&self) -> &'static str {
match self {
HyperlinkAction::NextSlide => "ppaction://hlinkshowjump?jump=nextslide",
HyperlinkAction::PrevSlide => "ppaction://hlinkshowjump?jump=previousslide",
HyperlinkAction::FirstSlide => "ppaction://hlinkshowjump?jump=firstslide",
HyperlinkAction::LastSlide => "ppaction://hlinkshowjump?jump=lastslide",
HyperlinkAction::EndShow => "ppaction://hlinkshowjump?jump=endshow",
}
}
}
#[derive(Debug, Clone, Default)]
pub struct HyperlinkProps {
pub r_id: u32,
pub slide: Option<u32>,
pub url: Option<String>,
pub tooltip: Option<String>,
pub action: Option<HyperlinkAction>,
}
impl HyperlinkProps {
pub fn url(url: impl Into<String>) -> Self {
HyperlinkProps { r_id: 0, slide: None, url: Some(url.into()), tooltip: None, action: None }
}
pub fn slide(slide_num: u32) -> Self {
HyperlinkProps { r_id: 0, slide: Some(slide_num), url: None, tooltip: None, action: None }
}
pub fn with_tooltip(mut self, tip: impl Into<String>) -> Self {
self.tooltip = Some(tip.into());
self
}
}
#[derive(Debug, Clone)]
pub struct GlowProps {
pub size: f64,
pub color: String,
pub opacity: f64,
}
impl GlowProps {
pub fn new(size: f64, color: impl Into<String>, opacity: f64) -> Self {
GlowProps { size, color: color.into().trim_start_matches('#').to_uppercase(), opacity }
}
}
#[derive(Debug, Clone)]
pub struct TextOutlineProps {
pub color: String,
pub size: f64,
}
#[derive(Debug, Clone, PartialEq)]
pub enum Direction {
Left,
Right,
Up,
Down,
}
#[derive(Debug, Clone, PartialEq)]
pub enum SplitOrientation {
Horizontal,
Vertical,
}
#[derive(Debug, Clone, PartialEq)]
pub enum CheckerboardDir {
Across,
Down,
}
#[derive(Debug, Clone, PartialEq)]
pub enum StripDir {
LeftDown,
LeftUp,
RightDown,
RightUp,
}
#[derive(Debug, Clone, PartialEq)]
pub enum ShapeVariant {
Box,
Circle,
Diamond,
Plus,
}
#[derive(Debug, Clone, Default)]
pub struct ImageColorAdjust {
pub brightness: Option<f64>,
pub contrast: Option<f64>,
pub grayscale: bool,
}
#[derive(Debug, Clone)]
pub enum FieldType {
SlideNumber,
DateTime,
Custom(String),
}
impl FieldType {
pub fn as_ooxml(&self) -> &str {
match self {
FieldType::SlideNumber => "slidenum",
FieldType::DateTime => "datetime1",
FieldType::Custom(s) => s.as_str(),
}
}
}
#[derive(Debug, Clone, PartialEq)]
pub enum TextTarget {
CharRange { st_idx: u32, end_idx: u32 },
ParaRange { st_idx: u32, end_idx: u32 },
}
#[derive(Debug, Clone, PartialEq, Default)]
pub enum AnimationTrigger {
#[default]
OnClick,
WithPrevious,
AfterPrevious,
}
#[derive(Debug, Clone)]
pub struct AnimationEffect {
pub effect: AnimationEffectType,
pub text_target: Option<TextTarget>,
pub click_group: Option<u32>,
pub trigger: AnimationTrigger,
pub delay_ms: Option<u32>,
}
#[derive(Debug, Clone, PartialEq)]
pub enum AnimationEffectType {
Appear,
FadeIn,
FlyIn(Direction),
WipeIn(Direction),
ZoomIn,
SplitIn(SplitOrientation),
BlindsIn(SplitOrientation),
CheckerboardIn(CheckerboardDir),
DissolveIn,
PeekIn(Direction),
RandomBarsIn(SplitOrientation),
ShapeIn(ShapeVariant),
StripsIn(StripDir),
WedgeIn,
WheelIn(u32),
ExpandIn,
SwivelIn,
BasicZoomIn,
CentreRevolveIn,
FloatIn(Direction),
GrowTurnIn,
RiseUpIn,
SpinnerIn,
StretchIn(Direction),
BoomerangIn,
BounceIn,
CreditsIn,
CurveUpIn,
DropIn,
FlipIn,
PinwheelIn,
SpiralIn,
BasicSwivelIn,
WhipIn,
Disappear,
FadeOut,
FlyOut(Direction),
WipeOut(Direction),
ZoomOut,
SplitOut(SplitOrientation),
BlindsOut(SplitOrientation),
CheckerboardOut(CheckerboardDir),
DissolveOut,
PeekOut(Direction),
RandomBarsOut(SplitOrientation),
ShapeOut(ShapeVariant),
StripsOut(StripDir),
WedgeOut,
WheelOut(u32),
ContractOut,
SwivelOut,
CentreRevolveOut,
CollapseOut,
FloatOut(Direction),
ShrinkTurnOut,
SinkDownOut,
SpinnerOut,
BasicZoomOut,
StretchyOut(Direction),
BoomerangOut,
BounceOut,
CreditsOut,
CurveDownOut,
DropOut,
FlipOut,
PinwheelOut,
SpiralOut,
BasicSwivelOut,
WhipOut,
Spin(f32),
Pulse,
GrowShrink(f32),
FillColor(String),
FontColor(String),
LineColor(String),
Transparency(f32),
BoldFlash,
BrushColor(String),
ComplementaryColor,
ComplementaryColor2,
ContrastingColor,
Darken,
Desaturate,
Lighten,
ObjectColor(String),
Underline,
ColorPulse(String),
GrowWithColor(String),
Shimmer,
Teeter,
Blink,
BoldReveal,
Wave,
}
impl AnimationEffect {
fn new(effect: AnimationEffectType) -> Self {
Self { effect, text_target: None, click_group: None, trigger: AnimationTrigger::OnClick, delay_ms: None }
}
pub fn with_group(mut self, group: u32) -> Self {
self.click_group = Some(group);
self
}
pub fn with_previous(mut self) -> Self {
self.trigger = AnimationTrigger::WithPrevious;
self
}
pub fn after_previous(mut self) -> Self {
self.trigger = AnimationTrigger::AfterPrevious;
self
}
pub fn delay(mut self, ms: u32) -> Self {
self.delay_ms = Some(ms);
self
}
pub fn with_char_range(mut self, st_idx: u32, end_idx: u32) -> Self {
self.text_target = Some(TextTarget::CharRange { st_idx, end_idx });
self
}
pub fn with_para_range(mut self, st_idx: u32, end_idx: u32) -> Self {
self.text_target = Some(TextTarget::ParaRange { st_idx, end_idx });
self
}
pub fn appear() -> Self { Self::new(AnimationEffectType::Appear) }
pub fn fade_in() -> Self { Self::new(AnimationEffectType::FadeIn) }
pub fn fly_in(dir: Direction) -> Self { Self::new(AnimationEffectType::FlyIn(dir)) }
pub fn wipe_in(dir: Direction) -> Self { Self::new(AnimationEffectType::WipeIn(dir)) }
pub fn zoom_in() -> Self { Self::new(AnimationEffectType::ZoomIn) }
pub fn split_in(o: SplitOrientation) -> Self { Self::new(AnimationEffectType::SplitIn(o)) }
pub fn blinds_in(o: SplitOrientation) -> Self { Self::new(AnimationEffectType::BlindsIn(o)) }
pub fn checkerboard_in(d: CheckerboardDir) -> Self { Self::new(AnimationEffectType::CheckerboardIn(d)) }
pub fn dissolve_in() -> Self { Self::new(AnimationEffectType::DissolveIn) }
pub fn peek_in(dir: Direction) -> Self { Self::new(AnimationEffectType::PeekIn(dir)) }
pub fn random_bars_in(o: SplitOrientation) -> Self { Self::new(AnimationEffectType::RandomBarsIn(o)) }
pub fn shape_in(v: ShapeVariant) -> Self { Self::new(AnimationEffectType::ShapeIn(v)) }
pub fn strips_in(d: StripDir) -> Self { Self::new(AnimationEffectType::StripsIn(d)) }
pub fn wedge_in() -> Self { Self::new(AnimationEffectType::WedgeIn) }
pub fn wheel_in(spokes: u32) -> Self { Self::new(AnimationEffectType::WheelIn(spokes)) }
pub fn expand_in() -> Self { Self::new(AnimationEffectType::ExpandIn) }
pub fn swivel_in() -> Self { Self::new(AnimationEffectType::SwivelIn) }
pub fn basic_zoom_in() -> Self { Self::new(AnimationEffectType::BasicZoomIn) }
pub fn centre_revolve_in() -> Self { Self::new(AnimationEffectType::CentreRevolveIn) }
pub fn float_in(dir: Direction) -> Self { Self::new(AnimationEffectType::FloatIn(dir)) }
pub fn grow_turn_in() -> Self { Self::new(AnimationEffectType::GrowTurnIn) }
pub fn rise_up_in() -> Self { Self::new(AnimationEffectType::RiseUpIn) }
pub fn spinner_in() -> Self { Self::new(AnimationEffectType::SpinnerIn) }
pub fn stretch_in(dir: Direction) -> Self { Self::new(AnimationEffectType::StretchIn(dir)) }
pub fn boomerang_in() -> Self { Self::new(AnimationEffectType::BoomerangIn) }
pub fn bounce_in() -> Self { Self::new(AnimationEffectType::BounceIn) }
pub fn credits_in() -> Self { Self::new(AnimationEffectType::CreditsIn) }
pub fn curve_up_in() -> Self { Self::new(AnimationEffectType::CurveUpIn) }
pub fn drop_in() -> Self { Self::new(AnimationEffectType::DropIn) }
pub fn flip_in() -> Self { Self::new(AnimationEffectType::FlipIn) }
pub fn pinwheel_in() -> Self { Self::new(AnimationEffectType::PinwheelIn) }
pub fn spiral_in() -> Self { Self::new(AnimationEffectType::SpiralIn) }
pub fn basic_swivel_in() -> Self { Self::new(AnimationEffectType::BasicSwivelIn) }
pub fn whip_in() -> Self { Self::new(AnimationEffectType::WhipIn) }
pub fn disappear() -> Self { Self::new(AnimationEffectType::Disappear) }
pub fn fade_out() -> Self { Self::new(AnimationEffectType::FadeOut) }
pub fn fly_out(dir: Direction) -> Self { Self::new(AnimationEffectType::FlyOut(dir)) }
pub fn wipe_out(dir: Direction) -> Self { Self::new(AnimationEffectType::WipeOut(dir)) }
pub fn zoom_out() -> Self { Self::new(AnimationEffectType::ZoomOut) }
pub fn split_out(o: SplitOrientation) -> Self { Self::new(AnimationEffectType::SplitOut(o)) }
pub fn blinds_out(o: SplitOrientation) -> Self { Self::new(AnimationEffectType::BlindsOut(o)) }
pub fn checkerboard_out(d: CheckerboardDir) -> Self { Self::new(AnimationEffectType::CheckerboardOut(d)) }
pub fn dissolve_out() -> Self { Self::new(AnimationEffectType::DissolveOut) }
pub fn peek_out(dir: Direction) -> Self { Self::new(AnimationEffectType::PeekOut(dir)) }
pub fn random_bars_out(o: SplitOrientation) -> Self { Self::new(AnimationEffectType::RandomBarsOut(o)) }
pub fn shape_out(v: ShapeVariant) -> Self { Self::new(AnimationEffectType::ShapeOut(v)) }
pub fn strips_out(d: StripDir) -> Self { Self::new(AnimationEffectType::StripsOut(d)) }
pub fn wedge_out() -> Self { Self::new(AnimationEffectType::WedgeOut) }
pub fn wheel_out(spokes: u32) -> Self { Self::new(AnimationEffectType::WheelOut(spokes)) }
pub fn contract_out() -> Self { Self::new(AnimationEffectType::ContractOut) }
pub fn swivel_out() -> Self { Self::new(AnimationEffectType::SwivelOut) }
pub fn centre_revolve_out() -> Self { Self::new(AnimationEffectType::CentreRevolveOut) }
pub fn collapse_out() -> Self { Self::new(AnimationEffectType::CollapseOut) }
pub fn float_out(dir: Direction) -> Self { Self::new(AnimationEffectType::FloatOut(dir)) }
pub fn shrink_turn_out() -> Self { Self::new(AnimationEffectType::ShrinkTurnOut) }
pub fn sink_down_out() -> Self { Self::new(AnimationEffectType::SinkDownOut) }
pub fn spinner_out() -> Self { Self::new(AnimationEffectType::SpinnerOut) }
pub fn basic_zoom_out() -> Self { Self::new(AnimationEffectType::BasicZoomOut) }
pub fn stretchy_out(dir: Direction) -> Self { Self::new(AnimationEffectType::StretchyOut(dir)) }
pub fn boomerang_out() -> Self { Self::new(AnimationEffectType::BoomerangOut) }
pub fn bounce_out() -> Self { Self::new(AnimationEffectType::BounceOut) }
pub fn credits_out() -> Self { Self::new(AnimationEffectType::CreditsOut) }
pub fn curve_down_out() -> Self { Self::new(AnimationEffectType::CurveDownOut) }
pub fn drop_out() -> Self { Self::new(AnimationEffectType::DropOut) }
pub fn flip_out() -> Self { Self::new(AnimationEffectType::FlipOut) }
pub fn pinwheel_out() -> Self { Self::new(AnimationEffectType::PinwheelOut) }
pub fn spiral_out() -> Self { Self::new(AnimationEffectType::SpiralOut) }
pub fn basic_swivel_out() -> Self { Self::new(AnimationEffectType::BasicSwivelOut) }
pub fn whip_out() -> Self { Self::new(AnimationEffectType::WhipOut) }
pub fn spin(degrees: f32) -> Self { Self::new(AnimationEffectType::Spin(degrees)) }
pub fn pulse() -> Self { Self::new(AnimationEffectType::Pulse) }
pub fn grow_shrink(scale: f32) -> Self { Self::new(AnimationEffectType::GrowShrink(scale)) }
pub fn fill_color(hex: &str) -> Self { Self::new(AnimationEffectType::FillColor(hex.trim_start_matches('#').to_uppercase())) }
pub fn font_color(hex: &str) -> Self { Self::new(AnimationEffectType::FontColor(hex.trim_start_matches('#').to_uppercase())) }
pub fn line_color(hex: &str) -> Self { Self::new(AnimationEffectType::LineColor(hex.trim_start_matches('#').to_uppercase())) }
pub fn transparency(level: f32) -> Self { Self::new(AnimationEffectType::Transparency(level)) }
pub fn bold_flash() -> Self { Self::new(AnimationEffectType::BoldFlash) }
pub fn brush_color(hex: &str) -> Self { Self::new(AnimationEffectType::BrushColor(hex.trim_start_matches('#').to_uppercase())) }
pub fn complementary_color() -> Self { Self::new(AnimationEffectType::ComplementaryColor) }
pub fn complementary_color2() -> Self { Self::new(AnimationEffectType::ComplementaryColor2) }
pub fn contrasting_color() -> Self { Self::new(AnimationEffectType::ContrastingColor) }
pub fn darken() -> Self { Self::new(AnimationEffectType::Darken) }
pub fn desaturate() -> Self { Self::new(AnimationEffectType::Desaturate) }
pub fn lighten() -> Self { Self::new(AnimationEffectType::Lighten) }
pub fn object_color(hex: &str) -> Self { Self::new(AnimationEffectType::ObjectColor(hex.trim_start_matches('#').to_uppercase())) }
pub fn underline() -> Self { Self::new(AnimationEffectType::Underline) }
pub fn color_pulse(hex: &str) -> Self { Self::new(AnimationEffectType::ColorPulse(hex.trim_start_matches('#').to_uppercase())) }
pub fn grow_with_color(hex: &str) -> Self { Self::new(AnimationEffectType::GrowWithColor(hex.trim_start_matches('#').to_uppercase())) }
pub fn shimmer() -> Self { Self::new(AnimationEffectType::Shimmer) }
pub fn teeter() -> Self { Self::new(AnimationEffectType::Teeter) }
pub fn blink() -> Self { Self::new(AnimationEffectType::Blink) }
pub fn bold_reveal() -> Self { Self::new(AnimationEffectType::BoldReveal) }
pub fn wave() -> Self { Self::new(AnimationEffectType::Wave) }
}
#[derive(Debug, Clone, PartialEq, Default)]
pub enum TransitionType {
#[default]
None,
Cut,
Fade,
Push,
Wipe,
Split,
Cover,
Uncover,
Zoom,
Flash,
Morph,
Vortex,
Ripple,
Glitter,
Honeycomb,
Shred,
Switch,
Flip,
Pan,
Ferris,
Gallery,
Conveyor,
Doors,
Box,
Random,
RandomBar,
Circle,
Diamond,
Wheel,
Checker,
Blinds,
Strips,
Plus,
}
#[derive(Debug, Clone, PartialEq)]
pub enum TransitionDir {
Left,
Right,
Up,
Down,
LeftDown,
LeftUp,
RightDown,
RightUp,
}
impl TransitionDir {
pub fn as_str(&self) -> &'static str {
match self {
TransitionDir::Left => "l",
TransitionDir::Right => "r",
TransitionDir::Up => "u",
TransitionDir::Down => "d",
TransitionDir::LeftDown => "ld",
TransitionDir::LeftUp => "lu",
TransitionDir::RightDown => "rd",
TransitionDir::RightUp => "ru",
}
}
}
#[derive(Debug, Clone, PartialEq)]
pub enum TransitionSpeed {
Slow,
Medium,
Fast,
}
impl TransitionSpeed {
pub fn as_str(&self) -> &'static str {
match self {
TransitionSpeed::Slow => "slow",
TransitionSpeed::Medium => "med",
TransitionSpeed::Fast => "fast",
}
}
}
#[derive(Debug, Clone, Default)]
pub struct TransitionProps {
pub transition_type: TransitionType,
pub direction: Option<TransitionDir>,
pub speed: Option<TransitionSpeed>,
pub duration_ms: Option<u32>,
pub advance_after_ms: Option<u32>,
pub advance_on_click: bool,
}
impl TransitionProps {
pub fn new(t: TransitionType) -> Self {
TransitionProps { transition_type: t, advance_on_click: true, ..Default::default() }
}
pub fn fade() -> Self { Self::new(TransitionType::Fade) }
pub fn push(dir: TransitionDir) -> Self {
let mut p = Self::new(TransitionType::Push);
p.direction = Some(dir);
p
}
pub fn wipe(dir: TransitionDir) -> Self {
let mut p = Self::new(TransitionType::Wipe);
p.direction = Some(dir);
p
}
}