Merge branch 'main' into collab-panel
This commit is contained in:
commit
c537cf2a57
92 changed files with 2015 additions and 1591 deletions
File diff suppressed because it is too large
Load diff
|
@ -6,7 +6,7 @@ use crate::{
|
|||
platform::{Event, InputHandler, KeyDownEvent, Platform},
|
||||
Action, AppContext, BorrowAppContext, BorrowWindowContext, Entity, FontCache, Handle,
|
||||
ModelContext, ModelHandle, Subscription, Task, View, ViewContext, ViewHandle, WeakHandle,
|
||||
WindowContext,
|
||||
WindowContext, WindowHandle,
|
||||
};
|
||||
use collections::BTreeMap;
|
||||
use futures::Future;
|
||||
|
@ -60,7 +60,7 @@ impl TestAppContext {
|
|||
RefCounts::new(leak_detector),
|
||||
(),
|
||||
);
|
||||
cx.next_entity_id = first_entity_id;
|
||||
cx.next_id = first_entity_id;
|
||||
let cx = TestAppContext {
|
||||
cx: Rc::new(RefCell::new(cx)),
|
||||
foreground_platform,
|
||||
|
@ -148,17 +148,18 @@ impl TestAppContext {
|
|||
self.cx.borrow_mut().add_model(build_model)
|
||||
}
|
||||
|
||||
pub fn add_window<T, F>(&mut self, build_root_view: F) -> (usize, ViewHandle<T>)
|
||||
pub fn add_window<T, F>(&mut self, build_root_view: F) -> WindowHandle<T>
|
||||
where
|
||||
T: View,
|
||||
F: FnOnce(&mut ViewContext<T>) -> T,
|
||||
{
|
||||
let (window_id, view) = self
|
||||
let window = self
|
||||
.cx
|
||||
.borrow_mut()
|
||||
.add_window(Default::default(), build_root_view);
|
||||
self.simulate_window_activation(Some(window_id));
|
||||
(window_id, view)
|
||||
self.simulate_window_activation(Some(window.window_id()));
|
||||
|
||||
WindowHandle::new(window.window_id())
|
||||
}
|
||||
|
||||
pub fn add_view<T, F>(&mut self, window_id: usize, build_view: F) -> ViewHandle<T>
|
||||
|
@ -405,14 +406,20 @@ impl BorrowAppContext for TestAppContext {
|
|||
}
|
||||
|
||||
impl BorrowWindowContext for TestAppContext {
|
||||
fn read_with<T, F: FnOnce(&WindowContext) -> T>(&self, window_id: usize, f: F) -> T {
|
||||
type Result<T> = T;
|
||||
|
||||
fn read_window_with<T, F: FnOnce(&WindowContext) -> T>(&self, window_id: usize, f: F) -> T {
|
||||
self.cx
|
||||
.borrow()
|
||||
.read_window(window_id, f)
|
||||
.expect("window was closed")
|
||||
}
|
||||
|
||||
fn update<T, F: FnOnce(&mut WindowContext) -> T>(&mut self, window_id: usize, f: F) -> T {
|
||||
fn update_window<T, F: FnOnce(&mut WindowContext) -> T>(
|
||||
&mut self,
|
||||
window_id: usize,
|
||||
f: F,
|
||||
) -> T {
|
||||
self.cx
|
||||
.borrow_mut()
|
||||
.update_window(window_id, f)
|
||||
|
|
|
@ -15,7 +15,7 @@ use crate::{
|
|||
util::post_inc,
|
||||
Action, AnyView, AnyViewHandle, AppContext, BorrowAppContext, BorrowWindowContext, Effect,
|
||||
Element, Entity, Handle, LayoutContext, MouseRegion, MouseRegionId, SceneBuilder, Subscription,
|
||||
View, ViewContext, ViewHandle, WindowInvalidation,
|
||||
View, ViewContext, ViewHandle, WindowHandle, WindowInvalidation,
|
||||
};
|
||||
use anyhow::{anyhow, bail, Result};
|
||||
use collections::{HashMap, HashSet};
|
||||
|
@ -142,7 +142,9 @@ impl BorrowAppContext for WindowContext<'_> {
|
|||
}
|
||||
|
||||
impl BorrowWindowContext for WindowContext<'_> {
|
||||
fn read_with<T, F: FnOnce(&WindowContext) -> T>(&self, window_id: usize, f: F) -> T {
|
||||
type Result<T> = T;
|
||||
|
||||
fn read_window_with<T, F: FnOnce(&WindowContext) -> T>(&self, window_id: usize, f: F) -> T {
|
||||
if self.window_id == window_id {
|
||||
f(self)
|
||||
} else {
|
||||
|
@ -150,7 +152,11 @@ impl BorrowWindowContext for WindowContext<'_> {
|
|||
}
|
||||
}
|
||||
|
||||
fn update<T, F: FnOnce(&mut WindowContext) -> T>(&mut self, window_id: usize, f: F) -> T {
|
||||
fn update_window<T, F: FnOnce(&mut WindowContext) -> T>(
|
||||
&mut self,
|
||||
window_id: usize,
|
||||
f: F,
|
||||
) -> T {
|
||||
if self.window_id == window_id {
|
||||
f(self)
|
||||
} else {
|
||||
|
@ -1151,15 +1157,15 @@ impl<'a> WindowContext<'a> {
|
|||
self.window.platform_window.prompt(level, msg, answers)
|
||||
}
|
||||
|
||||
pub fn replace_root_view<V, F>(&mut self, build_root_view: F) -> ViewHandle<V>
|
||||
pub fn replace_root_view<V, F>(&mut self, build_root_view: F) -> WindowHandle<V>
|
||||
where
|
||||
V: View,
|
||||
F: FnOnce(&mut ViewContext<V>) -> V,
|
||||
{
|
||||
let root_view = self.add_view(|cx| build_root_view(cx));
|
||||
self.window.root_view = Some(root_view.clone().into_any());
|
||||
self.window.focused_view_id = Some(root_view.id());
|
||||
root_view
|
||||
self.window.root_view = Some(root_view.into_any());
|
||||
WindowHandle::new(self.window_id)
|
||||
}
|
||||
|
||||
pub fn add_view<T, F>(&mut self, build_view: F) -> ViewHandle<T>
|
||||
|
@ -1176,7 +1182,7 @@ impl<'a> WindowContext<'a> {
|
|||
F: FnOnce(&mut ViewContext<T>) -> Option<T>,
|
||||
{
|
||||
let window_id = self.window_id;
|
||||
let view_id = post_inc(&mut self.next_entity_id);
|
||||
let view_id = post_inc(&mut self.next_id);
|
||||
let mut cx = ViewContext::mutable(self, view_id);
|
||||
let handle = if let Some(view) = build_view(&mut cx) {
|
||||
let mut keymap_context = KeymapContext::default();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue