Return true in the Window::on_event callback if event was handled
This commit is contained in:
@@ -1774,11 +1774,13 @@ impl MutableAppContext {
|
|||||||
presenter.borrow().dispatch_path(cx.as_ref()),
|
presenter.borrow().dispatch_path(cx.as_ref()),
|
||||||
keystroke,
|
keystroke,
|
||||||
) {
|
) {
|
||||||
return;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
presenter.borrow_mut().dispatch_event(event, cx);
|
presenter.borrow_mut().dispatch_event(event, cx)
|
||||||
|
} else {
|
||||||
|
false
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}));
|
}));
|
||||||
|
|||||||
@@ -90,7 +90,7 @@ pub trait Dispatcher: Send + Sync {
|
|||||||
|
|
||||||
pub trait Window: WindowContext {
|
pub trait Window: WindowContext {
|
||||||
fn as_any_mut(&mut self) -> &mut dyn Any;
|
fn as_any_mut(&mut self) -> &mut dyn Any;
|
||||||
fn on_event(&mut self, callback: Box<dyn FnMut(Event)>);
|
fn on_event(&mut self, callback: Box<dyn FnMut(Event) -> bool>);
|
||||||
fn on_active_status_change(&mut self, callback: Box<dyn FnMut(bool)>);
|
fn on_active_status_change(&mut self, callback: Box<dyn FnMut(bool)>);
|
||||||
fn on_resize(&mut self, callback: Box<dyn FnMut()>);
|
fn on_resize(&mut self, callback: Box<dyn FnMut()>);
|
||||||
fn on_close(&mut self, callback: Box<dyn FnOnce()>);
|
fn on_close(&mut self, callback: Box<dyn FnOnce()>);
|
||||||
|
|||||||
@@ -164,7 +164,7 @@ pub struct Window(Rc<RefCell<WindowState>>);
|
|||||||
struct WindowState {
|
struct WindowState {
|
||||||
id: usize,
|
id: usize,
|
||||||
native_window: id,
|
native_window: id,
|
||||||
event_callback: Option<Box<dyn FnMut(Event)>>,
|
event_callback: Option<Box<dyn FnMut(Event) -> bool>>,
|
||||||
activate_callback: Option<Box<dyn FnMut(bool)>>,
|
activate_callback: Option<Box<dyn FnMut(bool)>>,
|
||||||
resize_callback: Option<Box<dyn FnMut()>>,
|
resize_callback: Option<Box<dyn FnMut()>>,
|
||||||
close_callback: Option<Box<dyn FnOnce()>>,
|
close_callback: Option<Box<dyn FnOnce()>>,
|
||||||
@@ -331,7 +331,7 @@ impl platform::Window for Window {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_event(&mut self, callback: Box<dyn FnMut(Event)>) {
|
fn on_event(&mut self, callback: Box<dyn FnMut(Event) -> bool>) {
|
||||||
self.0.as_ref().borrow_mut().event_callback = Some(callback);
|
self.0.as_ref().borrow_mut().event_callback = Some(callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ pub struct Window {
|
|||||||
size: Vector2F,
|
size: Vector2F,
|
||||||
scale_factor: f32,
|
scale_factor: f32,
|
||||||
current_scene: Option<crate::Scene>,
|
current_scene: Option<crate::Scene>,
|
||||||
event_handlers: Vec<Box<dyn FnMut(super::Event)>>,
|
event_handlers: Vec<Box<dyn FnMut(super::Event) -> bool>>,
|
||||||
resize_handlers: Vec<Box<dyn FnMut()>>,
|
resize_handlers: Vec<Box<dyn FnMut()>>,
|
||||||
close_handlers: Vec<Box<dyn FnOnce()>>,
|
close_handlers: Vec<Box<dyn FnOnce()>>,
|
||||||
pub(crate) title: Option<String>,
|
pub(crate) title: Option<String>,
|
||||||
@@ -233,7 +233,7 @@ impl super::Window for Window {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_event(&mut self, callback: Box<dyn FnMut(crate::Event)>) {
|
fn on_event(&mut self, callback: Box<dyn FnMut(crate::Event) -> bool>) {
|
||||||
self.event_handlers.push(callback);
|
self.event_handlers.push(callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -224,7 +224,7 @@ impl Presenter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn dispatch_event(&mut self, event: Event, cx: &mut MutableAppContext) {
|
pub fn dispatch_event(&mut self, event: Event, cx: &mut MutableAppContext) -> bool {
|
||||||
if let Some(root_view_id) = cx.root_view_id(self.window_id) {
|
if let Some(root_view_id) = cx.root_view_id(self.window_id) {
|
||||||
let mut invalidated_views = Vec::new();
|
let mut invalidated_views = Vec::new();
|
||||||
let mut mouse_down_out_handlers = Vec::new();
|
let mut mouse_down_out_handlers = Vec::new();
|
||||||
@@ -366,7 +366,7 @@ impl Presenter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if !handled {
|
if !handled {
|
||||||
event_cx.dispatch_event(root_view_id, &event);
|
handled = event_cx.dispatch_event(root_view_id, &event);
|
||||||
}
|
}
|
||||||
|
|
||||||
invalidated_views.extend(event_cx.invalidated_views);
|
invalidated_views.extend(event_cx.invalidated_views);
|
||||||
@@ -384,6 +384,10 @@ impl Presenter {
|
|||||||
}
|
}
|
||||||
cx.dispatch_action_any(self.window_id, &dispatch_path, directive.action.as_ref());
|
cx.dispatch_action_any(self.window_id, &dispatch_path, directive.action.as_ref());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
handled
|
||||||
|
} else {
|
||||||
|
false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user