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.
45use crate::bones::Bone;
6use crate::core::{Core, CoreContext, ObjectRef, OnAdded, Property};
7use crate::status_code::StatusCode;
8use crate::transform_component::TransformComponent;
910#[derive(Debug, Default)]
11pub struct RootBone {
12 bone: Bone,
13 x: Property<f32>,
14 y: Property<f32>,
15}
1617impl ObjectRef<'_, RootBone> {
18pub fn x(&self) -> f32 {
19self.x.get()
20 }
2122pub fn set_x(&self, x: f32) {
23if self.x() == x {
24return;
25 }
2627self.x.set(x);
28self.cast::<TransformComponent>().mark_transform_dirty();
29 }
3031pub fn y(&self) -> f32 {
32self.y.get()
33 }
3435pub fn set_y(&self, y: f32) {
36if self.y() == y {
37return;
38 }
3940self.y.set(y);
41self.cast::<TransformComponent>().mark_transform_dirty();
42 }
43}
4445impl Core for RootBone {
46parent_types![(bone, Bone)];
4748properties![(90, x, set_x), (91, y, set_y), bone];
49}
5051impl OnAdded for ObjectRef<'_, RootBone> {
52on_added!([on_added_dirty, import], Bone);
5354fn on_added_clean(&self, context: &dyn CoreContext) -> StatusCode {
55// Intentionally doesn't call Bone::on_added_clean and goes straight to
56 // the super.super TransformComponent as that assumes the parent must be a
57 // Bone while a root bone is a special case Bone that can be parented to
58 // other TransformComponents.
59self.cast::<TransformComponent>().on_added_clean(context)
60 }
61}