moly_kit/utils/makepad/
events.rs

1use makepad_widgets::{Action, Event, WidgetAction, WidgetActionCast};
2
3pub trait EventExt {
4    /// Returns `&[Action]` (either the event's actions or an empty fallback).
5    fn actions(&self) -> &[Action];
6
7    /// Filtered iterator over widget actions.
8    fn widget_actions(&self) -> impl Iterator<Item = &WidgetAction>;
9}
10
11impl EventExt for Event {
12    fn actions(&self) -> &[Action] {
13        match self {
14            Event::Actions(actions) => actions.as_slice(),
15            _ => &[],
16        }
17    }
18
19    fn widget_actions(&self) -> impl Iterator<Item = &WidgetAction> {
20        self.actions()
21            .iter()
22            .filter_map(|action| action.as_widget_action())
23    }
24}