diff options
author | 2020-11-14 02:17:21 +0100 | |
---|---|---|
committer | 2020-11-14 02:17:21 +0100 | |
commit | 62295f554b885b8d486b666bc10dc4ecdc78c7d6 (patch) | |
tree | 4758f6f17301b1a6c252a5a32248ae5498d1bb11 /native/src/event.rs | |
parent | 73811c394a39c3816c67bffd2cf7d7a93c8803a9 (diff) | |
parent | bf2d2561b8dde3e160438428b59c03c38a5f752a (diff) | |
download | iced-62295f554b885b8d486b666bc10dc4ecdc78c7d6.tar.gz iced-62295f554b885b8d486b666bc10dc4ecdc78c7d6.tar.bz2 iced-62295f554b885b8d486b666bc10dc4ecdc78c7d6.zip |
Merge pull request #614 from hecrj/feature/event-capturing
Event capturing
Diffstat (limited to 'native/src/event.rs')
-rw-r--r-- | native/src/event.rs | 41 |
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, + } + } +} |