Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Wire up hacky children for `Panel`
Marshall Bowers4b793f44ef41
diff --git a/crates/gpui3/src/element.rs b/crates/gpui3/src/element.rsindex c145a9725b1..2b2ddfc3bf1 100644--- a/crates/gpui3/src/element.rs+++ b/crates/gpui3/src/element.rs@@ -39,6 +39,31 @@ pub trait ParentElement<S> {.extend(iter.into_iter().map(|item| item.into_any()));self}++ // HACK: This is a temporary hack to get children working for the purposes+ // of building UI on top of the current version of gpui2.+ //+ // We'll (hopefully) be moving away from this in the future.+ fn children_any<I>(mut self, children: I) -> Self+ where+ I: IntoIterator<Item = AnyElement<S>>,+ Self: Sized,+ {+ self.children_mut().extend(children.into_iter());+ self+ }++ // HACK: This is a temporary hack to get children working for the purposes+ // of building UI on top of the current version of gpui2.+ //+ // We'll (hopefully) be moving away from this in the future.+ fn child_any(mut self, children: AnyElement<S>) -> Self+ where+ Self: Sized,+ {+ self.children_mut().push(children);+ self+ }}trait ElementObject<S> {diff --git a/crates/storybook2/src/ui/components/panel.rs b/crates/storybook2/src/ui/components/panel.rsindex 525dcaa8078..e6847fa78b7 100644--- a/crates/storybook2/src/ui/components/panel.rs+++ b/crates/storybook2/src/ui/components/panel.rs@@ -48,15 +48,15 @@ pub struct Panel<S: 'static + Send + Sync> {allowed_sides: PanelAllowedSides,initial_width: AbsoluteLength,width: Option<AbsoluteLength>,- // children: HackyChildren<V>,- // payload: HackyChildrenPayload,+ children: HackyChildren<S>,+ payload: HackyChildrenPayload,}impl<S: 'static + Send + Sync> Panel<S> {pub fn new(scroll_state: ScrollState,- // children: HackyChildren<S>,- // payload: HackyChildrenPayload,+ children: HackyChildren<S>,+ payload: HackyChildrenPayload,) -> Self {let token = token();@@ -67,8 +67,8 @@ impl<S: 'static + Send + Sync> Panel<S> {allowed_sides: PanelAllowedSides::default(),initial_width: token.default_panel_size,width: None,- // children,- // payload,+ children,+ payload,}}@@ -141,8 +141,6 @@ impl<S: 'static + Send + Sync> Panel<S> {}}- panel_base-- // panel_base.children_any((self.children)(cx, self.payload.as_ref()))+ panel_base.children_any((self.children)(cx, self.payload.as_ref()))}}diff --git a/crates/storybook2/src/ui/prelude.rs b/crates/storybook2/src/ui/prelude.rsindex 0be2c78c03b..d89bb944e51 100644--- a/crates/storybook2/src/ui/prelude.rs+++ b/crates/storybook2/src/ui/prelude.rs@@ -1,3 +1,3 @@-pub use gpui3::{Element, ScrollState, StyleHelpers, ViewContext};+pub use gpui3::{Element, IntoAnyElement, ParentElement, ScrollState, StyleHelpers, ViewContext};pub use crate::ui::{HackyChildren, HackyChildrenPayload};diff --git a/crates/storybook2/src/workspace.rs b/crates/storybook2/src/workspace.rsindex 6d60fb3e3e3..a12f31b40b8 100644--- a/crates/storybook2/src/workspace.rs+++ b/crates/storybook2/src/workspace.rs@@ -35,7 +35,17 @@ impl Workspace {.size_full().v_stack().fill(theme.lowest.base.default.background)- .child(Panel::new(ScrollState::default()))+ .child(Panel::new(+ ScrollState::default(),+ |_, _| {+ vec![div()+ .font("Courier")+ .text_color(gpui3::hsla(1., 1., 1., 1.))+ .child("Hello world")+ .into_any()]+ },+ Box::new(()),+ )).child(div().size_full()