summaryrefslogtreecommitdiffstats
path: root/native/src/event.rs
diff options
context:
space:
mode:
Diffstat (limited to 'native/src/event.rs')
-rw-r--r--native/src/event.rs41
1 files changed, 40 insertions, 1 deletions
diff --git a/native/src/event.rs b/native/src/event.rs
index 606a71d6..9c079151 100644
--- a/native/src/event.rs
+++ b/native/src/event.rs
@@ -1,3 +1,4 @@
+//! Handle events of a user interface.
use crate::{keyboard, mouse, window};
/// A user interface event.
@@ -6,7 +7,7 @@ use crate::{keyboard, mouse, window};
/// additional events, feel free to [open an issue] and share your use case!_
///
/// [open an issue]: https://github.com/hecrj/iced/issues
-#[derive(PartialEq, Clone, Debug)]
+#[derive(Debug, Clone, PartialEq)]
pub enum Event {
/// A keyboard event
Keyboard(keyboard::Event),
@@ -17,3 +18,41 @@ pub enum Event {
/// A window event
Window(window::Event),
}
+
+/// The status of an [`Event`] after being processed.
+///
+/// [`Event`]: enum.Event.html
+/// [`UserInterface`]: ../struct.UserInterface.html
+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
+pub enum Status {
+ /// The [`Event`] was **NOT** handled by any widget.
+ ///
+ /// [`Event`]: enum.Event.html
+ Ignored,
+
+ /// The [`Event`] was handled and processed by a widget.
+ ///
+ /// [`Event`]: enum.Event.html
+ Captured,
+}
+
+impl Status {
+ /// Merges two [`Status`] into one.
+ ///
+ /// `Captured` takes precedence over `Ignored`:
+ ///
+ /// ```
+ /// use iced_native::event::Status;
+ ///
+ /// 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,
+ }
+ }
+}