iced_core/
event.rs

1//! Handle events of a user interface.
2use dnd::DndEvent;
3use dnd::DndSurface;
4
5use crate::keyboard;
6use crate::mouse;
7use crate::touch;
8use crate::window;
9#[cfg(feature = "wayland")]
10/// A platform specific event for wayland
11pub mod wayland;
12/// A user interface event.
13///
14/// _**Note:** This type is largely incomplete! If you need to track
15/// additional events, feel free to [open an issue] and share your use case!_
16///
17/// [open an issue]: https://github.com/iced-rs/iced/issues
18#[derive(Debug, Clone, PartialEq)]
19pub enum Event {
20    /// A keyboard event
21    Keyboard(keyboard::Event),
22
23    /// A mouse event
24    Mouse(mouse::Event),
25
26    /// A window event
27    Window(window::Event),
28
29    /// A touch event
30    Touch(touch::Event),
31
32    #[cfg(feature = "a11y")]
33    /// An Accesskit event for a specific Accesskit Node in an accessible widget
34    A11y(
35        crate::widget::Id,
36        iced_accessibility::accesskit::ActionRequest,
37    ),
38
39    /// A DnD event.
40    Dnd(DndEvent<DndSurface>),
41
42    /// Platform specific events
43    PlatformSpecific(PlatformSpecific),
44}
45
46/// A platform specific event
47#[derive(Debug, Clone, PartialEq)]
48pub enum PlatformSpecific {
49    #[cfg(feature = "wayland")]
50    /// A Wayland specific event
51    Wayland(wayland::Event),
52}
53
54/// The status of an [`Event`] after being processed.
55#[derive(Debug, Clone, Copy, PartialEq, Eq)]
56pub enum Status {
57    /// The [`Event`] was **NOT** handled by any widget.
58    Ignored,
59
60    /// The [`Event`] was handled and processed by a widget.
61    Captured,
62}
63
64impl Status {
65    /// Merges two [`Status`] into one.
66    ///
67    /// `Captured` takes precedence over `Ignored`:
68    ///
69    /// ```
70    /// use iced_core::event::Status;
71    ///
72    /// assert_eq!(Status::Ignored.merge(Status::Ignored), Status::Ignored);
73    /// assert_eq!(Status::Ignored.merge(Status::Captured), Status::Captured);
74    /// assert_eq!(Status::Captured.merge(Status::Ignored), Status::Captured);
75    /// assert_eq!(Status::Captured.merge(Status::Captured), Status::Captured);
76    /// ```
77    pub fn merge(self, b: Self) -> Self {
78        match self {
79            Status::Ignored => b,
80            Status::Captured => Status::Captured,
81        }
82    }
83}