Checkpoint

This commit is contained in:
Nathan Sobo 2023-10-02 15:43:03 -06:00
parent 77e67c19fe
commit 6046ed4f5c
7 changed files with 220 additions and 496 deletions

View file

@ -5,6 +5,7 @@ use crate::{
};
use anyhow::Result;
use futures::Future;
use smallvec::SmallVec;
use std::{any::TypeId, marker::PhantomData, mem, sync::Arc};
use util::ResultExt;
@ -18,6 +19,7 @@ pub struct Window {
layout_engine: TaffyLayoutEngine,
pub(crate) root_view: Option<AnyView<()>>,
mouse_position: Point<Pixels>,
z_index_stack: SmallVec<[u32; 8]>,
pub(crate) scene: Scene,
pub(crate) dirty: bool,
}
@ -56,6 +58,7 @@ impl Window {
layout_engine: TaffyLayoutEngine::new(),
root_view: None,
mouse_position,
z_index_stack: SmallVec::new(),
scene: Scene::new(scale_factor),
dirty: true,
}
@ -126,6 +129,13 @@ impl<'a, 'w> WindowContext<'a, 'w> {
&mut self.window.scene
}
pub fn with_z_index<R>(&mut self, z_index: u32, f: impl FnOnce(&mut Self) -> R) -> R {
self.window.z_index_stack.push(z_index);
let result = f(self);
self.window.z_index_stack.pop();
result
}
pub fn run_on_main<R>(
&self,
f: impl FnOnce(&mut MainThread<WindowContext>) -> R + Send + 'static,