Dispatch keystrokes and fix rerendering when window invalidated

Co-Authored-By: Antonio Scandurra <me@as-cii.com>
This commit is contained in:
Nathan Sobo
2021-03-21 11:38:23 -06:00
co-authored by Antonio Scandurra
parent f5df3681f8
commit 046fe3fff9
9 changed files with 55 additions and 27 deletions
+16 -3
View File
@@ -11,6 +11,7 @@ use anyhow::{anyhow, Result};
use keymap::MatchResult;
use parking_lot::Mutex;
use pathfinder_geometry::{rect::RectF, vector::vec2f};
use platform::Event;
use smol::{channel, prelude::*};
use std::{
any::{type_name, Any, TypeId},
@@ -639,10 +640,22 @@ impl MutableAppContext {
{
let mut app = self.upgrade();
let presenter = presenter.clone();
window.on_event(Box::new(move |event, window| {
window.on_event(Box::new(move |event| {
log::info!("event {:?}", event);
app.update(|ctx| {
ctx.pending_flushes += 1;
if let Event::KeyDown { keystroke, .. } = &event {
if ctx
.dispatch_keystroke(
window_id,
presenter.borrow().dispatch_path(ctx.downgrade()),
keystroke,
)
.unwrap()
{
return;
}
}
let actions = presenter
.borrow_mut()
.dispatch_event(event, ctx.downgrade());
@@ -654,7 +667,6 @@ impl MutableAppContext {
action.arg.as_ref(),
);
}
ctx.flush_effects();
})
}));
}
@@ -675,6 +687,7 @@ impl MutableAppContext {
}
self.on_window_invalidated(window_id, move |invalidation, ctx| {
log::info!("window invalidated");
let mut presenter = presenter.borrow_mut();
presenter.invalidate(invalidation, ctx.downgrade());
let scene = presenter.build_scene(window.size(), window.scale_factor(), ctx);