From 4b793f44ef41818f623e4cc99f3276d9660fbc51 Mon Sep 17 00:00:00 2001 From: Marshall Bowers Date: Wed, 4 Oct 2023 11:22:33 -0400 Subject: [PATCH] Wire up hacky children for `Panel` --- crates/gpui3/src/element.rs | 25 ++++++++++++++++++++ crates/storybook2/src/ui/components/panel.rs | 16 ++++++------- crates/storybook2/src/ui/prelude.rs | 2 +- crates/storybook2/src/workspace.rs | 12 +++++++++- 4 files changed, 44 insertions(+), 11 deletions(-) diff --git a/crates/gpui3/src/element.rs b/crates/gpui3/src/element.rs index c145a9725b1c93508a2f30d8d54746abd3e04709..2b2ddfc3bf12d55a10609f93e7184c66beb768cc 100644 --- a/crates/gpui3/src/element.rs +++ b/crates/gpui3/src/element.rs @@ -39,6 +39,31 @@ pub trait ParentElement { .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(mut self, children: I) -> Self + where + I: IntoIterator>, + 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) -> Self + where + Self: Sized, + { + self.children_mut().push(children); + self + } } trait ElementObject { diff --git a/crates/storybook2/src/ui/components/panel.rs b/crates/storybook2/src/ui/components/panel.rs index 525dcaa80784230c107d89a2d964b66e83f25b53..e6847fa78b73463f347649b24a558b88c4ef1613 100644 --- a/crates/storybook2/src/ui/components/panel.rs +++ b/crates/storybook2/src/ui/components/panel.rs @@ -48,15 +48,15 @@ pub struct Panel { allowed_sides: PanelAllowedSides, initial_width: AbsoluteLength, width: Option, - // children: HackyChildren, - // payload: HackyChildrenPayload, + children: HackyChildren, + payload: HackyChildrenPayload, } impl Panel { pub fn new( scroll_state: ScrollState, - // children: HackyChildren, - // payload: HackyChildrenPayload, + children: HackyChildren, + payload: HackyChildrenPayload, ) -> Self { let token = token(); @@ -67,8 +67,8 @@ impl Panel { allowed_sides: PanelAllowedSides::default(), initial_width: token.default_panel_size, width: None, - // children, - // payload, + children, + payload, } } @@ -141,8 +141,6 @@ impl Panel { } } - 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.rs index 0be2c78c03bf27fa8edf83876f76ee07800543d5..d89bb944e51dc8b751f7c5981895c8fc86f534a1 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.rs index 6d60fb3e3e308667e952f70414e8681b5678cec5..a12f31b40b8aaf7d905250d4d331528e55b88349 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()