Synthesize a mouse moved event in the previous position after painting a scene
This ensures that we correctly update the hover state of elements whose position has changed relative to the mouse cursor even though the mouse hasn't actually moved. Co-Authored-By: Antonio Scandurra <me@as-cii.com> Co-Authored-By: Max Brunsfeld <maxbrunsfeld@gmail.com>
This commit is contained in:
parent
b5463dcd1e
commit
1cb3fdbf7d
3 changed files with 41 additions and 36 deletions
|
@ -584,6 +584,11 @@ impl MutableAppContext {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) fn notify_view(&mut self, window_id: usize, view_id: usize) {
|
||||||
|
self.pending_effects
|
||||||
|
.push_back(Effect::ViewNotification { window_id, view_id });
|
||||||
|
}
|
||||||
|
|
||||||
pub fn dispatch_action<T: 'static + Any>(
|
pub fn dispatch_action<T: 'static + Any>(
|
||||||
&mut self,
|
&mut self,
|
||||||
window_id: usize,
|
window_id: usize,
|
||||||
|
@ -594,7 +599,7 @@ impl MutableAppContext {
|
||||||
self.dispatch_action_any(window_id, &responder_chain, name, Box::new(arg).as_ref());
|
self.dispatch_action_any(window_id, &responder_chain, name, Box::new(arg).as_ref());
|
||||||
}
|
}
|
||||||
|
|
||||||
fn dispatch_action_any(
|
pub(crate) fn dispatch_action_any(
|
||||||
&mut self,
|
&mut self,
|
||||||
window_id: usize,
|
window_id: usize,
|
||||||
path: &[usize],
|
path: &[usize],
|
||||||
|
@ -787,23 +792,7 @@ impl MutableAppContext {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let (actions, invalidated_views) =
|
presenter.borrow_mut().dispatch_event(event, ctx);
|
||||||
presenter.borrow_mut().dispatch_event(event, ctx.as_ref());
|
|
||||||
|
|
||||||
ctx.window_invalidations
|
|
||||||
.entry(window_id)
|
|
||||||
.or_default()
|
|
||||||
.updated
|
|
||||||
.extend(invalidated_views.into_iter());
|
|
||||||
|
|
||||||
for action in actions {
|
|
||||||
ctx.dispatch_action_any(
|
|
||||||
window_id,
|
|
||||||
&action.path,
|
|
||||||
action.name,
|
|
||||||
action.arg.as_ref(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
@ -924,11 +913,14 @@ impl MutableAppContext {
|
||||||
self.focus(window_id, view_id);
|
self.focus(window_id, view_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if self.pending_effects.is_empty() {
|
||||||
|
self.remove_dropped_entities();
|
||||||
|
self.update_windows();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
self.flushing_effects = false;
|
self.flushing_effects = false;
|
||||||
self.remove_dropped_entities();
|
|
||||||
self.update_windows();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1850,12 +1842,7 @@ impl<'a, T: View> ViewContext<'a, T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn notify(&mut self) {
|
pub fn notify(&mut self) {
|
||||||
self.app
|
self.app.notify_view(self.window_id, self.view_id);
|
||||||
.pending_effects
|
|
||||||
.push_back(Effect::ViewNotification {
|
|
||||||
window_id: self.window_id,
|
|
||||||
view_id: self.view_id,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn propagate_action(&mut self) {
|
pub fn propagate_action(&mut self) {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use crate::{geometry::vector::Vector2F, keymap::Keystroke};
|
use crate::{geometry::vector::Vector2F, keymap::Keystroke};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub enum Event {
|
pub enum Event {
|
||||||
KeyDown {
|
KeyDown {
|
||||||
keystroke: Keystroke,
|
keystroke: Keystroke,
|
||||||
|
|
|
@ -22,6 +22,7 @@ pub struct Presenter {
|
||||||
font_cache: Arc<FontCache>,
|
font_cache: Arc<FontCache>,
|
||||||
text_layout_cache: TextLayoutCache,
|
text_layout_cache: TextLayoutCache,
|
||||||
asset_cache: Arc<AssetCache>,
|
asset_cache: Arc<AssetCache>,
|
||||||
|
last_mouse_moved_event: Option<Event>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Presenter {
|
impl Presenter {
|
||||||
|
@ -39,6 +40,7 @@ impl Presenter {
|
||||||
font_cache,
|
font_cache,
|
||||||
text_layout_cache,
|
text_layout_cache,
|
||||||
asset_cache,
|
asset_cache,
|
||||||
|
last_mouse_moved_event: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,6 +86,10 @@ impl Presenter {
|
||||||
};
|
};
|
||||||
ctx.paint(root_view_id, Vector2F::zero());
|
ctx.paint(root_view_id, Vector2F::zero());
|
||||||
self.text_layout_cache.finish_frame();
|
self.text_layout_cache.finish_frame();
|
||||||
|
|
||||||
|
if let Some(event) = self.last_mouse_moved_event.clone() {
|
||||||
|
self.dispatch_event(event, app)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
log::error!("could not find root_view_id for window {}", self.window_id);
|
log::error!("could not find root_view_id for window {}", self.window_id);
|
||||||
}
|
}
|
||||||
|
@ -118,12 +124,12 @@ impl Presenter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn dispatch_event(
|
pub fn dispatch_event(&mut self, event: Event, app: &mut MutableAppContext) {
|
||||||
&mut self,
|
|
||||||
event: Event,
|
|
||||||
app: &AppContext,
|
|
||||||
) -> (Vec<ActionToDispatch>, HashSet<usize>) {
|
|
||||||
if let Some(root_view_id) = app.root_view_id(self.window_id) {
|
if let Some(root_view_id) = app.root_view_id(self.window_id) {
|
||||||
|
if matches!(event, Event::MouseMoved { .. }) {
|
||||||
|
self.last_mouse_moved_event = Some(event.clone());
|
||||||
|
}
|
||||||
|
|
||||||
let mut ctx = EventContext {
|
let mut ctx = EventContext {
|
||||||
rendered_views: &mut self.rendered_views,
|
rendered_views: &mut self.rendered_views,
|
||||||
actions: Default::default(),
|
actions: Default::default(),
|
||||||
|
@ -131,12 +137,24 @@ impl Presenter {
|
||||||
text_layout_cache: &self.text_layout_cache,
|
text_layout_cache: &self.text_layout_cache,
|
||||||
view_stack: Default::default(),
|
view_stack: Default::default(),
|
||||||
invalidated_views: Default::default(),
|
invalidated_views: Default::default(),
|
||||||
app,
|
app: app.as_ref(),
|
||||||
};
|
};
|
||||||
ctx.dispatch_event(root_view_id, &event);
|
ctx.dispatch_event(root_view_id, &event);
|
||||||
(ctx.actions, ctx.invalidated_views)
|
|
||||||
} else {
|
let invalidated_views = ctx.invalidated_views;
|
||||||
Default::default()
|
let actions = ctx.actions;
|
||||||
|
|
||||||
|
for view_id in invalidated_views {
|
||||||
|
app.notify_view(self.window_id, view_id);
|
||||||
|
}
|
||||||
|
for action in actions {
|
||||||
|
app.dispatch_action_any(
|
||||||
|
self.window_id,
|
||||||
|
&action.path,
|
||||||
|
action.name,
|
||||||
|
action.arg.as_ref(),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue