Merge branch 'main' into picker
This commit is contained in:
@@ -24,12 +24,12 @@ macro_rules! actions {
|
||||
|
||||
( $name:ident ) => {
|
||||
#[derive(::std::clone::Clone, ::std::default::Default, ::std::fmt::Debug, ::std::cmp::PartialEq, $crate::serde::Deserialize)]
|
||||
struct $name;
|
||||
pub struct $name;
|
||||
};
|
||||
|
||||
( $name:ident { $($token:tt)* } ) => {
|
||||
#[derive(::std::clone::Clone, ::std::default::Default, ::std::fmt::Debug, ::std::cmp::PartialEq, $crate::serde::Deserialize)]
|
||||
struct $name { $($token)* }
|
||||
pub struct $name { $($token)* }
|
||||
};
|
||||
|
||||
( $name:ident, $($rest:tt)* ) => {
|
||||
|
||||
+12
-2
@@ -779,11 +779,21 @@ impl AppContext {
|
||||
(build)(params)
|
||||
}
|
||||
|
||||
/// Halt propagation of a mouse event, keyboard event, or action. This prevents listeners
|
||||
/// that have not yet been invoked from receiving the event.
|
||||
/// Event handlers propagate events by default. Call this method to stop dispatching to
|
||||
/// event handlers with a lower z-index (mouse) or higher in the tree (keyboard). This is
|
||||
/// the opposite of [propagate]. It's also possible to cancel a call to [propagate] by
|
||||
/// calling this method before effects are flushed.
|
||||
pub fn stop_propagation(&mut self) {
|
||||
self.propagate_event = false;
|
||||
}
|
||||
|
||||
/// Action handlers stop propagation by default during the bubble phase of action dispatch
|
||||
/// dispatching to action handlers higher in the element tree. This is the opposite of
|
||||
/// [stop_propagation]. It's also possible to cancel a call to [stop_propagate] by calling
|
||||
/// this method before effects are flushed.
|
||||
pub fn propagate(&mut self) {
|
||||
self.propagate_event = true;
|
||||
}
|
||||
}
|
||||
|
||||
impl Context for AppContext {
|
||||
|
||||
@@ -300,7 +300,8 @@ impl Window {
|
||||
|
||||
/// When constructing the element tree, we maintain a stack of key dispatch frames until we
|
||||
/// find the focused element. We interleave key listeners with dispatch contexts so we can use the
|
||||
/// contexts when matching key events against the keymap.
|
||||
/// contexts when matching key events against the keymap. A key listener can be either an action
|
||||
/// handler or a [KeyDown] / [KeyUp] event listener.
|
||||
enum KeyDispatchStackFrame {
|
||||
Listener {
|
||||
event_type: TypeId,
|
||||
@@ -1056,6 +1057,10 @@ impl<'a> WindowContext<'a> {
|
||||
|
||||
/// Dispatch a mouse or keyboard event on the window.
|
||||
pub fn dispatch_event(&mut self, event: InputEvent) -> bool {
|
||||
// Handlers may set this to false by calling `stop_propagation`
|
||||
self.app.propagate_event = true;
|
||||
self.window.default_prevented = false;
|
||||
|
||||
let event = match event {
|
||||
// Track the mouse position with our own state, since accessing the platform
|
||||
// API for the mouse position can only occur on the main thread.
|
||||
@@ -1109,10 +1114,6 @@ impl<'a> WindowContext<'a> {
|
||||
};
|
||||
|
||||
if let Some(any_mouse_event) = event.mouse_event() {
|
||||
// Handlers may set this to false by calling `stop_propagation`
|
||||
self.app.propagate_event = true;
|
||||
self.window.default_prevented = false;
|
||||
|
||||
if let Some(mut handlers) = self
|
||||
.window
|
||||
.mouse_listeners
|
||||
@@ -1322,6 +1323,7 @@ impl<'a> WindowContext<'a> {
|
||||
} = stack_frame
|
||||
{
|
||||
if action_type == *event_type {
|
||||
self.app.propagate_event = false;
|
||||
listener(action.as_any(), &[], DispatchPhase::Bubble, self);
|
||||
if !self.app.propagate_event {
|
||||
break;
|
||||
@@ -1336,6 +1338,7 @@ impl<'a> WindowContext<'a> {
|
||||
self.app.global_action_listeners.remove(&action_type)
|
||||
{
|
||||
for listener in global_listeners.iter().rev() {
|
||||
self.app.propagate_event = false;
|
||||
listener(action.as_ref(), DispatchPhase::Bubble, self);
|
||||
if !self.app.propagate_event {
|
||||
break;
|
||||
@@ -2043,9 +2046,9 @@ impl<V> Context for ViewContext<'_, V> {
|
||||
impl<V: 'static> VisualContext for ViewContext<'_, V> {
|
||||
fn build_view<W: 'static>(
|
||||
&mut self,
|
||||
build_view: impl FnOnce(&mut ViewContext<'_, W>) -> W,
|
||||
build_view_state: impl FnOnce(&mut ViewContext<'_, W>) -> W,
|
||||
) -> Self::Result<View<W>> {
|
||||
self.window_cx.build_view(build_view)
|
||||
self.window_cx.build_view(build_view_state)
|
||||
}
|
||||
|
||||
fn update_view<V2: 'static, R>(
|
||||
|
||||
Reference in New Issue
Block a user