Skip to main content

ferroui_xaml_behaviors/
lib.rs

1//! ferroui-xaml-behaviors
2//!
3//! The behaviors, triggers and actions of FerroUI in one crate, as the `Xaml.Behaviors` bundle of
4//! Xaml.Behaviors (see `NOTICE.md`) is one package: each crate of the port is a module of this one,
5//! behind a feature, and [`register_types`] registers all that are enabled.
6//!
7//! | Module | Crate | Feature |
8//! |---|---|---|
9//! | [`interactivity`] | `ferroui-xaml-interactivity` (the object model: `Interaction.Behaviors`, behaviors, triggers, actions) | always |
10//! | `animations` | `ferroui-xaml-behaviors-animations` | `animations` |
11//! | `interactions` | `ferroui-xaml-interactions` (event, data and timer triggers, property, method and command actions, clipboard, pickers) | `interactions` |
12//! | `custom` | `ferroui-xaml-interactions-custom` (about 330 behaviors for controls, input, focus, validation, windows, ...) | `custom` |
13//! | `events` | `ferroui-xaml-interactions-events` (a trigger and a behavior per input routed event) | `events` |
14//! | `draggable` | `ferroui-xaml-interactions-draggable` | `draggable` |
15//! | `drag_and_drop` | `ferroui-xaml-interactions-draganddrop` | `drag-and-drop` |
16//! | `responsive` | `ferroui-xaml-interactions-responsive` | `responsive` |
17//! | `reactiveui` | `ferroui-xaml-interactions-reactiveui` | `reactiveui` (off by default) |
18//!
19//! The default features are the crates of the reference's bundle; ReactiveUI is a package of its
20//! own there and a feature that is off here. All types are in the default XML namespace of the
21//! framework once [`register_types`] ran, so documents name them without a prefix.
22
23pub use ferroui_xaml_interactivity as interactivity;
24
25#[cfg(feature = "animations")]
26pub use ferroui_xaml_behaviors_animations as animations;
27#[cfg(feature = "custom")]
28pub use ferroui_xaml_interactions_custom as custom;
29#[cfg(feature = "drag-and-drop")]
30pub use ferroui_xaml_interactions_draganddrop as drag_and_drop;
31#[cfg(feature = "draggable")]
32pub use ferroui_xaml_interactions_draggable as draggable;
33#[cfg(feature = "events")]
34pub use ferroui_xaml_interactions_events as events;
35#[cfg(feature = "interactions")]
36pub use ferroui_xaml_interactions as interactions;
37#[cfg(feature = "reactiveui")]
38pub use ferroui_xaml_interactions_reactiveui as reactiveui;
39#[cfg(feature = "responsive")]
40pub use ferroui_xaml_interactions_responsive as responsive;
41
42/// Registers the types of every enabled behavior crate for markup (and of the crates they are built
43/// on). Cheap and idempotent; call it before loading or compiling documents that use behaviors.
44pub fn register_types() {
45    ferroui_xaml_interactivity::register_types();
46    #[cfg(feature = "animations")]
47    ferroui_xaml_behaviors_animations::register_types();
48    #[cfg(feature = "interactions")]
49    ferroui_xaml_interactions::register_types();
50    #[cfg(feature = "custom")]
51    ferroui_xaml_interactions_custom::register_types();
52    #[cfg(feature = "events")]
53    ferroui_xaml_interactions_events::register_types();
54    #[cfg(feature = "draggable")]
55    ferroui_xaml_interactions_draggable::register_types();
56    #[cfg(feature = "drag-and-drop")]
57    ferroui_xaml_interactions_draganddrop::register_types();
58    #[cfg(feature = "responsive")]
59    ferroui_xaml_interactions_responsive::register_types();
60    #[cfg(feature = "reactiveui")]
61    ferroui_xaml_interactions_reactiveui::register_types();
62}
63
64#[cfg(test)]
65mod tests {
66    // Not from the reference: the facade registers the types of its default crates.
67    use ferroui_base::TypeInfo;
68
69    #[test]
70    #[cfg(all(feature = "interactions", feature = "custom"))]
71    fn the_default_features_register_the_types_of_the_bundle() {
72        super::register_types();
73
74        assert!(TypeInfo::find("FerroUI.Xaml.Interactivity", "Interaction").is_some());
75        assert!(TypeInfo::find("FerroUI.Xaml.Interactions.Core", "EventTriggerBehavior").is_some());
76        assert!(TypeInfo::find("FerroUI.Xaml.Interactions.Custom", "AttachedToVisualTreeBehavior").is_some());
77    }
78}