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; 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 // 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. // special purposes, such as detecting events outside of a given Bounds.
for listener in &mut self.window.rendered_frame.mouse_listeners { for listener in &mut mouse_listeners {
self.with_element_context(|cx| { listener.dispatch(event, DispatchPhase::Capture, &mouse_occlusion, self);
handler(event, DispatchPhase::Capture, cx);
});
if !self.app.propagate_event { if !self.app.propagate_event {
break; break;
} }
@ -1156,20 +1156,15 @@ impl<'a> WindowContext<'a> {
// Bubble phase, where most normal handlers do their work. // Bubble phase, where most normal handlers do their work.
if self.app.propagate_event { if self.app.propagate_event {
for (_, _, handler) in handlers.iter_mut().rev() { for listener in mouse_listeners.iter_mut().rev() {
self.with_element_context(|cx| { listener.dispatch(event, DispatchPhase::Bubble, &mouse_occlusion, self);
handler(event, DispatchPhase::Bubble, cx);
});
if !self.app.propagate_event { if !self.app.propagate_event {
break; break;
} }
} }
} }
self.window self.window.rendered_frame.mouse_listeners = mouse_listeners;
.rendered_frame
.mouse_listeners
.insert(event.type_id(), handlers);
if self.app.propagate_event && self.has_active_drag() { if self.app.propagate_event && self.has_active_drag() {
if event.is::<MouseMoveEvent>() { if event.is::<MouseMoveEvent>() {

View file

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