Skip to main content

AnimatedIcon

Enum AnimatedIcon 

Source
#[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
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

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

Source

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());
Source

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() },
);
Source

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(_)));
Source

pub fn frame_list(&self) -> Option<&FrameList>

Return the frame list (for Frames variant) or None (for Transform).

Source

pub fn frame_duration_ms(&self) -> Option<NonZeroU32>

Return the frame duration in milliseconds (for Frames variant) or None.

Source

pub fn icon(&self) -> Option<&IconData>

Return the icon data (for Transform variant) or None.

Source

pub fn animation(&self) -> Option<&TransformAnimation>

Return the transform animation (for Transform variant) or None.

Source

pub fn new_frames(frames: Vec<IconData>, frame_duration_ms: u32) -> Option<Self>

👎Deprecated since 0.5.7:

use AnimatedIcon::frames() which returns Result

Deprecated: Use AnimatedIcon::frames() instead.

Trait Implementations§

Source§

impl Clone for AnimatedIcon

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for AnimatedIcon

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for AnimatedIcon

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Eq for AnimatedIcon

Source§

impl PartialEq for AnimatedIcon

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for AnimatedIcon

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for AnimatedIcon

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more