Checkpoint
This commit is contained in:
parent
e68b24f839
commit
02d6b91b73
7 changed files with 156 additions and 98 deletions
|
@ -1,10 +1,10 @@
|
|||
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, AsyncWindowContext, 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;
|
||||
|
@ -109,6 +109,7 @@ impl<'a, 'w> WindowContext<'a, 'w> {
|
|||
}
|
||||
|
||||
pub fn notify(&mut self) {
|
||||
dbg!("ViewContext::notify");
|
||||
self.window.dirty = true;
|
||||
}
|
||||
|
||||
|
@ -129,33 +130,23 @@ impl<'a, 'w> WindowContext<'a, 'w> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn to_async(&self) -> AsyncWindowContext {
|
||||
AsyncWindowContext::new(self.app.to_async(), self.window.handle)
|
||||
}
|
||||
|
||||
pub fn spawn<Fut, R>(
|
||||
&mut self,
|
||||
f: impl FnOnce(&mut WindowContext<'_, '_>) -> Fut + Send + 'static,
|
||||
) -> Task<Result<R>>
|
||||
f: impl FnOnce(AnyWindowHandle, AsyncWindowContext) -> Fut + Send + 'static,
|
||||
) -> Task<R>
|
||||
where
|
||||
R: Send + 'static,
|
||||
Fut: Future<Output = R> + Send + 'static,
|
||||
{
|
||||
let id = self.window.handle.id;
|
||||
self.app.spawn(move |cx| {
|
||||
let future = cx.update_window(id, f);
|
||||
async move { Ok(future?.await) }
|
||||
})
|
||||
}
|
||||
|
||||
pub fn try_spawn<Fut, R>(
|
||||
&mut self,
|
||||
f: impl FnOnce(&mut WindowContext<'_, '_>) -> Fut + Send + 'static,
|
||||
) -> Task<Result<R>>
|
||||
where
|
||||
R: Send + 'static,
|
||||
Fut: Future<Output = Result<R>> + Send + 'static,
|
||||
{
|
||||
let id = self.window.handle.id;
|
||||
self.app.spawn(move |cx| {
|
||||
let future = cx.update_window(id, f);
|
||||
async move { future?.await }
|
||||
let window = self.window.handle;
|
||||
self.app.spawn(move |app| {
|
||||
let cx = AsyncWindowContext::new(app, window);
|
||||
let future = f(window, cx);
|
||||
async move { future.await }
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -448,7 +439,7 @@ impl Context for WindowContext<'_, '_> {
|
|||
&mut self.window,
|
||||
slot.id,
|
||||
));
|
||||
self.entities.redeem(slot, entity)
|
||||
self.entities.insert(slot, entity)
|
||||
}
|
||||
|
||||
fn update_entity<T: Send + Sync + 'static, R>(
|
||||
|
@ -607,6 +598,7 @@ impl<'a, 'w, S: Send + Sync + 'static> ViewContext<'a, 'w, S> {
|
|||
}
|
||||
|
||||
pub fn notify(&mut self) {
|
||||
dbg!("ViewContext::notify");
|
||||
self.window_cx.notify();
|
||||
self.window_cx
|
||||
.app
|
||||
|
@ -633,16 +625,16 @@ impl<'a, 'w, S: Send + Sync + 'static> ViewContext<'a, 'w, S> {
|
|||
|
||||
pub fn spawn<Fut, R>(
|
||||
&mut self,
|
||||
f: impl FnOnce(&mut S, &mut ViewContext<'_, '_, S>) -> Fut + Send + 'static,
|
||||
) -> Task<Result<R>>
|
||||
f: impl FnOnce(WeakHandle<S>, AsyncWindowContext) -> Fut + Send + 'static,
|
||||
) -> Task<R>
|
||||
where
|
||||
R: Send + 'static,
|
||||
Fut: Future<Output = R> + Send + 'static,
|
||||
{
|
||||
let handle = self.handle();
|
||||
self.window_cx.try_spawn(move |cx| {
|
||||
let result = handle.update(cx, f);
|
||||
async move { Ok(result?.await) }
|
||||
self.window_cx.spawn(move |_, cx| {
|
||||
let result = f(handle, cx);
|
||||
async move { result.await }
|
||||
})
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue