Wire up hacky children for Panel

This commit is contained in:
Marshall Bowers 2023-10-04 11:22:33 -04:00
parent aae4f00a4b
commit 4b793f44ef
4 changed files with 44 additions and 11 deletions

View file

@ -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> {

View file

@ -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()))
}
}

View file

@ -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};

View file

@ -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()