Skip to main content

ferroui_xaml_interactivity/behaviors/
interactive_behavior_base.rs

1//! Port of `Behaviors/InteractiveBehaviorBase.cs`.
2
3use crate::{StyledElementBehaviorImpl, StyledElementBehaviorOfT};
4use ferroui_base::interactivity::{Interactive, RoutingStrategies};
5use ferroui_base::{ferro_class, ferro_properties, FerroObjectImpl, FerroProperty, StaticType, StyledElementImpl, StyledProperty};
6
7/// Base class for behaviors that listen for routed events (a behavior attached to an
8/// [`Interactive`]).
9#[repr(C)]
10pub struct InteractiveBehaviorBase {
11    base: StyledElementBehaviorOfT,
12}
13
14ferro_class!(InteractiveBehaviorBase: StyledElementBehaviorOfT);
15ferroui_base::ferro_impl_classes!(InteractiveBehaviorBase: FerroObjectImpl, StyledElementImpl, StyledElementBehaviorImpl);
16
17ferro_properties! {
18    impl InteractiveBehaviorBase {
19        /// Identifies the `RoutingStrategies` property.
20        pub fn routing_strategies_property() -> StyledProperty<RoutingStrategies> {
21            FerroProperty::register::<InteractiveBehaviorBase, _>("RoutingStrategies", RoutingStrategies::BUBBLE)
22        }
23    }
24}
25
26impl InteractiveBehaviorBase {
27    /// Creates the class data; see [`ferroui_base::FerroObject::construct`].
28    pub fn construct() -> Self {
29        Self { base: StyledElementBehaviorOfT::construct(<Interactive as StaticType>::TYPE) }
30    }
31
32    /// Gets or sets the routing strategies used when subscribing to events.
33    pub fn routing_strategies(&self) -> RoutingStrategies {
34        self.get_value(Self::routing_strategies_property())
35    }
36
37    pub fn set_routing_strategies(&self, value: RoutingStrategies) {
38        self.set_value(Self::routing_strategies_property(), value)
39    }
40}