rive_rs/shapes/
parametric_path.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::shapes::path::Path;
7
8#[derive(Debug)]
9pub struct ParametricPath {
10    path: Path,
11    width: Property<f32>,
12    height: Property<f32>,
13    origin_x: Property<f32>,
14    origin_y: Property<f32>,
15}
16
17impl ObjectRef<'_, ParametricPath> {
18    pub fn width(&self) -> f32 {
19        self.width.get()
20    }
21
22    pub fn set_width(&self, width: f32) {
23        if self.width() == width {
24            return;
25        }
26
27        self.width.set(width);
28        self.cast::<Path>().mark_path_dirty();
29    }
30
31    pub fn height(&self) -> f32 {
32        self.height.get()
33    }
34
35    pub fn set_height(&self, height: f32) {
36        if self.height() == height {
37            return;
38        }
39
40        self.height.set(height);
41        self.cast::<Path>().mark_path_dirty();
42    }
43
44    pub fn origin_x(&self) -> f32 {
45        self.origin_x.get()
46    }
47
48    pub fn set_origin_x(&self, origin_x: f32) {
49        self.origin_x.set(origin_x);
50    }
51
52    pub fn origin_y(&self) -> f32 {
53        self.origin_y.get()
54    }
55
56    pub fn set_origin_y(&self, origin_y: f32) {
57        self.origin_y.set(origin_y);
58    }
59}
60
61impl Core for ParametricPath {
62    parent_types![(path, Path)];
63
64    properties![
65        (20, width, set_width),
66        (21, height, set_height),
67        (123, origin_x, set_origin_x),
68        (124, origin_y, set_origin_y),
69        path,
70    ];
71}
72
73impl OnAdded for ObjectRef<'_, ParametricPath> {
74    on_added!(Path);
75}
76
77impl Default for ParametricPath {
78    fn default() -> Self {
79        Self {
80            path: Path::default(),
81            width: Property::new(0.0),
82            height: Property::new(0.0),
83            origin_x: Property::new(0.5),
84            origin_y: Property::new(0.5),
85        }
86    }
87}