Remove hacky children

This commit is contained in:
Marshall Bowers 2023-10-12 15:50:09 -04:00
parent 24bab48043
commit d320d3a8bf
6 changed files with 10 additions and 40 deletions

View file

@ -82,31 +82,6 @@ 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<I>(mut self, children: I) -> Self
where
I: IntoIterator<Item = AnyElement<Self::State>>,
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::State>) -> Self
where
Self: Sized,
{
self.children_mut().push(children);
self
}
}
trait ElementObject<S>: 'static + Send + Sync {

View file

@ -19,16 +19,20 @@ impl<S: 'static + Send + Sync + Clone> KitchenSinkStory<S> {
}
fn render(&mut self, _view: &mut S, cx: &mut ViewContext<S>) -> impl Element<ViewState = S> {
let element_stories = ElementStory::iter().map(|selector| selector.story());
let component_stories = ComponentStory::iter().map(|selector| selector.story(cx)).collect::<Vec<_>>();
let element_stories = ElementStory::iter()
.map(|selector| selector.story())
.collect::<Vec<_>>();
let component_stories = ComponentStory::iter()
.map(|selector| selector.story(cx))
.collect::<Vec<_>>();
Story::container(cx)
.overflow_y_scroll(ScrollState::default())
.child(Story::title(cx, "Kitchen Sink"))
.child(Story::label(cx, "Elements"))
.child(div().flex().flex_col().children_any(element_stories))
.child(div().flex().flex_col().children(element_stories))
.child(Story::label(cx, "Components"))
.child(div().flex().flex_col().children_any(component_stories))
.child(div().flex().flex_col().children(component_stories))
// Add a bit of space at the bottom of the kitchen sink so elements
// don't end up squished right up against the bottom of the screen.
.child(div().p_4())

View file

@ -109,7 +109,7 @@ impl StoryWrapper {
.flex()
.flex_col()
.size_full()
.child_any(self.selector.story(cx))
.child(self.selector.story(cx))
})
}
}

View file

@ -1,7 +0,0 @@
use std::any::Any;
use gpui3::{AnyElement, ViewContext};
pub type HackyChildren<S> = fn(&mut ViewContext<S>, &dyn Any) -> Vec<AnyElement<S>>;
pub type HackyChildrenPayload = Box<dyn Any + Send + Sync>;

View file

@ -1,6 +1,5 @@
#![allow(dead_code, unused_variables)]
mod children;
mod components;
mod element_ext;
mod elements;
@ -8,7 +7,6 @@ pub mod prelude;
mod static_data;
mod theme;
pub use children::*;
pub use components::*;
pub use element_ext::*;
pub use elements::*;

View file

@ -3,7 +3,7 @@ pub use gpui3::{
WindowContext,
};
pub use crate::{theme, ButtonVariant, ElementExt, HackyChildren, HackyChildrenPayload, Theme};
pub use crate::{theme, ButtonVariant, ElementExt, Theme};
use gpui3::{hsla, rems, rgb, AbsoluteLength, Hsla};
use strum::EnumIter;