Skip to main content

ferroui_controls/
path_icon.rs

1use crate::primitives::TemplatedControlImpl;
2use crate::{ControlImpl, IconElement};
3use ferroui_base::input::InputElementImpl;
4use ferroui_base::interactivity::InteractiveImpl;
5use ferroui_base::layout::LayoutableImpl;
6use ferroui_base::media::Geometry;
7use ferroui_base::{
8    ferro_class, ferro_impl_classes, ferro_property, instantiate, FerroObjectImpl, FerroProperty,
9    Nullable, Ref, StyledElementImpl, StyledProperty, Visual, VisualImpl,
10};
11
12/// Represents an icon that uses a vector path as its content.
13#[repr(C)]
14pub struct PathIcon {
15    base: IconElement,
16}
17
18ferro_class!(PathIcon: IconElement);
19ferroui_base::ferro_class_info!(PathIcon { new: PathIcon::new });
20ferro_impl_classes!(
21    PathIcon: StyledElementImpl,
22    VisualImpl,
23    LayoutableImpl,
24    InteractiveImpl,
25    InputElementImpl,
26    ControlImpl,
27    TemplatedControlImpl
28);
29
30ferroui_base::ferro_impl_classes!(PathIcon: FerroObjectImpl);
31
32ferroui_base::ferro_properties! { impl PathIcon {
33    ferro_property!(
34        /// Defines the `Data` property.
35        pub fn data_property() -> StyledProperty<Option<Ref<Geometry>>> {
36            FerroProperty::register::<PathIcon, _>("Data", None)
37        }
38    );
39} }
40
41impl PathIcon {
42    fn static_constructor() {
43        Visual::affects_render::<PathIcon>(&[Self::data_property().as_property()]);
44    }
45
46    /// Creates the class data; see [`ferroui_base::FerroObject::construct`].
47    pub fn construct() -> Self {
48        Self { base: IconElement::construct() }
49    }
50
51    pub fn new() -> Ref<Self> {
52        instantiate(Self::construct())
53    }
54
55    /// Gets the geometry drawn by the icon.
56    pub fn data(&self) -> Option<Ref<Geometry>> {
57        self.get_value(Self::data_property())
58    }
59
60    /// Sets the geometry drawn by the icon.
61    pub fn set_data(&self, value: impl Into<Nullable<Geometry>>) {
62        self.set_value(Self::data_property(), value.into().0)
63    }
64}