Checkpoint

This commit is contained in:
Antonio Scandurra 2023-09-26 11:34:41 -06:00
parent 04d3ea9563
commit bfe2205ecb
3 changed files with 21 additions and 15 deletions

View file

@ -97,7 +97,7 @@ impl AppContext {
let this = self.this.upgrade().unwrap(); let this = self.this.upgrade().unwrap();
self.platform.read(move |platform| { self.platform.read(move |platform| {
let cx = &mut *this.lock(); let cx = &mut *this.lock();
f(platform, cx) cx.update(|cx| f(platform, cx))
}) })
} }
@ -122,22 +122,24 @@ impl AppContext {
id: WindowId, id: WindowId,
update: impl FnOnce(&mut WindowContext) -> R, update: impl FnOnce(&mut WindowContext) -> R,
) -> Result<R> { ) -> Result<R> {
let mut window = self self.update(|cx| {
let mut window = cx
.windows .windows
.get_mut(id) .get_mut(id)
.ok_or_else(|| anyhow!("window not found"))? .ok_or_else(|| anyhow!("window not found"))?
.take() .take()
.unwrap(); .unwrap();
let result = update(&mut WindowContext::mutable(self, &mut window)); let result = update(&mut WindowContext::mutable(cx, &mut window));
window.dirty = true; window.dirty = true;
self.windows cx.windows
.get_mut(id) .get_mut(id)
.ok_or_else(|| anyhow!("window not found"))? .ok_or_else(|| anyhow!("window not found"))?
.replace(window); .replace(window);
Ok(result) Ok(result)
})
} }
fn update<R>(&mut self, update: impl FnOnce(&mut Self) -> R) -> R { fn update<R>(&mut self, update: impl FnOnce(&mut Self) -> R) -> R {

View file

@ -8,12 +8,13 @@ use collections::BTreeMap;
// Exported to metal // Exported to metal
pub type PointF = Point<f32>; pub type PointF = Point<f32>;
#[derive(Debug)]
pub struct Scene { pub struct Scene {
layers: BTreeMap<u32, SceneLayer>, layers: BTreeMap<u32, SceneLayer>,
pub(crate) scale_factor: f32, pub(crate) scale_factor: f32,
} }
#[derive(Default)] #[derive(Default, Debug)]
pub struct SceneLayer { pub struct SceneLayer {
pub quads: Vec<Quad>, pub quads: Vec<Quad>,
} }

View file

@ -39,7 +39,9 @@ impl Window {
let handle = handle; let handle = handle;
let cx = cx.to_async(); let cx = cx.to_async();
move |content_size, scale_factor| { move |content_size, scale_factor| {
dbg!("!!!!!!!!!!!!");
cx.update_window(handle, |cx| { cx.update_window(handle, |cx| {
dbg!("!!!!!!!!");
cx.window.scene = Scene::new(scale_factor); cx.window.scene = Scene::new(scale_factor);
cx.window.content_size = content_size; cx.window.content_size = content_size;
cx.window.dirty = true; cx.window.dirty = true;
@ -101,6 +103,7 @@ impl<'a, 'w> WindowContext<'a, 'w> {
root_view.paint(layout, &mut (), &mut frame_state, cx)?; root_view.paint(layout, &mut (), &mut frame_state, cx)?;
cx.window.root_view = Some(root_view); cx.window.root_view = Some(root_view);
let scene = cx.window.scene.take(); let scene = cx.window.scene.take();
dbg!(&scene);
let _ = cx.window.platform_window.read(|platform_window| { let _ = cx.window.platform_window.read(|platform_window| {
platform_window.draw(scene); platform_window.draw(scene);
future::ready(()) future::ready(())