Get GPUI compiling with some todos

This commit is contained in:
Nathan Sobo 2024-02-29 17:34:36 -07:00
parent 542fb5c89a
commit bdedeab7af
2 changed files with 29 additions and 18 deletions

View file

@ -1143,12 +1143,12 @@ impl<'a> WindowContext<'a> {
return;
};
let mut mouse_listeners = mem::take(&mut self.window.rendered_frame.mouse_listeners);
// Capture phase, events bubble from back to front. Handlers for this phase are used for
// special purposes, such as detecting events outside of a given Bounds.
for listener in &mut self.window.rendered_frame.mouse_listeners {
self.with_element_context(|cx| {
handler(event, DispatchPhase::Capture, cx);
});
for listener in &mut mouse_listeners {
listener.dispatch(event, DispatchPhase::Capture, &mouse_occlusion, self);
if !self.app.propagate_event {
break;
}
@ -1156,20 +1156,15 @@ impl<'a> WindowContext<'a> {
// Bubble phase, where most normal handlers do their work.
if self.app.propagate_event {
for (_, _, handler) in handlers.iter_mut().rev() {
self.with_element_context(|cx| {
handler(event, DispatchPhase::Bubble, cx);
});
for listener in mouse_listeners.iter_mut().rev() {
listener.dispatch(event, DispatchPhase::Bubble, &mouse_occlusion, self);
if !self.app.propagate_event {
break;
}
}
}
self.window
.rendered_frame
.mouse_listeners
.insert(event.type_id(), handlers);
self.window.rendered_frame.mouse_listeners = mouse_listeners;
if self.app.propagate_event && self.has_active_drag() {
if event.is::<MouseMoveEvent>() {

View file

@ -38,10 +38,26 @@ use crate::{
SUBPIXEL_VARIANTS,
};
struct MouseListener {
occlusion_id: OcclusionId,
invert_occlusion: bool,
callback: Box<dyn FnMut(&dyn Any, DispatchPhase, &mut ElementContext) + 'static>,
pub(crate) struct MouseListener {
pub(crate) occlusion_id: OcclusionId,
pub(crate) invert_occlusion: bool,
pub(crate) callback: Box<dyn FnMut(&dyn Any, DispatchPhase, &mut ElementContext) + 'static>,
}
impl MouseListener {
pub(crate) fn dispatch(
&mut self,
event: &dyn Any,
phase: DispatchPhase,
mouse_occlusion: &Occlusion,
cx: &mut WindowContext,
) {
if (self.occlusion_id == mouse_occlusion.id) != self.invert_occlusion {
cx.with_element_context(|cx| {
(self.callback)(event, phase, cx);
});
}
}
}
pub(crate) struct RequestedInputHandler {
@ -54,7 +70,7 @@ pub(crate) struct TooltipRequest {
pub(crate) tooltip: AnyTooltip,
}
struct CursorStyleRequest {
pub(crate) struct CursorStyleRequest {
pub(crate) occlusion_id: OcclusionId,
pub(crate) style: CursorStyle,
}
@ -64,7 +80,7 @@ pub(crate) struct OcclusionId(usize);
/// Identifies an occlusion, see [ElementContext::insert_occlusion] for more details.
#[derive(Clone, Deref)]
pub(crate) struct Occlusion {
pub struct Occlusion {
pub(crate) id: OcclusionId,
#[deref]
pub(crate) bounds: Bounds<Pixels>,