Checkpoint

This commit is contained in:
Nathan Sobo 2023-10-02 13:34:07 -06:00
parent 79e1e1a747
commit 66ef5549e9
6 changed files with 47 additions and 11 deletions

View file

@ -289,6 +289,18 @@ impl MainThread<AppContext> {
})
}
pub(crate) fn update_window<R>(
&mut self,
id: WindowId,
update: impl FnOnce(&mut WindowContext) -> R,
) -> Result<R> {
self.0.update_window(id, |cx| {
update(unsafe {
std::mem::transmute::<&mut WindowContext, &mut MainThread<WindowContext>>(cx)
})
})
}
pub(crate) fn platform(&self) -> &dyn Platform {
self.platform.borrow_on_main_thread()
}

View file

@ -21,6 +21,7 @@ pub use color::*;
pub use element::*;
pub use elements::*;
pub use executor::*;
use futures::Future;
pub use geometry::*;
pub use gpui3_macros::*;
pub use platform::*;

View file

@ -103,6 +103,8 @@ impl MetalRenderer {
}
pub fn draw(&mut self, scene: &Scene) {
dbg!(scene);
let layer = self.layer.clone();
let viewport_size = layer.drawable_size();
let viewport_size: Size<DevicePixels> = size(

View file

@ -1358,6 +1358,7 @@ extern "C" fn display_layer(this: &Object, _: Sel, _: id) {
let window_state = get_window_state(this);
let mut window_state = window_state.as_ref().lock();
if let Some(scene) = window_state.scene_to_render.take() {
dbg!("render", &scene);
window_state.renderer.draw(&scene);
}
}

View file

@ -4,7 +4,8 @@ use crate::{
StackContext, Style, TaffyLayoutEngine, WeakHandle, WindowOptions,
};
use anyhow::Result;
use std::{any::TypeId, marker::PhantomData, sync::Arc};
use futures::Future;
use std::{any::TypeId, marker::PhantomData, mem, sync::Arc};
use util::ResultExt;
pub struct AnyWindow {}
@ -125,6 +126,23 @@ impl<'a, 'w> WindowContext<'a, 'w> {
&mut self.window.scene
}
pub fn run_on_main<R>(
&self,
f: impl FnOnce(&mut MainThread<WindowContext>) -> R + Send + 'static,
) -> impl Future<Output = Result<R>>
where
R: Send + 'static,
{
let id = self.window.handle.id;
self.app.run_on_main(move |cx| {
cx.update_window(id, |cx| {
f(unsafe {
mem::transmute::<&mut WindowContext, &mut MainThread<WindowContext>>(cx)
})
})
})
}
pub(crate) fn draw(&mut self) -> Result<()> {
let unit_entity = self.unit_entity.clone();
self.update_entity(&unit_entity, |_, cx| {
@ -135,19 +153,19 @@ impl<'a, 'w> WindowContext<'a, 'w> {
.layout_engine
.compute_layout(root_layout_id, available_space)?;
let layout = cx.window.layout_engine.layout(root_layout_id)?;
dbg!(&layout.bounds);
root_view.paint(layout, &mut (), &mut frame_state, cx)?;
cx.window.root_view = Some(root_view);
let scene = cx.window.scene.take();
dbg!(&scene);
// // todo!
// self.run_on_main(|cx| {
// cx.window
// .platform_window
// .borrow_on_main_thread()
// .draw(scene);
// });
let _ = cx.run_on_main(|cx| {
cx.window
.platform_window
.borrow_on_main_thread()
.draw(scene);
});
cx.window.dirty = false;
Ok(())

View file

@ -27,7 +27,9 @@ impl Workspace {
fn render(&mut self, cx: &mut ViewContext<Self>) -> impl Element<State = Self> {
let theme = rose_pine_dawn();
div().fill(theme.middle.positive.default.background)
div()
.size_full()
.fill(theme.middle.positive.default.background)
// TODO: Implement style.
//.size_full().fill(gpui3::hsla(0.83, 1., 0.5, 1.))