use super::*;
pub struct XMultiChild<'p>(pub(crate) Box<dyn BoxedParent + 'p>);
pub struct MultiPair<'a, P> {
pub(super) parent: P,
pub(super) children: Vec<Widget<'a>>,
}
impl<'p, P> MultiPair<'p, P> {
pub fn with_child<'c: 'w, 'w, K: ?Sized>(
self, child: impl IntoWidgetIter<'c, K>,
) -> MultiPair<'w, P>
where
'p: 'w,
{
let MultiPair { parent, mut children } = self;
for c in child.into_widget_iter() {
children.push(c);
}
MultiPair { parent, children }
}
}
impl<'p, P> From<P> for XMultiChild<'p>
where
P: Parent + MultiChild + 'p,
{
fn from(value: P) -> Self { XMultiChild(Box::new(value)) }
}
impl<'w, I, K> IntoWidgetIter<'w, dyn Iterator<Item = K>> for I
where
I: IntoIterator<Item: IntoWidget<'w, K>>,
{
fn into_widget_iter(self) -> impl Iterator<Item = Widget<'w>> {
self.into_iter().map(IntoWidget::into_widget)
}
}
impl<P, K> IntoWidgetIter<'static, Pipe<fn() -> [K]>> for Pipe<P>
where
P: IntoIterator<Item: IntoWidget<'static, K>> + 'static,
{
fn into_widget_iter(self) -> impl Iterator<Item = Widget<'static>> {
self.build_multi().into_iter()
}
}
impl<'w, W: IntoWidget<'w, IntoKind>> IntoWidgetIter<'w, IntoKind> for W {
fn into_widget_iter(self) -> impl Iterator<Item = Widget<'w>> {
std::iter::once(self.into_widget())
}
}
impl<'w, W, K: ?Sized> IntoWidgetIter<'w, OtherWidget<K>> for W
where
W: IntoWidget<'w, OtherWidget<K>>,
{
fn into_widget_iter(self) -> impl Iterator<Item = Widget<'w>> {
std::iter::once(self.into_widget())
}
}
impl<'p> MultiChild for XMultiChild<'p> {}
impl<T> MultiChild for T where T: StateReader<Value: MultiChild> {}
impl<P: MultiChild> MultiChild for FatObj<P> {}
impl<P: MultiChild, F: FnOnce() -> P> MultiChild for FnWidget<P, F> {}
impl<P: Into<XMultiChild<'static>>> MultiChild for Pipe<P> {}
impl<'w, 'c: 'w, P> RFrom<MultiPair<'c, P>, OtherWidget<dyn Compose>> for Widget<'w>
where
P: MultiChild + XParent + 'w,
{
fn r_from(value: MultiPair<'c, P>) -> Self {
let MultiPair { parent, children } = value;
parent.x_with_children(children)
}
}
impl<'p> RFrom<XMultiChild<'p>, OtherWidget<dyn Compose>> for Widget<'p> {
#[inline]
fn r_from(value: XMultiChild<'p>) -> Self { value.0.boxed_with_children(vec![]) }
}
impl<'p, P> std::ops::Deref for MultiPair<'p, P> {
type Target = P;
fn deref(&self) -> &Self::Target { &self.parent }
}
impl<'p, P> std::ops::DerefMut for MultiPair<'p, P> {
fn deref_mut(&mut self) -> &mut Self::Target { &mut self.parent }
}