ferroui_xaml_interactivity/ferro_object/
trigger.rs1use crate::{ActionCollection, Behavior, BehaviorImpl, IBehavior, ITrigger};
4use ferroui_base::{ferro_class, ferro_class_info, ferro_properties, DirectProperty, FerroObject, FerroObjectImpl, FerroProperty, Ref};
5use std::cell::OnceCell;
6
7#[repr(C)]
12pub struct Trigger {
13 base: Behavior,
14 actions: OnceCell<ActionCollection>,
15}
16
17ferro_class!(Trigger: Behavior);
18ferro_class_info!(Trigger {
19 markup: {
20 content: Actions,
21 },
22});
23ferroui_base::ferro_impl_classes!(Trigger: FerroObjectImpl, BehaviorImpl);
24
25ferro_properties! {
26 impl Trigger {
27 pub fn actions_property() -> DirectProperty<Trigger, ActionCollection> {
29 FerroProperty::register_direct::<Trigger, _>("Actions", |t| t.actions(), None, ActionCollection::new())
30 }
31 }
32}
33
34impl Trigger {
35 fn static_constructor() {
37 <dyn ITrigger>::register::<Trigger>();
38 }
39
40 pub fn construct() -> Self {
42 Self { base: Behavior::construct(), actions: OnceCell::new() }
43 }
44
45 pub fn actions(&self) -> ActionCollection {
48 self.actions.get_or_init(ActionCollection::new).clone()
49 }
50}
51
52impl IBehavior for Trigger {
53 fn associated_object(&self) -> Option<Ref<FerroObject>> {
54 Behavior::associated_object(self)
55 }
56
57 fn attach(&self, associated_object: Option<Ref<FerroObject>>) {
58 Behavior::attach(self, associated_object)
59 }
60
61 fn detach(&self) {
62 Behavior::detach(self)
63 }
64}
65
66impl ITrigger for Trigger {
67 fn actions(&self) -> Option<ActionCollection> {
68 Some(Trigger::actions(self))
69 }
70}