diff options
author | 2024-10-25 19:28:18 +0200 | |
---|---|---|
committer | 2024-11-05 23:52:58 +0100 | |
commit | dcc184b01b753dbecb500205391f6eaaa21c8683 (patch) | |
tree | 9f1854261c3b3805e28f524df65487c09c9729f7 /core/src/shell.rs | |
parent | 752403d70c851ece620c4007710062b158e8dec3 (diff) | |
download | iced-dcc184b01b753dbecb500205391f6eaaa21c8683.tar.gz iced-dcc184b01b753dbecb500205391f6eaaa21c8683.tar.bz2 iced-dcc184b01b753dbecb500205391f6eaaa21c8683.zip |
Replace `event::Status` in `Widget::on_event` with `Shell::capture_event`
Diffstat (limited to 'core/src/shell.rs')
-rw-r--r-- | core/src/shell.rs | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/core/src/shell.rs b/core/src/shell.rs index 7a92a2be..12ebbaa8 100644 --- a/core/src/shell.rs +++ b/core/src/shell.rs @@ -1,3 +1,4 @@ +use crate::event; use crate::time::Instant; use crate::window; @@ -10,6 +11,7 @@ use crate::window; #[derive(Debug)] pub struct Shell<'a, Message> { messages: &'a mut Vec<Message>, + event_status: event::Status, redraw_request: Option<window::RedrawRequest>, is_layout_invalid: bool, are_widgets_invalid: bool, @@ -20,6 +22,7 @@ impl<'a, Message> Shell<'a, Message> { pub fn new(messages: &'a mut Vec<Message>) -> Self { Self { messages, + event_status: event::Status::Ignored, redraw_request: None, is_layout_invalid: false, are_widgets_invalid: false, @@ -36,6 +39,24 @@ impl<'a, Message> Shell<'a, Message> { self.messages.push(message); } + /// Marks the current event as captured. Prevents "event bubbling". + /// + /// A widget should capture an event when no ancestor should + /// handle it. + pub fn capture_event(&mut self) { + self.event_status = event::Status::Captured; + } + + /// Returns the current [`event::Status`] of the [`Shell`]. + pub fn event_status(&self) -> event::Status { + self.event_status + } + + /// Returns whether the current event has been captured. + pub fn is_event_captured(&self) -> bool { + self.event_status == event::Status::Captured + } + /// Requests a new frame to be drawn as soon as possible. pub fn request_redraw(&mut self) { self.redraw_request = Some(window::RedrawRequest::NextFrame); @@ -114,5 +135,7 @@ impl<'a, Message> Shell<'a, Message> { self.are_widgets_invalid = self.are_widgets_invalid || other.are_widgets_invalid; + + self.event_status = self.event_status.merge(other.event_status); } } |