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 /// A wake event, produced by a [`Waker`](crate::shell::Waker).
36 Waken,
37}
38
39/// The status of an [`Event`] after being processed.
40#[derive(Debug, Clone, Copy, PartialEq, Eq)]
41pub enum Status {
42 /// The [`Event`] was **NOT** handled by any widget.
43 Ignored,
44
45 /// The [`Event`] was handled and processed by a widget.
46 Captured,
47}
48
49impl Status {
50 /// Merges two [`Status`] into one.
51 ///
52 /// `Captured` takes precedence over `Ignored`:
53 ///
54 /// ```
55 /// use iced_core::event::Status;
56 ///
57 /// assert_eq!(Status::Ignored.merge(Status::Ignored), Status::Ignored);
58 /// assert_eq!(Status::Ignored.merge(Status::Captured), Status::Captured);
59 /// assert_eq!(Status::Captured.merge(Status::Ignored), Status::Captured);
60 /// assert_eq!(Status::Captured.merge(Status::Captured), Status::Captured);
61 /// ```
62 pub fn merge(self, b: Self) -> Self {
63 match self {
64 Status::Ignored => b,
65 Status::Captured => Status::Captured,
66 }
67 }
68}