aura_anim_iced/keyframes/
frame.rs1use crate::property::PropertySnapshot;
2
3#[cfg(test)]
4use crate::{prelude::RawPropertySpec, property::PropertyEntry};
5
6#[derive(Debug, Clone, PartialEq)]
8pub struct Keyframe {
9 offset: f32,
10 snapshot: PropertySnapshot,
11}
12
13impl Keyframe {
14 #[must_use]
16 pub fn new(offset: f32, mut snapshot: PropertySnapshot) -> Self {
17 snapshot.sort_by_composition_key();
18
19 Self {
20 offset: normalize_offset(offset),
21 snapshot,
22 }
23 }
24
25 #[must_use]
27 pub const fn offset(&self) -> f32 {
28 self.offset
29 }
30
31 #[must_use]
33 pub const fn snapshot(&self) -> &PropertySnapshot {
34 &self.snapshot
35 }
36
37 pub(crate) fn merge_snapshot(&mut self, snapshot: PropertySnapshot) {
38 self.snapshot.merge(snapshot);
39 }
40
41 #[cfg(test)]
42 pub(crate) fn find_property(&self, property: &RawPropertySpec) -> Option<&PropertyEntry> {
43 self.snapshot.find_property(property)
44 }
45}
46
47#[must_use]
49pub fn normalize_offset(offset: f32) -> f32 {
50 if offset.is_finite() {
51 offset.clamp(0.0, 1.0)
52 } else {
53 0.0
54 }
55}