WIP
This commit is contained in:
parent
a9d7c86307
commit
e8857d959b
4 changed files with 43 additions and 28 deletions
|
@ -1,6 +1,6 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
AnyWindowHandle, AppContext, Context, Executor, MainThread, Model, ModelContext, Render,
|
AnyView, AnyWindowHandle, AppContext, Context, Executor, MainThread, Model, ModelContext,
|
||||||
Result, Task, View, ViewContext, VisualContext, WindowContext, WindowHandle,
|
Render, Result, Task, View, ViewContext, VisualContext, WindowContext, WindowHandle,
|
||||||
};
|
};
|
||||||
use anyhow::Context as _;
|
use anyhow::Context as _;
|
||||||
use derive_more::{Deref, DerefMut};
|
use derive_more::{Deref, DerefMut};
|
||||||
|
@ -293,6 +293,10 @@ impl Context for AsyncWindowContext {
|
||||||
impl VisualContext for AsyncWindowContext {
|
impl VisualContext for AsyncWindowContext {
|
||||||
type ViewContext<'a, V: 'static> = ViewContext<'a, V>;
|
type ViewContext<'a, V: 'static> = ViewContext<'a, V>;
|
||||||
|
|
||||||
|
fn root_view(&self) -> Result<AnyView> {
|
||||||
|
self.app.update_window(self.window, |cx| cx.root_view())
|
||||||
|
}
|
||||||
|
|
||||||
fn build_view<V>(
|
fn build_view<V>(
|
||||||
&mut self,
|
&mut self,
|
||||||
build_view_state: impl FnOnce(&mut Self::ViewContext<'_, V>) -> V,
|
build_view_state: impl FnOnce(&mut Self::ViewContext<'_, V>) -> V,
|
||||||
|
|
|
@ -215,6 +215,10 @@ impl<C: Context> Context for MainThread<C> {
|
||||||
impl<C: VisualContext> VisualContext for MainThread<C> {
|
impl<C: VisualContext> VisualContext for MainThread<C> {
|
||||||
type ViewContext<'a, V: 'static> = MainThread<C::ViewContext<'a, V>>;
|
type ViewContext<'a, V: 'static> = MainThread<C::ViewContext<'a, V>>;
|
||||||
|
|
||||||
|
fn root_view(&self) -> AnyView {
|
||||||
|
self.0.root_view()
|
||||||
|
}
|
||||||
|
|
||||||
fn build_view<V>(
|
fn build_view<V>(
|
||||||
&mut self,
|
&mut self,
|
||||||
build_view_state: impl FnOnce(&mut Self::ViewContext<'_, V>) -> V,
|
build_view_state: impl FnOnce(&mut Self::ViewContext<'_, V>) -> V,
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
px, size, Action, AnyBox, AnyDrag, AnyView, AppContext, AsyncWindowContext, AvailableSpace,
|
px, size, Action, AnyBox, AnyDrag, AnyView, AppContext, AsyncWindowContext, AvailableSpace,
|
||||||
Bounds, BoxShadow, Context, Corners, DevicePixels, DispatchContext, DisplayId, Edges, Effect,
|
Bounds, BoxShadow, Context, Corners, DevicePixels, DispatchContext, DisplayId, Edges, Effect,
|
||||||
Entity, EntityId, EventEmitter, FileDropEvent, FocusEvent, FontId, GlobalElementId, GlyphId,
|
Entity, EntityId, EventEmitter, FileDropEvent, Flatten, FocusEvent, FontId, GlobalElementId,
|
||||||
Hsla, ImageData, InputEvent, IsZero, KeyListener, KeyMatch, KeyMatcher, Keystroke, LayoutId,
|
GlyphId, Hsla, ImageData, InputEvent, IsZero, KeyListener, KeyMatch, KeyMatcher, Keystroke,
|
||||||
MainThread, MainThreadOnly, Model, ModelContext, Modifiers, MonochromeSprite, MouseButton,
|
LayoutId, MainThread, MainThreadOnly, Model, ModelContext, Modifiers, MonochromeSprite,
|
||||||
MouseDownEvent, MouseMoveEvent, MouseUpEvent, Path, Pixels, PlatformAtlas, PlatformWindow,
|
MouseButton, MouseDownEvent, MouseMoveEvent, MouseUpEvent, Path, Pixels, PlatformAtlas,
|
||||||
Point, PolychromeSprite, Quad, Render, RenderGlyphParams, RenderImageParams, RenderSvgParams,
|
PlatformWindow, Point, PolychromeSprite, Quad, Render, RenderGlyphParams, RenderImageParams,
|
||||||
ScaledPixels, SceneBuilder, Shadow, SharedString, Size, Style, Subscription, TaffyLayoutEngine,
|
RenderSvgParams, ScaledPixels, SceneBuilder, Shadow, SharedString, Size, Style, Subscription,
|
||||||
Task, Underline, UnderlineStyle, View, VisualContext, WeakView, WindowOptions,
|
TaffyLayoutEngine, Task, Underline, UnderlineStyle, View, VisualContext, WeakView,
|
||||||
SUBPIXEL_VARIANTS,
|
WindowOptions, SUBPIXEL_VARIANTS,
|
||||||
};
|
};
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use collections::HashMap;
|
use collections::HashMap;
|
||||||
|
@ -316,8 +316,6 @@ impl<'a> WindowContext<'a> {
|
||||||
Self { app, window }
|
Self { app, window }
|
||||||
}
|
}
|
||||||
|
|
||||||
// fn replace_root(&mut )
|
|
||||||
|
|
||||||
/// Obtain a handle to the window that belongs to this context.
|
/// Obtain a handle to the window that belongs to this context.
|
||||||
pub fn window_handle(&self) -> AnyWindowHandle {
|
pub fn window_handle(&self) -> AnyWindowHandle {
|
||||||
self.window.handle
|
self.window.handle
|
||||||
|
@ -1312,6 +1310,13 @@ impl Context for WindowContext<'_> {
|
||||||
impl VisualContext for WindowContext<'_> {
|
impl VisualContext for WindowContext<'_> {
|
||||||
type ViewContext<'a, V: 'static> = ViewContext<'a, V>;
|
type ViewContext<'a, V: 'static> = ViewContext<'a, V>;
|
||||||
|
|
||||||
|
fn root_view(&self) -> Self::Result<AnyView> {
|
||||||
|
self.window
|
||||||
|
.root_view
|
||||||
|
.clone()
|
||||||
|
.expect("we only take the root_view value when we draw")
|
||||||
|
}
|
||||||
|
|
||||||
fn build_view<V>(
|
fn build_view<V>(
|
||||||
&mut self,
|
&mut self,
|
||||||
build_view_state: impl FnOnce(&mut Self::ViewContext<'_, V>) -> V,
|
build_view_state: impl FnOnce(&mut Self::ViewContext<'_, V>) -> V,
|
||||||
|
@ -1966,6 +1971,10 @@ impl<V> Context for ViewContext<'_, V> {
|
||||||
impl<V: 'static> VisualContext for ViewContext<'_, V> {
|
impl<V: 'static> VisualContext for ViewContext<'_, V> {
|
||||||
type ViewContext<'a, W: 'static> = ViewContext<'a, W>;
|
type ViewContext<'a, W: 'static> = ViewContext<'a, W>;
|
||||||
|
|
||||||
|
fn root_view(&self) -> Self::Result<AnyView> {
|
||||||
|
self.window_cx.root_view()
|
||||||
|
}
|
||||||
|
|
||||||
fn build_view<W: 'static + Send>(
|
fn build_view<W: 'static + Send>(
|
||||||
&mut self,
|
&mut self,
|
||||||
build_view: impl FnOnce(&mut Self::ViewContext<'_, W>) -> W,
|
build_view: impl FnOnce(&mut Self::ViewContext<'_, W>) -> W,
|
||||||
|
@ -2034,20 +2043,20 @@ impl<V: 'static + Render> WindowHandle<V> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update_root<R>(
|
pub fn update_root<C, R>(
|
||||||
&self,
|
&self,
|
||||||
cx: &mut AppContext,
|
cx: &mut C,
|
||||||
update: impl FnOnce(&mut V, &mut ViewContext<V>) -> R,
|
update: impl FnOnce(&mut V, &mut ViewContext<V>) -> R,
|
||||||
) -> Result<R> {
|
) -> Result<R>
|
||||||
|
where
|
||||||
|
C: Context,
|
||||||
|
{
|
||||||
cx.update_window(self.any_handle, |cx| {
|
cx.update_window(self.any_handle, |cx| {
|
||||||
let root_view = cx
|
let x = Ok(cx.root_view()).flatten();
|
||||||
.window
|
|
||||||
.root_view
|
// let root_view = x.unwrap().downcast::<V>().unwrap();
|
||||||
.clone()
|
// root_view.update(cx, update)
|
||||||
.unwrap()
|
todo!()
|
||||||
.downcast::<V>()
|
|
||||||
.unwrap();
|
|
||||||
root_view.update(cx, update)
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -887,11 +887,9 @@ impl Workspace {
|
||||||
.await
|
.await
|
||||||
.log_err();
|
.log_err();
|
||||||
|
|
||||||
cx.update_global(|_, cx| {
|
window.update_root(&mut cx, |_, cx| {
|
||||||
window.update_root(&mut cx, |_, cx| {
|
// todo!()
|
||||||
// todo!()
|
// cx.activate_window()
|
||||||
// cx.activate_window()
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
let workspace = workspace.downgrade();
|
let workspace = workspace.downgrade();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue