2020-11-11 23:54:59 +01:00
|
|
|
//! Handle events of a user interface.
|
2020-12-15 06:13:19 +01:00
|
|
|
use crate::keyboard;
|
|
|
|
|
use crate::mouse;
|
|
|
|
|
use crate::touch;
|
|
|
|
|
use crate::window;
|
2019-07-20 19:12:31 +02:00
|
|
|
|
|
|
|
|
/// A user interface event.
|
2019-09-05 09:59:38 +02:00
|
|
|
///
|
|
|
|
|
/// _**Note:** This type is largely incomplete! If you need to track
|
|
|
|
|
/// additional events, feel free to [open an issue] and share your use case!_
|
|
|
|
|
///
|
2021-12-23 09:34:37 +02:00
|
|
|
/// [open an issue]: https://github.com/iced-rs/iced/issues
|
2020-11-11 23:54:59 +01:00
|
|
|
#[derive(Debug, Clone, PartialEq)]
|
2019-07-20 19:12:31 +02:00
|
|
|
pub enum Event {
|
|
|
|
|
/// A keyboard event
|
|
|
|
|
Keyboard(keyboard::Event),
|
|
|
|
|
|
|
|
|
|
/// A mouse event
|
|
|
|
|
Mouse(mouse::Event),
|
2020-01-10 01:28:45 +01:00
|
|
|
|
|
|
|
|
/// A window event
|
2024-06-04 23:20:33 +02:00
|
|
|
Window(window::Event),
|
2019-11-11 20:29:58 -08:00
|
|
|
|
|
|
|
|
/// A touch event
|
2020-12-15 06:38:46 +01:00
|
|
|
Touch(touch::Event),
|
2019-07-20 19:12:31 +02:00
|
|
|
}
|
2020-11-11 23:54:59 +01:00
|
|
|
|
2020-11-12 00:09:52 +01:00
|
|
|
/// The status of an [`Event`] after being processed.
|
2020-11-11 23:54:59 +01:00
|
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
|
|
|
|
pub enum Status {
|
2020-11-12 00:19:12 +01:00
|
|
|
/// The [`Event`] was **NOT** handled by any widget.
|
2020-11-11 23:54:59 +01:00
|
|
|
Ignored,
|
|
|
|
|
|
2020-11-12 00:09:52 +01:00
|
|
|
/// The [`Event`] was handled and processed by a widget.
|
2020-11-11 23:54:59 +01:00
|
|
|
Captured,
|
|
|
|
|
}
|
2020-11-12 00:30:06 +01:00
|
|
|
|
|
|
|
|
impl Status {
|
|
|
|
|
/// Merges two [`Status`] into one.
|
|
|
|
|
///
|
|
|
|
|
/// `Captured` takes precedence over `Ignored`:
|
|
|
|
|
///
|
|
|
|
|
/// ```
|
2023-03-04 05:37:11 +01:00
|
|
|
/// use iced_core::event::Status;
|
2020-11-12 00:30:06 +01:00
|
|
|
///
|
|
|
|
|
/// assert_eq!(Status::Ignored.merge(Status::Ignored), Status::Ignored);
|
|
|
|
|
/// assert_eq!(Status::Ignored.merge(Status::Captured), Status::Captured);
|
|
|
|
|
/// assert_eq!(Status::Captured.merge(Status::Ignored), Status::Captured);
|
|
|
|
|
/// assert_eq!(Status::Captured.merge(Status::Captured), Status::Captured);
|
|
|
|
|
/// ```
|
|
|
|
|
pub fn merge(self, b: Self) -> Self {
|
|
|
|
|
match self {
|
|
|
|
|
Status::Ignored => b,
|
|
|
|
|
Status::Captured => Status::Captured,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|