ferroui_xaml_interactivity/events/contract/i_add_event_handler.rs
1//! Port of `Events/Contract/IAddEventHandler.cs`.
2
3use ferroui_base::reactive::IDisposable;
4use ferroui_base::BoxedValue;
5use std::rc::Rc;
6
7/// The handler an [`IAddEventHandler`] subscribes: it receives the sender (if the event has one)
8/// and the event args, untyped (`Action<object?, object>`).
9pub type AddEventHandlerCallback = Rc<dyn Fn(Option<&BoxedValue>, &BoxedValue)>;
10
11/// A service that provides a way to register event handlers for specific events on various
12/// controls.
13pub trait IAddEventHandler {
14 /// Checks if the given source object and event name match the criteria for this event
15 /// handler.
16 fn matches(&self, source: &BoxedValue, event_name: &str) -> bool;
17
18 /// Registers an event handler for a specific event on the given source object. Disposing the
19 /// returned handle removes it; `None` when the source or the event does not match.
20 fn add_handler(
21 &self,
22 source: &BoxedValue,
23 event_name: &str,
24 handler: AddEventHandlerCallback,
25 ) -> Option<Rc<dyn IDisposable>>;
26}