ferroui_reactiveui/binding/interfaces/i_activatable_view.rs
1//! `IActivatableView` (ReactiveUI.Binding, `Interfaces/IActivatableView.cs`).
2
3use super::IViewFor;
4use ferroui_system::component_model::INotifyPropertyChanged;
5use std::any::Any;
6use std::rc::Rc;
7
8/// The marker of a view that can be activated (`IActivatableView`); every
9/// [`IViewFor`] is one. Upstream declares no members.
10///
11/// It is `Any`, so that the code that activates a view (the activation fetchers) can find the
12/// concrete type of the view behind a `&dyn IActivatableView`.
13///
14/// Deviation (DEVIATIONS.md, ReactiveUI): upstream asks a view at run time whether it is an
15/// `IViewFor` and whether it raises `PropertyChanged` (`view is IViewFor`, `view is
16/// INotifyPropertyChanged`), which Rust cannot ask of a trait object. The two provided methods
17/// answer it; a view overrides them, and [`view_for!`](crate::view_for) writes them.
18pub trait IActivatableView: Any {
19 /// The view as an [`IViewFor`], when it is one (`view as IViewFor`); `None` by default.
20 fn as_view_for(&self) -> Option<&dyn IViewFor> {
21 None
22 }
23
24 /// The change notification of the view, when it raises `PropertyChanged`
25 /// (`view as INotifyPropertyChanged`); `None` by default. The property observation of the
26 /// view's `ViewModel` uses it.
27 fn as_notify_property_changed(self: Rc<Self>) -> Option<Rc<dyn INotifyPropertyChanged>> {
28 None
29 }
30
31 /// The view as an [`ICanActivate`](crate::ICanActivate), when it is one
32 /// (`view as ICanActivate`); `None` by default. `CanActivateViewFetcher` uses it.
33 fn as_can_activate(&self) -> Option<&dyn crate::ICanActivate> {
34 None
35 }
36}