diff --git a/core/src/builtin_widgets.rs b/core/src/builtin_widgets.rs index abed9e403..1e56fcf3d 100644 --- a/core/src/builtin_widgets.rs +++ b/core/src/builtin_widgets.rs @@ -59,7 +59,7 @@ pub use focus_node::*; pub mod focus_scope; pub use focus_scope::*; -use crate::{prelude::*, widget::WidgetBuilder}; +use crate::{prelude::*, widget::StrictBuilder}; macro_rules! impl_builtin_obj { ($($builtin_ty: ty),*) => { @@ -185,8 +185,8 @@ impl FatObj { } } -impl> WidgetBuilder for FatObj { - fn build(self, ctx: &BuildCtx) -> WidgetId { +impl> StrictBuilder for FatObj { + fn strict_build(self, ctx: &BuildCtx) -> WidgetId { let Self { host, builtin } = self; builtin.compose_with_host(host.into(), ctx).build(ctx) } diff --git a/core/src/builtin_widgets/lifecycle.rs b/core/src/builtin_widgets/lifecycle.rs index febe15eb6..7a2200442 100644 --- a/core/src/builtin_widgets/lifecycle.rs +++ b/core/src/builtin_widgets/lifecycle.rs @@ -213,12 +213,11 @@ mod tests { @MockMulti { @ { pipe!(*$cnt).map(move |cnt| { - let iter = (0..cnt).map(move |_| @MockBox { + (0..cnt).map(move |_| @MockBox { size: Size::zero(), on_mounted: move |e| { $mounted.write().insert(e.id); }, on_disposed: move |e| { $disposed.write().insert(e.id); }, - }); - Multi::new(iter) + }) }) } } diff --git a/core/src/builtin_widgets/theme.rs b/core/src/builtin_widgets/theme.rs index 8de5418fd..6850e046c 100644 --- a/core/src/builtin_widgets/theme.rs +++ b/core/src/builtin_widgets/theme.rs @@ -1,7 +1,7 @@ //! Theme use to share visual config or style compose logic. It can be defined //! to app-wide or particular part of the application. -use crate::{fill_svgs, impl_query_self_only, prelude::*, widget::WidgetBuilder}; +use crate::{fill_svgs, impl_query_self_only, prelude::*, widget::StrictBuilder}; pub use ribir_algo::{CowArc, ShareResource}; use ribir_geom::Size; use ribir_macros::Declare2; @@ -82,7 +82,7 @@ impl ComposeChild for ThemeWidget { AppCtx::load_font_from_theme(&theme); ctx.push_theme(theme.clone()); - let p = DataWidget::new(Box::new(Void), theme).build(ctx); + let p = DataWidget::new(Box::new(Void), theme).strict_build(ctx); let old = ctx.force_as_mut().reset_ctx_from(Some(p)); let c = child.build(ctx); ctx.append_child(p, c); diff --git a/core/src/pipe.rs b/core/src/pipe.rs index 8f09d83b9..c0d6f3520 100644 --- a/core/src/pipe.rs +++ b/core/src/pipe.rs @@ -16,7 +16,7 @@ use crate::{ impl_proxy_render, prelude::*, ticker::FrameMsg, - widget::{Query, QueryOrder, Render, Widget, WidgetBuilder, WidgetId, WidgetTree}, + widget::{Query, QueryOrder, Render, StrictBuilder, Widget, WidgetBuilder, WidgetId, WidgetTree}, window::WindowId, }; @@ -84,8 +84,8 @@ impl Pipe { pub fn value_mut(&mut self) -> &mut V { &mut self.value } } -impl + 'static> WidgetBuilder for Pipe { - fn build(self, ctx: &BuildCtx) -> WidgetId { +impl + 'static> StrictBuilder for Pipe { + fn strict_build(self, ctx: &BuildCtx) -> WidgetId { let (v, modifies) = self.unzip(); let id = v.into().build(ctx); let id_share = Sc::new(Cell::new(id)); @@ -166,7 +166,7 @@ impl + 'static> WidgetBuilder for Pipe> { fn build(self, ctx: &crate::context::BuildCtx) -> WidgetId { self .map(|w| w.map_or_else(|| Widget::from(Void), |w| w.into())) - .build(ctx) + .strict_build(ctx) } } @@ -183,11 +183,11 @@ impl SingleParent for Pipe { } } -impl MultiParent for Pipe { +impl MultiParent for Pipe { fn append_children(self, children: Vec, ctx: &mut BuildCtx) -> WidgetId { // if children is empty, we can let the pipe parent as the whole subtree. if children.is_empty() { - self.build(ctx) + self.strict_build(ctx) } else { let (v, modifies) = self.unzip(); let first_child = children[0]; @@ -202,7 +202,7 @@ impl MultiParent for Pipe { } } -impl SingleParent for Pipe> { +impl + 'static> SingleParent for Pipe> { fn append_child(self, child: WidgetId, ctx: &mut BuildCtx) -> WidgetId { self .map(|p| -> Box { @@ -275,24 +275,20 @@ fn update_pipe_parent( attach_unsubscribe_guard(parent.start, ctx.window().id(), unsub); } -impl Pipe> { +impl Pipe { pub(crate) fn build_multi(self, vec: &mut Vec, ctx: &mut BuildCtx) where W: IntoIterator, - W::Item: Into, + W::Item: WidgetBuilder, { fn build_multi( - v: Multi>>, + v: impl IntoIterator, ctx: &mut BuildCtx, ) -> Vec { - let mut ids = v - .into_inner() - .into_iter() - .map(|w| w.into().build(ctx)) - .collect::>(); + let mut ids = v.into_iter().map(|w| w.build(ctx)).collect::>(); if ids.is_empty() { - ids.push(Void.build(ctx)); + ids.push(Void.strict_build(ctx)); } ids @@ -643,14 +639,13 @@ mod tests { @MockMulti { @ { pipe!($v.clone()).map(move |v| { - let iter = v.into_iter().map(move |_| { + v.into_iter().map(move |_| { @MockBox{ size: Size::zero(), on_mounted: move |_| *$new_cnt.write() += 1, on_disposed: move |_| *$drop_cnt.write() += 1 } - }); - Multi::new(iter) + }) }) } } @@ -733,7 +728,7 @@ mod tests { @MockMulti { @ { pipe!($v.clone()).map(move |v| { - let iter = v.into_iter().map(move |(i, c)| { + v.into_iter().map(move |(i, c)| { let mut key = @KeyWidget { key: i, value: c }; @$key { @MockBox { @@ -753,8 +748,7 @@ mod tests { } } } - }); - Multi::new(iter) + }) }) } } @@ -909,8 +903,7 @@ mod tests { let w = fn_widget! { @MockMulti { @ { pipe!{ - let iter = $c_tasks.iter().map(|t| build(t.clone_writer())).collect::>(); - Multi::new(iter) + $c_tasks.iter().map(|t| build(t.clone_writer())).collect::>() }} } }; diff --git a/core/src/state.rs b/core/src/state.rs index df30fae65..4f5b1e61d 100644 --- a/core/src/state.rs +++ b/core/src/state.rs @@ -17,7 +17,7 @@ pub use stateful::*; use crate::{ context::BuildCtx, prelude::{MultiChild, SingleChild}, - widget::{Compose, Render, WidgetBuilder, WidgetId}, + widget::{Compose, Render, StrictBuilder, WidgetId}, }; /// The `StateReader` trait allows for reading, clone and map the state. @@ -190,9 +190,9 @@ impl From> for Box { } } -impl WidgetBuilder for State { +impl StrictBuilder for State { #[inline] - fn build(self, ctx: &BuildCtx) -> WidgetId { Compose::compose(self).build(ctx) } + fn strict_build(self, ctx: &BuildCtx) -> WidgetId { Compose::compose(self).build(ctx) } } impl State { diff --git a/core/src/widget.rs b/core/src/widget.rs index 0bfc63387..e6b0b93c4 100644 --- a/core/src/widget.rs +++ b/core/src/widget.rs @@ -143,10 +143,36 @@ impl<'a> dyn Render + 'a { pub struct FnWidget(F); +/// Trait to build a type to a widget, `StrictBuilder` and `WidgetBuilder` is +/// only for type distinction and help us to build complex widget. +/// +/// +/// These type implement this trait: +/// +/// - type implemented `Compose` trait +/// - type implemented `Render` trait +/// - `ComposePair<_,_>` +/// - `SinglePair<_, _>` +/// - `MultiPair<_, _>` +/// - `Pipe` if `W` implement `LooseBuilder` +pub(crate) trait StrictBuilder { + fn strict_build(self, ctx: &BuildCtx) -> WidgetId; +} + +/// Trait to build a type to a widget and allow to create new widget in build +/// phase. +/// +/// - Types implemented `StrictBuilder` will auto implement `WidgetBuilder` +/// - `Pipe>` directly implement this trait. pub(crate) trait WidgetBuilder { fn build(self, ctx: &BuildCtx) -> WidgetId; } +impl> WidgetBuilder for T { + #[inline] + fn build(self, ctx: &BuildCtx) -> WidgetId { self.into().build(ctx) } +} + impl From for Widget { #[inline] fn from(id: WidgetId) -> Self { Widget(Box::new(move |_| id)) } @@ -156,7 +182,7 @@ impl FnWidget { #[inline] pub fn new(f: F) -> Self where - F: FnOnce(&BuildCtx) -> R + Into>, + F: FnOnce(&BuildCtx) -> R, { FnWidget(f) } @@ -165,12 +191,12 @@ impl FnWidget { pub fn into_inner(self) -> F { self.0 } } -impl WidgetBuilder for FnWidget +impl StrictBuilder for FnWidget where F: FnOnce(&BuildCtx) -> R + 'static, - R: Into, + R: WidgetBuilder, { - fn build(self, ctx: &BuildCtx) -> WidgetId { (self.0)(ctx).into().build(ctx) } + fn strict_build(self, ctx: &BuildCtx) -> WidgetId { (self.0)(ctx).build(ctx) } } #[macro_export] @@ -298,14 +324,14 @@ macro_rules! impl_proxy_render { }; } -impl WidgetBuilder for C { +impl StrictBuilder for C { #[inline] - fn build(self, ctx: &BuildCtx) -> WidgetId { State::value(self).build(ctx) } + fn strict_build(self, ctx: &BuildCtx) -> WidgetId { State::value(self).strict_build(ctx) } } -impl WidgetBuilder for Stateful { +impl StrictBuilder for Stateful { #[inline] - fn build(self, ctx: &BuildCtx) -> WidgetId { State::stateful(self).build(ctx) } + fn strict_build(self, ctx: &BuildCtx) -> WidgetId { State::stateful(self).strict_build(ctx) } } impl Compose for R { @@ -314,9 +340,9 @@ impl Compose for R { } } -impl From for Widget { +impl From for Widget { #[inline] - fn from(value: W) -> Self { Self(Box::new(|ctx| value.build(ctx))) } + fn from(value: W) -> Self { Self(Box::new(|ctx| value.strict_build(ctx))) } } impl From for FnWidget diff --git a/core/src/widget_children.rs b/core/src/widget_children.rs index 9f6c3079e..52d52bb14 100644 --- a/core/src/widget_children.rs +++ b/core/src/widget_children.rs @@ -29,7 +29,10 @@ //! clone, this seems too strict and if `A` is not support clone, the compile //! error is too complex to diagnostic. -use crate::{prelude::*, widget::WidgetBuilder}; +use crate::{ + prelude::*, + widget::{StrictBuilder, WidgetBuilder}, +}; mod compose_child_impl; mod multi_child_impl; mod single_child_impl; @@ -38,6 +41,7 @@ pub use multi_child_impl::*; pub use single_child_impl::*; pub mod child_convert; pub use child_convert::{ChildFrom, FromAnother}; + /// Trait to tell Ribir a object can have one child. pub trait SingleChild {} @@ -74,9 +78,9 @@ pub type WidgetOf = SinglePair; impl SingleChild for Box {} impl MultiChild for Box {} -impl WidgetBuilder for Box { +impl StrictBuilder for Box { #[inline] - fn build(self, ctx: &BuildCtx) -> WidgetId { self.boxed_build(ctx.force_as_mut()) } + fn strict_build(self, ctx: &BuildCtx) -> WidgetId { self.boxed_build(ctx.force_as_mut()) } } impl SingleParent for Box { @@ -86,9 +90,9 @@ impl SingleParent for Box { } } -impl WidgetBuilder for Box { +impl StrictBuilder for Box { #[inline] - fn build(self, ctx: &BuildCtx) -> WidgetId { self.boxed_build(ctx.force_as_mut()) } + fn strict_build(self, ctx: &BuildCtx) -> WidgetId { self.boxed_build(ctx.force_as_mut()) } } impl MultiParent for Box { @@ -98,26 +102,26 @@ impl MultiParent for Box { } } -pub(crate) trait SingleParent: WidgetBuilder { +pub(crate) trait SingleParent { fn append_child(self, child: WidgetId, ctx: &mut BuildCtx) -> WidgetId; } -pub(crate) trait MultiParent: WidgetBuilder { +pub(crate) trait MultiParent { fn append_children(self, children: Vec, ctx: &mut BuildCtx) -> WidgetId; } -impl> + SingleChild + WidgetBuilder> SingleParent for T { +impl> + SingleChild> SingleParent for T { fn append_child(self, child: WidgetId, ctx: &mut BuildCtx) -> WidgetId { - let p = self.build(ctx); + let p = ctx.alloc_widget(self.into()); ctx.append_child(p, child); p } } -impl> + MultiChild + WidgetBuilder> MultiParent for T { +impl> + MultiChild> MultiParent for T { #[inline] fn append_children(self, children: Vec, ctx: &mut BuildCtx) -> WidgetId { - let p = self.build(ctx); + let p = ctx.alloc_widget(self.into()); for c in children { ctx.append_child(p, c); } @@ -125,7 +129,7 @@ impl> + MultiChild + WidgetBuilder> MultiParent for T { } } -impl BoxedSingleParent for W { +impl BoxedSingleParent for W { #[inline] fn boxed_append_child(self: Box, child: WidgetId, ctx: &mut BuildCtx) -> WidgetId { (*self).append_child(child, ctx) @@ -135,7 +139,7 @@ impl BoxedSingleParent for W { fn boxed_build(self: Box, ctx: &mut BuildCtx) -> WidgetId { (*self).build(ctx) } } -impl BoxedMultiParent for W { +impl BoxedMultiParent for W { #[inline] fn boxed_append_children( self: Box, @@ -152,7 +156,7 @@ impl BoxedMultiParent for W { #[cfg(test)] mod tests { use super::*; - use crate::widget::WidgetBuilder; + use crate::widget::StrictBuilder; use crate::{reset_test_env, test_helper::*}; use ribir_dev_helper::*; @@ -332,7 +336,7 @@ mod tests { let _ = FnWidget::new(|ctx| { let child = MockBox { size: ZERO_SIZE }.with_child(Void, ctx); - X.with_child(child, ctx).build(ctx) + X.with_child(child, ctx).strict_build(ctx) }); } diff --git a/core/src/widget_children/child_convert.rs b/core/src/widget_children/child_convert.rs index 0fbe13af5..623e25c90 100644 --- a/core/src/widget_children/child_convert.rs +++ b/core/src/widget_children/child_convert.rs @@ -1,6 +1,7 @@ -use super::{ComposeChild, ComposePair, Multi, SinglePair}; +use super::{ComposeChild, ComposePair, SinglePair}; use crate::{ - builtin_widgets::FatObj, + builtin_widgets::{FatObj, Void}, + prelude::Pipe, state::{State, StateFrom}, widget::*, }; @@ -26,11 +27,19 @@ pub trait FromAnother { } // W -> Widget -impl FromAnother for Widget { +impl FromAnother for Widget { #[inline] fn from_another(value: W) -> Self { value.into() } } +impl + 'static> FromAnother>, ()> for Widget { + fn from_another(value: Pipe>) -> Self { + value + .map(|w| w.map_or_else(|| Widget::from(Void), |w| w.into())) + .into() + } +} + // W -> State // Stateful -> State // Stateful> -> State @@ -144,25 +153,11 @@ impl, M> FillVec for W { fn fill_vec(self, vec: &mut Vec) { vec.push(ChildFrom::child_from(self)) } } -impl FillVec for Option -where - C: ChildFrom, -{ - #[inline] - fn fill_vec(self, vec: &mut Vec) { - if let Some(w) = self { - vec.push(ChildFrom::child_from(w)) - } - } -} - -impl FillVec for Multi +impl FillVec for W where W: IntoIterator, C: ChildFrom, { #[inline] - fn fill_vec(self, vec: &mut Vec) { - vec.extend(self.into_inner().into_iter().map(ChildFrom::child_from)) - } + fn fill_vec(self, vec: &mut Vec) { vec.extend(self.into_iter().map(ChildFrom::child_from)) } } diff --git a/core/src/widget_children/compose_child_impl.rs b/core/src/widget_children/compose_child_impl.rs index 173d3bea6..bccc532e0 100644 --- a/core/src/widget_children/compose_child_impl.rs +++ b/core/src/widget_children/compose_child_impl.rs @@ -2,7 +2,7 @@ use crate::{ context::BuildCtx, prelude::ChildFrom, state::{State, Stateful}, - widget::{WidgetBuilder, WidgetId}, + widget::{StrictBuilder, WidgetId}, }; use super::{child_convert::FillVec, ComposeChild, SinglePair}; @@ -130,13 +130,13 @@ where } } -impl WidgetBuilder for ComposePair, C> +impl StrictBuilder for ComposePair, C> where W: ComposeChild, W::Child: From, { #[inline] - fn build(self, ctx: &BuildCtx) -> WidgetId { + fn strict_build(self, ctx: &BuildCtx) -> WidgetId { let Self { widget, child } = self; ComposeChild::compose_child(widget, child.into()).build(ctx) } @@ -201,7 +201,9 @@ mod tests { } #[test] - fn template_fill_template() { let _ = FnWidget::new(|ctx| P.with_child(Void, ctx).build(ctx)); } + fn template_fill_template() { + let _ = FnWidget::new(|ctx| P.with_child(Void, ctx).strict_build(ctx)); + } #[test] fn pair_compose_child() { @@ -209,7 +211,7 @@ mod tests { MockBox { size: ZERO_SIZE } .with_child(X, ctx) .with_child(Void {}, ctx) - .build(ctx) + .strict_build(ctx) }); } } diff --git a/core/src/widget_children/multi_child_impl.rs b/core/src/widget_children/multi_child_impl.rs index c69b66be1..11ba2db1d 100644 --- a/core/src/widget_children/multi_child_impl.rs +++ b/core/src/widget_children/multi_child_impl.rs @@ -1,9 +1,9 @@ use super::*; -use crate::widget::WidgetBuilder; +use crate::widget::StrictBuilder; /// Trait specify what child a multi child widget can have, and the target type /// after widget compose its child. -pub trait MultiWithChild { +pub trait MultiWithChild { type Target; fn with_child(self, child: C, ctx: &BuildCtx) -> Self::Target; } @@ -13,64 +13,44 @@ pub struct MultiPair

{ pub children: Vec, } -/// A struct hold multi object in it, as a representative of multiple children, -/// so the parent know combined children one by one in it. -pub struct Multi(W); - -impl Multi { - #[inline] - pub fn new(v: W) -> Self { Self(v) } - - #[inline] - pub fn into_inner(self) -> W { self.0 } -} - // Same with ChildConvert::FillVec, but only for MultiChild, // There are some duplicate implementations, but better compile error for -// users -trait FillVec { +// users and `MultiChild` support `pipe>` +// as child but `ComposeChild` not. +trait FillVec { fn fill_vec(self, vec: &mut Vec, ctx: &BuildCtx); } -impl> FillVec for W { +impl> FillVec<()> for W { #[inline] - fn fill_vec(self, vec: &mut Vec, ctx: &BuildCtx) { vec.push(self.into().build(ctx)) } -} - -impl> FillVec for Option { - #[inline] - fn fill_vec(self, vec: &mut Vec, ctx: &BuildCtx) { - if let Some(w) = self { - vec.push(w.into().build(ctx)) - } - } + fn fill_vec(self, vec: &mut Vec, ctx: &BuildCtx) { vec.push(self.build(ctx)) } } -impl FillVec for Multi +impl FillVec<[WidgetId; 0]> for W where W: IntoIterator, - W::Item: Into, + W::Item: WidgetBuilder, { #[inline] fn fill_vec(self, vec: &mut Vec, ctx: &BuildCtx) { - vec.extend(self.0.into_iter().map(|w| w.into().build(ctx))) + vec.extend(self.into_iter().map(|w| w.build(ctx))) } } -impl FillVec for Pipe> +impl FillVec<[(); 1]> for Pipe where D: IntoIterator + 'static, - D::Item: Into, + D::Item: WidgetBuilder, { fn fill_vec(self, vec: &mut Vec, ctx: &BuildCtx) { self.build_multi(vec, ctx.force_as_mut()); } } -impl MultiWithChild for P +impl MultiWithChild for P where P: MultiChild, - C: FillVec, + C: FillVec, { type Target = MultiPair

; @@ -81,9 +61,9 @@ where } } -impl MultiWithChild for MultiPair

+impl MultiWithChild for MultiPair

where - C: FillVec, + C: FillVec, { type Target = Self; #[inline] @@ -93,8 +73,8 @@ where } } -impl WidgetBuilder for MultiPair

{ - fn build(self, ctx: &BuildCtx) -> WidgetId { +impl StrictBuilder for MultiPair

{ + fn strict_build(self, ctx: &BuildCtx) -> WidgetId { let MultiPair { parent, children } = self; parent.append_children(children, ctx.force_as_mut()) } diff --git a/core/src/widget_children/single_child_impl.rs b/core/src/widget_children/single_child_impl.rs index 05d2d9306..7e32683ea 100644 --- a/core/src/widget_children/single_child_impl.rs +++ b/core/src/widget_children/single_child_impl.rs @@ -1,5 +1,5 @@ use super::*; -use crate::widget::WidgetBuilder; +use crate::widget::{StrictBuilder, WidgetBuilder}; /// Trait specify what child a widget can have, and the target type is the /// result of widget compose its child. @@ -47,42 +47,42 @@ impl SingleWithChild for SinglePair { } } -impl WidgetBuilder for SinglePair +impl StrictBuilder for SinglePair where W: SingleParent, - C: Into, + C: WidgetBuilder, { - fn build(self, ctx: &BuildCtx) -> WidgetId { + fn strict_build(self, ctx: &BuildCtx) -> WidgetId { let Self { widget, child } = self; - let child = child.into().build(ctx); + let child = child.build(ctx); widget.append_child(child, ctx.force_as_mut()) } } -impl WidgetBuilder for SinglePair, C> +impl StrictBuilder for SinglePair, C> where W: SingleParent, - C: Into, + C: WidgetBuilder, { - fn build(self, ctx: &BuildCtx) -> WidgetId { + fn strict_build(self, ctx: &BuildCtx) -> WidgetId { let Self { widget, child } = self; if let Some(widget) = widget { - SinglePair { widget, child }.build(ctx) + SinglePair { widget, child }.strict_build(ctx) } else { - child.into().build(ctx) + child.build(ctx) } } } -impl WidgetBuilder for SinglePair> +impl StrictBuilder for SinglePair> where - W: SingleParent, - SinglePair: WidgetBuilder, + W: SingleParent + WidgetBuilder, + SinglePair: StrictBuilder, { - fn build(self, ctx: &BuildCtx) -> WidgetId { + fn strict_build(self, ctx: &BuildCtx) -> WidgetId { let Self { widget, child } = self; if let Some(child) = child { - SinglePair { widget, child }.build(ctx) + SinglePair { widget, child }.strict_build(ctx) } else { widget.build(ctx) } @@ -103,7 +103,7 @@ mod tests { .clone() .with_child(mock_box.clone(), ctx) .with_child(mock_box, ctx) - .build(ctx) + .strict_build(ctx) }); } } diff --git a/core/src/widget_tree.rs b/core/src/widget_tree.rs index 74abdd978..7efaf0453 100644 --- a/core/src/widget_tree.rs +++ b/core/src/widget_tree.rs @@ -239,14 +239,13 @@ mod tests { @{ pipe!(($this.width, $this.depth)) .map(|(width, depth)| { - let iter = (0..width).map(move |_| -> Widget { + (0..width).map(move |_| -> Widget { if depth > 1 { Recursive { width, depth: depth - 1 }.into() } else { MockBox { size: Size::new(10., 10.)}.into() } - }); - Multi::new(iter) + }) }) } } @@ -273,9 +272,8 @@ mod tests { }; @MockMulti { @{ pipe!{ - let leafs = (0..$this.width - 1) - .map(|_| MockBox { size: Size::new(10., 10.)} ); - Multi::new(leafs) + (0..$this.width - 1) + .map(|_| MockBox { size: Size::new(10., 10.)}) }} @{ recursive_child } } @@ -507,7 +505,7 @@ mod tests { } else { Size::zero() }; - Multi::new((0..3).map(move |_| MockBox { size })) + (0..3).map(move |_| MockBox { size }) }) } } @@ -531,11 +529,11 @@ mod tests { let w1 = fn_widget! { @MockMulti { @ { - Multi::new((0..100).map(|_| + (0..100).map(|_| widget! { MockBox { size: Size::new(150., 50.), background: Color::BLUE, - }})) + }}) } }}; let mut wnd = TestWindow::new_with_size(w1, win_size); @@ -546,11 +544,11 @@ mod tests { let w2 = fn_widget! { @MockMulti { @ { - Multi::new((0..1).map(|_| + (0..1).map(|_| widget! { MockBox { size: Size::new(150., 50.), background: Color::BLUE, - }})) + }}) } }}; diff --git a/examples/messages/src/messages.rs b/examples/messages/src/messages.rs index d02212b3d..58b11aef7 100644 --- a/examples/messages/src/messages.rs +++ b/examples/messages/src/messages.rs @@ -99,7 +99,7 @@ impl Compose for MessageList { } }; - Multi::new($this.messages.clone().into_iter().map(message_gen)) + $this.messages.clone().into_iter().map(message_gen) } } } diff --git a/examples/todos/src/todos.rs b/examples/todos/src/todos.rs index 24c89721f..39dba9f33 100644 --- a/examples/todos/src/todos.rs +++ b/examples/todos/src/todos.rs @@ -77,7 +77,7 @@ impl Todos { on_performed_layout: move |_| *$mount_task_cnt.write() = 0, padding: EdgeInsets::vertical(8.), @ { - let task_widget_iter = $this + $this .tasks .iter() .enumerate() @@ -124,8 +124,7 @@ impl Todos { } } } - }).collect::>(); - Multi::new(task_widget_iter) + }).collect::>() } } diff --git a/tests/rdl_macro_test.rs b/tests/rdl_macro_test.rs index 711ad0eaa..c706d133f 100644 --- a/tests/rdl_macro_test.rs +++ b/tests/rdl_macro_test.rs @@ -293,7 +293,7 @@ fn pipe_as_multi_child() { let cnt2 = cnt.clone_writer(); let w = fn_widget! { let boxes = pipe! { - Multi::new((0..*$cnt).map(|_| fix_box.clone()).collect::>()) + (0..*$cnt).map(|_| fix_box.clone()).collect::>() }; rdl! { Flex { rdl!{ boxes } } } }; @@ -377,9 +377,9 @@ fn closure_in_fn_widget_capture() { fn at_embed_in_expression() -> impl Into { fn_widget! { @Row { - @{ Multi::new((0..3).map(|_| { - @SizedBox { size: Size::new(100., 100.) } - }))} + @{ (0..3).map(|_| { + @SizedBox { size: Size::new(100., 100.) } + })} } } } @@ -489,7 +489,7 @@ fn expression_for_children() { let size_five = Size::new(5., 5.); let embed_expr = fn_widget! { let sized_box = @SizedBox { size: size_one }; - let multi_box = Multi::new((0..3).map(move |_| @SizedBox { size: pipe!($sized_box.size) } )) + let multi_box = (0..3).map(move |_| @SizedBox { size: pipe!($sized_box.size) }) ; let pipe_box = pipe!($sized_box.size.area() > 2.) .map(move |v| v.then(|| @SizedBox { size: pipe!($sized_box.size) })); @@ -527,7 +527,7 @@ fn embed_widget_ref_outside() { let w = fn_widget! { let first = @SizedBox { size: Size::new(1., 1.) }; - let three_box = @{ Multi::new((0..3).map(move |_| @ SizedBox { size: pipe!($first.size) } ))}; + let three_box = @{ (0..3).map(move |_| @ SizedBox { size: pipe!($first.size) } )}; @Flex { @$first { on_tap: move |_| $first.write().size = Size::new(2., 2.)} @{ three_box } @@ -556,7 +556,7 @@ fn bind_fields() { .subscribe(move |v| $c.write().size = v); @Flex { on_tap: move |_| $a.write().size *= 2., - @ { Multi::new([a, b, c]) } + @ { [a, b, c] } } }; let mut wnd = TestWindow::new(w); diff --git a/widgets/src/checkbox.rs b/widgets/src/checkbox.rs index d59e8d3fb..04b102222 100644 --- a/widgets/src/checkbox.rs +++ b/widgets/src/checkbox.rs @@ -89,10 +89,10 @@ impl ComposeChild for Checkbox { @Row { @ { - Multi::new(match child { + match child { CheckboxTemplate::Before(w) => [ label(w.child()), icon ], CheckboxTemplate::After(w) => [ icon, label(w.child())], - }) + } } }.into() } else { diff --git a/widgets/src/input/selected_text.rs b/widgets/src/input/selected_text.rs index 76238a413..797b5ac2b 100644 --- a/widgets/src/input/selected_text.rs +++ b/widgets/src/input/selected_text.rs @@ -25,15 +25,14 @@ impl Compose for SelectedText { @Stack { @ { pipe!{ let color = color.clone(); - let iter = $this.rects.clone().into_iter().map(move |rc| { + $this.rects.clone().into_iter().map(move |rc| { @Container { background: color.clone(), top_anchor: rc.origin.y, left_anchor: rc.origin.x, size: rc.size, } - }); - Multi::new(iter) + }) }} } } diff --git a/widgets/src/layout/flex.rs b/widgets/src/layout/flex.rs index 3658f814f..904a109e0 100644 --- a/widgets/src/layout/flex.rs +++ b/widgets/src/layout/flex.rs @@ -427,7 +427,7 @@ mod tests { fn_widget! { @Flex { @{ - Multi::new((0..10).map(|_| SizedBox { size: Size::new(10., 20.) })) + (0..10).map(|_| SizedBox { size: Size::new(10., 20.) }) } } } @@ -439,7 +439,7 @@ mod tests { fn_widget! { @Flex { direction: Direction::Vertical, - @{ Multi::new((0..10).map(|_| SizedBox { size: Size::new(10., 20.) }))} + @{ (0..10).map(|_| SizedBox { size: Size::new(10., 20.) })} } } .into() @@ -451,7 +451,7 @@ mod tests { fn_widget! { @Flex { wrap: true, - @{ Multi::new((0..3).map(|_| SizedBox { size })) } + @{ (0..3).map(|_| SizedBox { size }) } } } .into() @@ -471,7 +471,7 @@ mod tests { @Flex { wrap: true, reverse: true, - @{ Multi::new((0..3).map(|_| SizedBox { size })) } + @{ (0..3).map(|_| SizedBox { size }) } } } .into() @@ -560,7 +560,7 @@ mod tests { wrap: true, cross_axis_gap: 10., align_items: Align::Center, - @{ Multi::new((0..3).map(|_| SizedBox { size })) } + @{ (0..3).map(|_| SizedBox { size }) } } } .into() diff --git a/widgets/src/lists.rs b/widgets/src/lists.rs index b1ea2ebc0..77cff6007 100644 --- a/widgets/src/lists.rs +++ b/widgets/src/lists.rs @@ -138,9 +138,7 @@ impl ComposeChild for Lists { fn compose_child(_: State, child: Self::Child) -> Widget { fn_widget! { @ListsDecorator { - @Column { - @ { Multi::new(child) } - } + @Column { @ { child } } } } .into() diff --git a/widgets/src/tabs.rs b/widgets/src/tabs.rs index 930c1d7e1..43f7ac3be 100644 --- a/widgets/src/tabs.rs +++ b/widgets/src/tabs.rs @@ -309,14 +309,12 @@ impl ComposeChild for Tabs { Position::Left | Position::Right => BoxClamp::fixed_width(extent), }), @ $flex { - @ { - Multi::new( + @{ Tabs::tab_header( headers, tabs_style, this.clone_writer(), indicator_decorator.clone_writer() ) - ) } } } @@ -349,7 +347,7 @@ impl ComposeChild for Tabs { matches!(pos, Position::Right | Position::Bottom) }, @ { header } - @ { Multi::new(panes) } + @ { panes } } } }