Checkpoint: Compiling

This commit is contained in:
Marshall Bowers 2023-09-29 20:51:45 -04:00
parent 963f179d7f
commit 8cac89d17c
3 changed files with 39 additions and 39 deletions

View file

@ -137,40 +137,38 @@ impl<Thread> AppContext<Thread> {
AsyncContext(self.this.clone()) AsyncContext(self.this.clone())
} }
// pub fn run_on_main<R>( pub fn run_on_main<R>(
// &self, &self,
// f: impl FnOnce(&mut AppContext<MainThread>) -> R + Send + 'static, f: impl FnOnce(&mut AppContext<MainThread>) -> R + Send + 'static,
// ) -> impl Future<Output = R> ) -> impl Future<Output = R>
// where where
// R: Send + 'static, R: Send + 'static,
// { {
// let this = self.this.upgrade().unwrap(); let this = self.this.upgrade().unwrap();
// run_on_main(self.dispatcher.clone(), move || { run_on_main(self.dispatcher.clone(), move || {
// let cx = &mut *this.lock(); let cx = &mut *this.lock();
// let main_thread_cx: &mut AppContext<MainThread> = unsafe { std::mem::transmute(cx) }; let main_thread_cx =
// main_thread_cx.update(|cx| f(cx)) unsafe { std::mem::transmute::<&mut AppContext, &mut AppContext<MainThread>>(cx) };
// }) main_thread_cx.update(|cx| f(cx))
// } })
}
// pub fn spawn_on_main<F, R>( pub fn spawn_on_main<F, R>(
// &self, &self,
// f: impl FnOnce(&mut AppContext<MainThread>) -> F + Send + 'static, f: impl FnOnce(&mut AppContext<MainThread>) -> F + Send + 'static,
// ) -> impl Future<Output = R> ) -> impl Future<Output = R>
// where where
// F: Future<Output = R> + 'static, F: Future<Output = R> + 'static,
// R: Send + 'static, R: Send + 'static,
// { {
// let this = self.this.upgrade().unwrap(); let this = self.this.upgrade().unwrap();
// spawn_on_main(self.dispatcher.clone(), move || { spawn_on_main(self.dispatcher.clone(), move || {
// let cx = &mut *this.lock(); let cx = &mut *this.lock();
// let platform = cx.platform.borrow_on_main_thread().clone(); let main_thread_cx =
// // todo!() unsafe { std::mem::transmute::<&mut AppContext, &mut AppContext<MainThread>>(cx) };
// // cx.update(|cx| f(&mut MainThreadContext::mutable(cx, platform.as_ref()))) main_thread_cx.update(|cx| f(cx))
})
// future::ready(()) }
// })
// // self.platform.read(move |platform| {
// }
pub fn text_style(&self) -> TextStyle { pub fn text_style(&self) -> TextStyle {
let mut style = TextStyle::default(); let mut style = TextStyle::default();
@ -319,7 +317,7 @@ impl Context for AppContext {
} }
impl AppContext<MainThread> { impl AppContext<MainThread> {
fn platform(&self) -> &dyn Platform { pub(crate) fn platform(&self) -> &dyn Platform {
self.platform.borrow_on_main_thread() self.platform.borrow_on_main_thread()
} }
@ -334,7 +332,7 @@ impl AppContext<MainThread> {
) -> WindowHandle<S> { ) -> WindowHandle<S> {
let id = self.windows.insert(None); let id = self.windows.insert(None);
let handle = WindowHandle::new(id); let handle = WindowHandle::new(id);
let mut window = Window::new(handle.into(), options, self.platform(), self); let mut window = Window::new(handle.into(), options, self);
let root_view = build_root_view(&mut WindowContext::mutable(self, &mut window)); let root_view = build_root_view(&mut WindowContext::mutable(self, &mut window));
window.root_view.replace(root_view.into_any()); window.root_view.replace(root_view.into_any());
self.windows.get_mut(id).unwrap().replace(window); self.windows.get_mut(id).unwrap().replace(window);

View file

@ -26,10 +26,9 @@ impl Window {
pub fn new( pub fn new(
handle: AnyWindowHandle, handle: AnyWindowHandle,
options: WindowOptions, options: WindowOptions,
platform: &dyn Platform,
cx: &mut AppContext<MainThread>, cx: &mut AppContext<MainThread>,
) -> Self { ) -> Self {
let platform_window = platform.open_window(handle, options); let platform_window = cx.platform().open_window(handle, options);
let mouse_position = platform_window.mouse_position(); let mouse_position = platform_window.mouse_position();
let content_size = platform_window.content_size(); let content_size = platform_window.content_size();
let scale_factor = platform_window.scale_factor(); let scale_factor = platform_window.scale_factor();
@ -46,7 +45,8 @@ impl Window {
} }
})); }));
let platform_window = MainThreadOnly::new(Arc::new(platform_window), platform.dispatcher()); let platform_window =
MainThreadOnly::new(Arc::new(platform_window), cx.platform().dispatcher());
Window { Window {
handle, handle,

View file

@ -17,7 +17,9 @@ fn main() {
SimpleLogger::init(LevelFilter::Info, Default::default()).expect("could not initialize logger"); SimpleLogger::init(LevelFilter::Info, Default::default()).expect("could not initialize logger");
gpui3::App::production().run(|cx| { gpui3::App::production().run(|cx| {
let window = cx.open_window(Default::default(), |cx| workspace(cx)); cx.run_on_main(|cx| {
let window = cx.open_window(Default::default(), |cx| workspace(cx));
});
}); });
} }