Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

Checkpoint

Nathan Sobo66ef5549e9c0
diff --git a/crates/gpui3/src/app.rs b/crates/gpui3/src/app.rs
index d27fc6a3f6f..124cc55c3c0 100644
--- a/crates/gpui3/src/app.rs
+++ b/crates/gpui3/src/app.rs
@@ -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()
}
diff --git a/crates/gpui3/src/gpui3.rs b/crates/gpui3/src/gpui3.rs
index d62b42ed747..798e086dce3 100644
--- a/crates/gpui3/src/gpui3.rs
+++ b/crates/gpui3/src/gpui3.rs
@@ -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::*;
diff --git a/crates/gpui3/src/platform/mac/metal_renderer.rs b/crates/gpui3/src/platform/mac/metal_renderer.rs
index db7311a9e40..e19f130f96c 100644
--- a/crates/gpui3/src/platform/mac/metal_renderer.rs
+++ b/crates/gpui3/src/platform/mac/metal_renderer.rs
@@ -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(
diff --git a/crates/gpui3/src/platform/mac/window.rs b/crates/gpui3/src/platform/mac/window.rs
index 6e5dc8bed2d..5c0355ddacd 100644
--- a/crates/gpui3/src/platform/mac/window.rs
+++ b/crates/gpui3/src/platform/mac/window.rs
@@ -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);
}
}
diff --git a/crates/gpui3/src/window.rs b/crates/gpui3/src/window.rs
index ccbbb247d2f..49cb012fce1 100644
--- a/crates/gpui3/src/window.rs
+++ b/crates/gpui3/src/window.rs
@@ -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(())
diff --git a/crates/storybook2/src/workspace.rs b/crates/storybook2/src/workspace.rs
index 7190035f22f..6e1665fe187 100644
--- a/crates/storybook2/src/workspace.rs
+++ b/crates/storybook2/src/workspace.rs
@@ -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.))