rive_rs/animation/
key_frame_id.rs

1// Copyright 2021 The Fuchsia Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5use crate::animation::KeyFrame;
6use crate::core::{Core, Object, ObjectRef, OnAdded, Property};
7
8use super::Animator;
9
10#[derive(Debug, Default)]
11pub struct KeyFrameId {
12    key_frame: KeyFrame,
13    value: Property<u64>,
14}
15
16impl ObjectRef<'_, KeyFrameId> {
17    pub fn value(&self) -> u64 {
18        self.value.get()
19    }
20
21    pub fn set_value(&self, value: u64) {
22        self.value.set(value);
23    }
24}
25
26impl ObjectRef<'_, KeyFrameId> {
27    pub fn apply(&self, core: Object, property_key: u64, _mix: f32) {
28        core.as_ref().animate(&core.as_ref(), property_key, &Animator::new(self.value()));
29    }
30
31    pub fn apply_interpolation(
32        &self,
33        core: Object,
34        property_key: u64,
35        _current_time: f32,
36        _next_frame: ObjectRef<'_, KeyFrame>,
37        _mix: f32,
38    ) {
39        core.as_ref().animate(&core.as_ref(), property_key, &Animator::new(self.value()));
40    }
41}
42
43impl Core for KeyFrameId {
44    parent_types![(key_frame, KeyFrame)];
45
46    properties![(122, value, set_value), key_frame];
47}
48
49impl OnAdded for ObjectRef<'_, KeyFrameId> {
50    on_added!(KeyFrame);
51}