ferroui_xaml_interactions_custom/icon/
set_path_icon_data_action.rs1use ferroui_base::data::core::ValueTypes;
4use ferroui_base::media::Geometry;
5use ferroui_base::{
6 ferro_class, ferro_class_info, ferro_properties, instantiate, BoxedValue, ElementRef, FerroObjectImpl,
7 FerroProperty, Nullable, Ref, StyledElementImpl, StyledProperty,
8};
9use ferroui_controls::PathIcon;
10use ferroui_xaml_interactivity::helpers::member_lookup::object_of;
11use ferroui_xaml_interactivity::{StyledElementAction, StyledElementActionImpl};
12use std::rc::Rc;
13
14#[repr(C)]
16pub struct SetPathIconDataAction {
17 base: StyledElementAction,
18}
19
20ferro_class!(SetPathIconDataAction: StyledElementAction);
21ferro_class_info!(SetPathIconDataAction {
22 new: SetPathIconDataAction::new,
23 markup: {
24 property_attributes: [
25 PathIcon: [ResolveByName],
26 ],
27 },
28});
29ferroui_base::ferro_impl_classes!(SetPathIconDataAction: FerroObjectImpl, StyledElementImpl);
30
31ferro_properties! {
32 impl SetPathIconDataAction {
33 pub fn data_property() -> StyledProperty<Option<Ref<Geometry>>> {
35 FerroProperty::register::<SetPathIconDataAction, _>("Data", None)
36 }
37
38 pub fn path_icon_property() -> StyledProperty<Option<ElementRef<PathIcon>>> {
43 ValueTypes::register_element_ref::<PathIcon>();
44 FerroProperty::register::<SetPathIconDataAction, _>("PathIcon", None)
45 }
46 }
47}
48
49impl StyledElementActionImpl for SetPathIconDataAction {
50 fn execute(this: &Self, sender: Option<&BoxedValue>, _parameter: Option<&BoxedValue>) -> Option<BoxedValue> {
51 if !this.is_enabled() {
52 return Some(Rc::new(false));
53 }
54
55 let target =
56 this.path_icon().or_else(|| sender.and_then(object_of).and_then(|sender| sender.cast::<PathIcon>()));
57 let Some(target) = target else {
58 return Some(Rc::new(false));
59 };
60
61 target.set_data(this.data());
62 Some(Rc::new(true))
63 }
64}
65
66impl SetPathIconDataAction {
67 pub fn construct() -> Self {
69 Self { base: StyledElementAction::construct() }
70 }
71
72 pub fn new() -> Ref<Self> {
74 instantiate(Self::construct())
75 }
76
77 pub fn data(&self) -> Option<Ref<Geometry>> {
79 self.get_value(Self::data_property())
80 }
81
82 pub fn set_data(&self, value: impl Into<Nullable<Geometry>>) {
83 self.set_value(Self::data_property(), value.into().0)
84 }
85
86 pub fn path_icon(&self) -> Option<Ref<PathIcon>> {
89 ElementRef::resolve(&self.get_value(Self::path_icon_property()))
90 }
91
92 pub fn set_path_icon(&self, value: impl Into<Nullable<PathIcon>>) {
93 self.set_value(Self::path_icon_property(), ElementRef::from_nullable(value.into().0))
94 }
95}