rive_rs/
node.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::core::{Core, ObjectRef, OnAdded, Property};
6use crate::transform_component::TransformComponent;
7
8#[derive(Debug, Default)]
9pub struct Node {
10    transform_component: TransformComponent,
11    x: Property<f32>,
12    y: Property<f32>,
13}
14
15impl ObjectRef<'_, Node> {
16    pub fn x(&self) -> f32 {
17        self.x.get()
18    }
19
20    pub fn set_x(&self, x: f32) {
21        if self.x() == x {
22            return;
23        }
24
25        self.x.set(x);
26        ObjectRef::from(&self.transform_component).mark_transform_dirty();
27    }
28
29    pub fn y(&self) -> f32 {
30        self.y.get()
31    }
32
33    pub fn set_y(&self, y: f32) {
34        if self.y() == y {
35            return;
36        }
37
38        self.y.set(y);
39        ObjectRef::from(&self.transform_component).mark_transform_dirty();
40    }
41}
42
43impl Core for Node {
44    parent_types![(transform_component, TransformComponent)];
45
46    properties![(13, x, set_x), (14, y, set_y), transform_component];
47}
48
49impl OnAdded for ObjectRef<'_, Node> {
50    on_added!(TransformComponent);
51}