Take an Into<AnyViewHandle> in ChildView::new

Co-Authored-By: Nathan Sobo <nathan@zed.dev>
Co-Authored-By: Max Brunsfeld <max@zed.dev>
This commit is contained in:
Antonio Scandurra 2022-01-27 17:52:36 +01:00
parent dbf48d2a5b
commit e7d4c385d5
12 changed files with 69 additions and 56 deletions

View file

@ -1,7 +1,7 @@
use crate::{ItemViewHandle, Pane, Settings};
use gpui::{
elements::*, ElementBox, Entity, MutableAppContext, RenderContext, Subscription, View,
ViewContext, ViewHandle,
elements::*, AnyViewHandle, ElementBox, Entity, MutableAppContext, RenderContext, Subscription,
View, ViewContext, ViewHandle,
};
use postage::watch;
@ -14,7 +14,7 @@ pub trait StatusItemView: View {
}
trait StatusItemViewHandle {
fn id(&self) -> usize;
fn to_any(&self) -> AnyViewHandle;
fn set_active_pane_item(
&self,
active_pane_item: Option<&dyn ItemViewHandle>,
@ -45,13 +45,13 @@ impl View for StatusBar {
.with_children(
self.left_items
.iter()
.map(|i| ChildView::new(i.id()).aligned().boxed()),
.map(|i| ChildView::new(i.as_ref()).aligned().boxed()),
)
.with_child(Empty::new().flexible(1., true).boxed())
.with_children(
self.right_items
.iter()
.map(|i| ChildView::new(i.id()).aligned().boxed()),
.map(|i| ChildView::new(i.as_ref()).aligned().boxed()),
)
.contained()
.with_style(theme.container)
@ -111,8 +111,8 @@ impl StatusBar {
}
impl<T: StatusItemView> StatusItemViewHandle for ViewHandle<T> {
fn id(&self) -> usize {
self.id()
fn to_any(&self) -> AnyViewHandle {
self.into()
}
fn set_active_pane_item(
@ -125,3 +125,9 @@ impl<T: StatusItemView> StatusItemViewHandle for ViewHandle<T> {
});
}
}
impl Into<AnyViewHandle> for &dyn StatusItemViewHandle {
fn into(self) -> AnyViewHandle {
self.to_any()
}
}