Introduce Shell type in iced_native

Widgets now can invalidate the current layout of the application on demand.
This commit is contained in:
Héctor Ramón Jiménez 2021-11-29 16:22:01 +07:00
parent f7792d89d6
commit bbd9355450
No known key found for this signature in database
GPG key ID: 140CC052C94F138E
26 changed files with 218 additions and 130 deletions

View file

@ -4,7 +4,7 @@ use crate::event::{self, Event};
use crate::layout;
use crate::mouse;
use crate::renderer;
use crate::{Clipboard, Hasher, Layout, Point, Rectangle, Size, Vector};
use crate::{Clipboard, Hasher, Layout, Point, Rectangle, Shell, Size, Vector};
/// A generic [`Overlay`].
#[allow(missing_debug_implementations)]
@ -62,7 +62,7 @@ where
cursor_position: Point,
renderer: &Renderer,
clipboard: &mut dyn Clipboard,
messages: &mut Vec<Message>,
shell: &mut Shell<'_, Message>,
) -> event::Status {
self.overlay.on_event(
event,
@ -70,7 +70,7 @@ where
cursor_position,
renderer,
clipboard,
messages,
shell,
)
}
@ -136,9 +136,10 @@ where
cursor_position: Point,
renderer: &Renderer,
clipboard: &mut dyn Clipboard,
messages: &mut Vec<B>,
shell: &mut Shell<'_, B>,
) -> event::Status {
let mut original_messages = Vec::new();
let mut local_messages = Vec::new();
let mut local_shell = Shell::new(&mut local_messages);
let event_status = self.content.on_event(
event,
@ -146,12 +147,10 @@ where
cursor_position,
renderer,
clipboard,
&mut original_messages,
&mut local_shell,
);
original_messages
.drain(..)
.for_each(|message| messages.push((self.mapper)(message)));
shell.merge(local_shell, self.mapper);
event_status
}