vizia_core/animation/
animation_id.rs

1use vizia_id::{
2    impl_generational_id, GenerationalId, GENERATIONAL_ID_GENERATION_MASK,
3    GENERATIONAL_ID_INDEX_BITS, GENERATIONAL_ID_INDEX_MASK,
4};
5
6use crate::context::EventContext;
7
8/// An ID used to reference style animations stored in the style store.
9#[derive(Clone, Copy, PartialEq, Eq, Hash)]
10pub struct Animation(u64);
11
12impl_generational_id!(Animation);
13
14/// Trait for getting the animation id From an [Animation] or an animation name.
15pub trait AnimId {
16    /// Returns the animation associated with the id.
17    fn get(&self, cx: &EventContext) -> Option<Animation>;
18}
19
20impl AnimId for Animation {
21    fn get(&self, _cx: &EventContext) -> Option<Animation> {
22        Some(*self)
23    }
24}
25
26impl AnimId for &'static str {
27    fn get(&self, cx: &EventContext) -> Option<Animation> {
28        cx.style.get_animation(self).copied()
29    }
30}