Skip to main content

iced_core/
event.rs

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