iced_core/
event.rs

1//! Handle events of a user interface.
2use crate::input_method;
3use crate::keyboard;
4use crate::mouse;
5use crate::touch;
6use crate::window;
7
8/// A user interface event.
9///
10/// _**Note:** This type is largely incomplete! If you need to track
11/// additional events, feel free to [open an issue] and share your use case!_
12///
13/// [open an issue]: https://github.com/iced-rs/iced/issues
14#[derive(Debug, Clone, PartialEq)]
15pub enum Event {
16    /// A keyboard event
17    Keyboard(keyboard::Event),
18
19    /// A mouse event
20    Mouse(mouse::Event),
21
22    /// A window event
23    Window(window::Event),
24
25    /// A touch event
26    Touch(touch::Event),
27
28    /// An input method event
29    InputMethod(input_method::Event),
30}
31
32/// The status of an [`Event`] after being processed.
33#[derive(Debug, Clone, Copy, PartialEq, Eq)]
34pub enum Status {
35    /// The [`Event`] was **NOT** handled by any widget.
36    Ignored,
37
38    /// The [`Event`] was handled and processed by a widget.
39    Captured,
40}
41
42impl Status {
43    /// Merges two [`Status`] into one.
44    ///
45    /// `Captured` takes precedence over `Ignored`:
46    ///
47    /// ```
48    /// use iced_core::event::Status;
49    ///
50    /// assert_eq!(Status::Ignored.merge(Status::Ignored), Status::Ignored);
51    /// assert_eq!(Status::Ignored.merge(Status::Captured), Status::Captured);
52    /// assert_eq!(Status::Captured.merge(Status::Ignored), Status::Captured);
53    /// assert_eq!(Status::Captured.merge(Status::Captured), Status::Captured);
54    /// ```
55    pub fn merge(self, b: Self) -> Self {
56        match self {
57            Status::Ignored => b,
58            Status::Captured => Status::Captured,
59        }
60    }
61}