WIP
This commit is contained in:
parent
e6cc132b19
commit
d9e4136b02
14 changed files with 235 additions and 150 deletions
|
@ -802,6 +802,14 @@ impl AppContext {
|
|||
.is_some()
|
||||
}
|
||||
|
||||
pub fn window_is_active(&self, window_id: usize) -> bool {
|
||||
self.windows.get(&window_id).map_or(false, |w| w.is_active)
|
||||
}
|
||||
|
||||
pub fn root_view(&self, window_id: usize) -> Option<&AnyViewHandle> {
|
||||
self.windows.get(&window_id).map(|w| w.root_view())
|
||||
}
|
||||
|
||||
pub fn window_ids(&self) -> impl Iterator<Item = usize> + '_ {
|
||||
self.windows.keys().copied()
|
||||
}
|
||||
|
@ -1648,6 +1656,18 @@ impl AppContext {
|
|||
window
|
||||
}
|
||||
|
||||
pub fn replace_root_view<V, F>(
|
||||
&mut self,
|
||||
window_id: usize,
|
||||
build_root_view: F,
|
||||
) -> Option<ViewHandle<V>>
|
||||
where
|
||||
V: View,
|
||||
F: FnOnce(&mut ViewContext<V>) -> V,
|
||||
{
|
||||
self.update_window(window_id, |cx| cx.replace_root_view(build_root_view))
|
||||
}
|
||||
|
||||
pub fn add_view<S, F>(&mut self, parent: &AnyViewHandle, build_view: F) -> ViewHandle<S>
|
||||
where
|
||||
S: View,
|
||||
|
@ -3326,6 +3346,22 @@ impl<'a, 'b, 'c, V: View> ViewContext<'a, 'b, 'c, V> {
|
|||
self.window.focused_view_id == Some(self.view_id)
|
||||
}
|
||||
|
||||
pub fn is_parent_view_focused(&self) -> bool {
|
||||
if let Some(parent_view_id) = self.ancestors(self.window_id, self.view_id).next().clone() {
|
||||
self.focused_view_id() == Some(parent_view_id)
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
pub fn focus_parent_view(&mut self) {
|
||||
let next = self.ancestors(self.window_id, self.view_id).next().clone();
|
||||
if let Some(parent_view_id) = next {
|
||||
let window_id = self.window_id;
|
||||
self.window_context.focus(window_id, Some(parent_view_id));
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_child(&self, view: impl Into<AnyViewHandle>) -> bool {
|
||||
let view = view.into();
|
||||
if self.window_id != view.window_id {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue