#[non_exhaustive]pub enum AnimatedIcon {
Frames(FramesData),
Transform(TransformData),
}Expand description
An animated icon, either frame-based or transform-based.
Frames carries pre-rendered frames with uniform timing (loops infinitely).
Transform carries a single icon and a description of the motion.
Variant fields are private (via FramesData and TransformData wrapper
structs). Use the constructors AnimatedIcon::frames() and
AnimatedIcon::transform() to build instances, and accessor methods to
read fields.
§Examples
use native_theme::theme::{AnimatedIcon, IconData, TransformAnimation};
use std::borrow::Cow;
use std::num::NonZeroU32;
// Frame-based animation (e.g., sprite sheet)
let frames_anim = AnimatedIcon::frames(
vec![
IconData::Svg(Cow::Borrowed(b"<svg>frame1</svg>")),
IconData::Svg(Cow::Borrowed(b"<svg>frame2</svg>")),
],
NonZeroU32::new(83).unwrap(),
).expect("non-empty frames");
// Transform-based animation (e.g., spinning icon)
let spin_anim = AnimatedIcon::transform(
IconData::Svg(Cow::Borrowed(b"<svg>spinner</svg>")),
TransformAnimation::Spin { duration_ms: NonZeroU32::new(1000).unwrap() },
);
// Pattern matching uses tuple variants + accessor methods
match &frames_anim {
AnimatedIcon::Frames(data) => {
assert_eq!(data.frames().len(), 2);
assert_eq!(data.frame_duration_ms().get(), 83);
}
AnimatedIcon::Transform(data) => {
let _icon = data.icon();
let _animation = data.animation();
}
_ => {}
}
// first_frame() returns &IconData (infallible, not Option)
let first = frames_anim.first_frame();
assert!(matches!(first, IconData::Svg(_)));Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Frames(FramesData)
A sequence of pre-rendered frames played at a fixed interval (loops infinitely).
Transform(TransformData)
A single icon with a continuous transform animation.
Implementations§
Source§impl AnimatedIcon
impl AnimatedIcon
Sourcepub fn frames(
frames: Vec<IconData>,
frame_duration_ms: NonZeroU32,
) -> Result<Self, EmptyFrameListError>
pub fn frames( frames: Vec<IconData>, frame_duration_ms: NonZeroU32, ) -> Result<Self, EmptyFrameListError>
Create a frame-based animation.
Returns Err(EmptyFrameListError) if frames is empty.
frame_duration_ms uses NonZeroU32 so zero duration is prevented at the type level.
§Examples
use native_theme::theme::{AnimatedIcon, IconData};
use std::borrow::Cow;
use std::num::NonZeroU32;
let anim = AnimatedIcon::frames(
vec![IconData::Svg(Cow::Borrowed(b"<svg>f1</svg>"))],
NonZeroU32::new(83).unwrap(),
);
assert!(anim.is_ok());
// Empty frames returns Err:
let empty = AnimatedIcon::frames(vec![], NonZeroU32::new(83).unwrap());
assert!(empty.is_err());Sourcepub fn transform(icon: IconData, animation: TransformAnimation) -> Self
pub fn transform(icon: IconData, animation: TransformAnimation) -> Self
Create a transform-based animation.
§Examples
use native_theme::theme::{AnimatedIcon, IconData, TransformAnimation};
use std::borrow::Cow;
use std::num::NonZeroU32;
let anim = AnimatedIcon::transform(
IconData::Svg(Cow::Borrowed(b"<svg>spinner</svg>")),
TransformAnimation::Spin { duration_ms: NonZeroU32::new(1000).unwrap() },
);Sourcepub fn first_frame(&self) -> &IconData
pub fn first_frame(&self) -> &IconData
Return a reference to the first displayable frame (infallible).
For Frames, returns the first element (guaranteed to exist via FrameList).
For Transform, returns the underlying icon.
§Examples
use native_theme::theme::{AnimatedIcon, IconData, TransformAnimation};
use std::borrow::Cow;
use std::num::NonZeroU32;
let anim = AnimatedIcon::frames(
vec![IconData::Svg(Cow::Borrowed(b"<svg>f1</svg>"))],
NonZeroU32::new(83).unwrap(),
).unwrap();
let first: &IconData = anim.first_frame();
assert!(matches!(first, IconData::Svg(_)));
let spin = AnimatedIcon::transform(
IconData::Svg(Cow::Borrowed(b"<svg>spinner</svg>")),
TransformAnimation::Spin { duration_ms: NonZeroU32::new(1000).unwrap() },
);
let first: &IconData = spin.first_frame();
assert!(matches!(first, IconData::Svg(_)));Sourcepub fn frame_list(&self) -> Option<&FrameList>
pub fn frame_list(&self) -> Option<&FrameList>
Return the frame list (for Frames variant) or None (for Transform).
Sourcepub fn frame_duration_ms(&self) -> Option<NonZeroU32>
pub fn frame_duration_ms(&self) -> Option<NonZeroU32>
Return the frame duration in milliseconds (for Frames variant) or None.
Sourcepub fn animation(&self) -> Option<&TransformAnimation>
pub fn animation(&self) -> Option<&TransformAnimation>
Return the transform animation (for Transform variant) or None.
Sourcepub fn new_frames(frames: Vec<IconData>, frame_duration_ms: u32) -> Option<Self>
👎Deprecated since 0.5.7: use AnimatedIcon::frames() which returns Result
pub fn new_frames(frames: Vec<IconData>, frame_duration_ms: u32) -> Option<Self>
use AnimatedIcon::frames() which returns Result
Deprecated: Use AnimatedIcon::frames() instead.