From ebc80597d59b03542cd057b26a425713a3426087 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Wed, 4 Oct 2023 20:09:55 +0200 Subject: [PATCH] WIP --- crates/gpui3/src/app.rs | 12 ++++++++++++ crates/gpui3/src/window.rs | 28 +++++++++++++++++++++------- 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/crates/gpui3/src/app.rs b/crates/gpui3/src/app.rs index 592a6076defb6b43f879e08584d44ddc94ade01c..3b1a66326c56b4f199e1d4aaa68f94725b63d760 100644 --- a/crates/gpui3/src/app.rs +++ b/crates/gpui3/src/app.rs @@ -225,6 +225,18 @@ impl AppContext { }) } + pub fn spawn(&self, f: impl FnOnce(&mut AppContext) -> Fut + Send + 'static) -> Task + where + Fut: Future + Send + 'static, + R: Send + 'static, + { + let this = self.this.upgrade().unwrap(); + self.executor.spawn(async move { + let future = f(&mut this.lock()); + future.await + }) + } + pub fn text_system(&self) -> &Arc { &self.text_system } diff --git a/crates/gpui3/src/window.rs b/crates/gpui3/src/window.rs index 3782dfe97a563b5e6ecc57ee13f834dc31ad66c4..3257f520cdabf7ad70f2927adb0709d6ca2d6ff0 100644 --- a/crates/gpui3/src/window.rs +++ b/crates/gpui3/src/window.rs @@ -1,14 +1,14 @@ use crate::{ - image_cache::RenderImageParams, px, AnyView, AppContext, AvailableSpace, BorrowAppContext, - Bounds, Context, Corners, DevicePixels, Effect, Element, EntityId, FontId, GlyphId, Handle, - Hsla, ImageData, IsZero, LayerId, LayoutId, MainThread, MainThreadOnly, MonochromeSprite, - Pixels, PlatformAtlas, PlatformWindow, Point, PolychromeSprite, Reference, RenderGlyphParams, - RenderSvgParams, ScaledPixels, Scene, SharedString, Size, Style, TaffyLayoutEngine, Task, - WeakHandle, WindowOptions, SUBPIXEL_VARIANTS, + image_cache::RenderImageParams, px, AnyView, AppContext, AsyncContext, AvailableSpace, + BorrowAppContext, Bounds, Context, Corners, DevicePixels, Effect, Element, EntityId, FontId, + GlyphId, Handle, Hsla, ImageData, IsZero, LayerId, LayoutId, MainThread, MainThreadOnly, + MonochromeSprite, Pixels, PlatformAtlas, PlatformWindow, Point, PolychromeSprite, Reference, + RenderGlyphParams, RenderSvgParams, ScaledPixels, Scene, SharedString, Size, Style, + TaffyLayoutEngine, Task, WeakHandle, WindowOptions, SUBPIXEL_VARIANTS, }; use anyhow::Result; use smallvec::SmallVec; -use std::{any::TypeId, borrow::Cow, marker::PhantomData, mem, sync::Arc}; +use std::{any::TypeId, borrow::Cow, future::Future, marker::PhantomData, mem, sync::Arc}; use util::ResultExt; pub struct AnyWindow {} @@ -601,6 +601,20 @@ impl<'a, 'w, S: Send + Sync + 'static> ViewContext<'a, 'w, S> { } } + pub fn spawn( + &mut self, + f: impl FnOnce(&mut S, &mut ViewContext<'_, '_, S>) -> Fut + Send + 'static, + ) -> Task> + where + Fut: Future + Send + 'static, + { + let handle = self.handle(); + todo!() + // self.window_cx.spawn(|cx| { + // f + // }) + } + pub(crate) fn erase_state(&mut self, f: impl FnOnce(&mut ViewContext<()>) -> R) -> R { let entity_id = self.unit_entity.id; let mut cx = ViewContext::mutable(