From 2968317aef19694ffd23480cb7092c5b07008a5b Mon Sep 17 00:00:00 2001 From: Adoo Date: Sat, 13 Jul 2024 23:02:38 +0800 Subject: [PATCH] =?UTF-8?q?refactor(core):=20=F0=9F=92=A1=20remove=20all?= =?UTF-8?q?=20widget=20builder=20traits?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 10 +- core/src/animation/stagger.rs | 2 +- core/src/builtin_widgets.rs | 45 ++-- core/src/builtin_widgets/align.rs | 20 +- core/src/builtin_widgets/anchor.rs | 8 +- core/src/builtin_widgets/box_decoration.rs | 2 +- core/src/builtin_widgets/container.rs | 2 +- core/src/builtin_widgets/cursor.rs | 2 +- core/src/builtin_widgets/fitted_box.rs | 2 +- core/src/builtin_widgets/focus_node.rs | 4 +- core/src/builtin_widgets/focus_scope.rs | 6 +- core/src/builtin_widgets/global_anchor.rs | 7 +- core/src/builtin_widgets/has_focus.rs | 2 +- core/src/builtin_widgets/keep_alive.rs | 8 +- core/src/builtin_widgets/key.rs | 6 +- core/src/builtin_widgets/layout_box.rs | 4 +- core/src/builtin_widgets/margin.rs | 2 +- core/src/builtin_widgets/mix_builtin.rs | 2 +- core/src/builtin_widgets/mouse_hover.rs | 2 +- core/src/builtin_widgets/padding.rs | 2 +- core/src/builtin_widgets/pointer_pressed.rs | 4 +- core/src/builtin_widgets/scrollable.rs | 4 +- core/src/builtin_widgets/theme.rs | 4 +- .../theme/compose_decorators.rs | 8 +- core/src/builtin_widgets/theme/icon_theme.rs | 2 +- core/src/builtin_widgets/transform_widget.rs | 2 +- core/src/builtin_widgets/unconstrained_box.rs | 2 +- core/src/builtin_widgets/visibility.rs | 2 +- core/src/context/app_ctx.rs | 6 +- core/src/context/build_ctx.rs | 2 +- core/src/events/dispatcher.rs | 6 +- core/src/events/focus_mgr.rs | 8 +- core/src/events/keyboard.rs | 2 +- core/src/overlay.rs | 4 +- core/src/pipe.rs | 80 +----- core/src/state.rs | 63 +---- core/src/state/map_state.rs | 23 +- core/src/state/splitted_state.rs | 24 +- core/src/state/stateful.rs | 46 +--- core/src/test_helper.rs | 6 +- core/src/widget.rs | 124 +-------- core/src/widget_children.rs | 44 ++-- core/src/widget_children/child_convert.rs | 29 ++- .../src/widget_children/compose_child_impl.rs | 244 +++++++++--------- core/src/widget_children/multi_child_impl.rs | 12 +- core/src/widget_tree/layout_info.rs | 4 +- core/src/window.rs | 4 +- dev-helper/src/widget_test.rs | 8 +- docs/en/get_started/quick_start.md | 4 +- .../practice_todos_app/develop_a_todos_app.md | 8 +- docs/zh/get_started/quick_start.md | 4 +- .../practice_todos_app/develop_a_todos_app.md | 8 +- examples/counter/src/lib.rs | 2 +- examples/messages/src/messages.rs | 4 +- examples/storybook/src/storybook.rs | 4 +- examples/todos/src/ui.rs | 14 +- examples/wordle_game/src/ui.rs | 6 +- macros/src/child_template.rs | 25 +- ribir/src/app.rs | 18 +- tests/benches/core_bench.rs | 4 +- tests/benches/widgets_bench.rs | 2 +- tests/child_template_derive_test.rs | 6 +- tests/path_child_test.rs | 6 +- tests/rdl_macro_test.rs | 46 ++-- themes/material/src/lib.rs | 14 +- themes/material/src/ripple.rs | 2 +- themes/material/src/state_layer.rs | 4 +- widgets/src/avatar.rs | 4 +- widgets/src/buttons.rs | 2 +- widgets/src/buttons/button.rs | 4 +- widgets/src/buttons/fab_button.rs | 4 +- widgets/src/buttons/filled_button.rs | 4 +- widgets/src/buttons/outlined_button.rs | 4 +- widgets/src/checkbox.rs | 18 +- widgets/src/icon.rs | 4 +- widgets/src/input.rs | 6 +- widgets/src/input/caret.rs | 2 +- widgets/src/input/selected_text.rs | 2 +- widgets/src/input/text_selectable.rs | 6 +- widgets/src/layout/constrained_box.rs | 6 +- widgets/src/layout/expanded.rs | 8 +- widgets/src/layout/flex.rs | 42 +-- widgets/src/layout/sized_box.rs | 8 +- widgets/src/layout/stack.rs | 2 +- widgets/src/link.rs | 2 +- widgets/src/lists.rs | 8 +- widgets/src/scrollbar.rs | 16 +- widgets/src/tabs.rs | 8 +- widgets/src/text.rs | 2 +- widgets/src/text_field.rs | 8 +- widgets/src/transform_box.rs | 2 +- 91 files changed, 485 insertions(+), 773 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dcb7ec746..3f286b475 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -44,11 +44,11 @@ Please only add new entries below the [Unreleased](#unreleased---releasedate) he ### Breaking -- Remove `ChildFrom` and `FromAnother` traits (#pr, @M-Adoo) -- Remove `SingleParent` and `MultiParent` traits. (#pr, @M-Adoo) -- Remove `PairChild` and `PairWithChild` traits. User can use a generic type instead. (#pr, @M-Adoo) -- Allow only the child to be converted to a widget or a type that implements the Into trait. (#pr, @M-Adoo) - +- Removed `ChildFrom` and `FromAnother` traits (#pr @M-Adoo) +- Removed `SingleParent` and `MultiParent` traits. (#pr @M-Adoo) +- Removed `PairChild` and `PairWithChild` traits. User can use a generic type instead. (#pr @M-Adoo) +- Allow only the child to be converted to a widget or a type that implements the Into trait. (#pr @M-Adoo) +- Removed the all builder traits such as WidgetBuilder and ComposeBuilder and so on. (#pr @M-Adoo) ## [0.4.0-alpha.3] - 2024-06-26 diff --git a/core/src/animation/stagger.rs b/core/src/animation/stagger.rs index aaab410ea..9938bcfe6 100644 --- a/core/src/animation/stagger.rs +++ b/core/src/animation/stagger.rs @@ -225,7 +225,7 @@ mod tests { use super::*; use crate::{reset_test_env, test_helper::*}; - fn stagger_run_and_stop() -> impl WidgetBuilder { + fn stagger_run_and_stop() -> impl IntoWidgetStrict { fn_widget! { let stagger = Stagger::new(Duration::from_millis(100), transitions::EASE_IN.of(ctx!())); let mut mock_box = @MockBox { size: Size::new(100., 100.) }; diff --git a/core/src/builtin_widgets.rs b/core/src/builtin_widgets.rs index 3342a3bdc..e4125f942 100644 --- a/core/src/builtin_widgets.rs +++ b/core/src/builtin_widgets.rs @@ -94,7 +94,7 @@ pub struct LazyWidgetId(Sc>>); /// let w = multi.get_margin_widget().clone_writer(); /// multi /// .on_tap(move |_| w.write().margin = EdgeInsets::all(20.)) -/// .build(ctx) +/// .into_widget(ctx) /// }; /// ``` pub struct FatObj { @@ -845,21 +845,6 @@ impl ObjDeclarer for FatObj { fn finish(self, _: &BuildCtx) -> Self::Target { self } } -crate::widget::multi_build_replace_impl! { - impl {#} for FatObj { - #[track_caller] - fn build(self, ctx: &BuildCtx) -> Widget { - self.map(|host| host.build(ctx)).build(ctx) - } - } -} - -impl WidgetBuilder for FatObj { - #[inline] - #[track_caller] - fn build(self, ctx: &BuildCtx) -> Widget { self.into_widget_strict(ctx) } -} - impl IntoWidgetStrict for FatObj where T: IntoWidget, @@ -869,19 +854,23 @@ where let mut host = self.host.into_widget(ctx); self.host_id.set(host.id()); if let Some(mix_builtin) = self.mix_builtin { - host = mix_builtin.with_child(host, ctx).build(ctx) + host = mix_builtin.with_child(host, ctx).into_widget(ctx) } if let Some(request_focus) = self.request_focus { - host = request_focus.with_child(host, ctx).build(ctx); + host = request_focus + .with_child(host, ctx) + .into_widget(ctx); } if let Some(has_focus) = self.has_focus { - host = has_focus.with_child(host, ctx).build(ctx); + host = has_focus.with_child(host, ctx).into_widget(ctx); } if let Some(mouse_hover) = self.mouse_hover { - host = mouse_hover.with_child(host, ctx).build(ctx); + host = mouse_hover.with_child(host, ctx).into_widget(ctx); } if let Some(pointer_pressed) = self.pointer_pressed { - host = pointer_pressed.with_child(host, ctx).build(ctx); + host = pointer_pressed + .with_child(host, ctx) + .into_widget(ctx); } if let Some(fitted_box) = self.fitted_box { host = fitted_box.with_child(host, ctx).into_widget(ctx); @@ -895,16 +884,16 @@ where host = padding.with_child(host, ctx).into_widget(ctx); } if let Some(layout_box) = self.layout_box { - host = layout_box.with_child(host, ctx).build(ctx); + host = layout_box.with_child(host, ctx).into_widget(ctx); } if let Some(cursor) = self.cursor { - host = cursor.with_child(host, ctx).build(ctx); + host = cursor.with_child(host, ctx).into_widget(ctx); } if let Some(margin) = self.margin { host = margin.with_child(host, ctx).into_widget(ctx); } if let Some(scrollable) = self.scrollable { - host = scrollable.with_child(host, ctx).build(ctx); + host = scrollable.with_child(host, ctx).into_widget(ctx); } if let Some(transform) = self.transform { host = transform.with_child(host, ctx).into_widget(ctx); @@ -921,16 +910,18 @@ where .into_widget(ctx); } if let Some(global_anchor) = self.global_anchor { - host = global_anchor.with_child(host, ctx).build(ctx); + host = global_anchor + .with_child(host, ctx) + .into_widget(ctx); } if let Some(visibility) = self.visibility { - host = visibility.with_child(host, ctx).build(ctx); + host = visibility.with_child(host, ctx).into_widget(ctx); } if let Some(opacity) = self.opacity { host = opacity.with_child(host, ctx).into_widget(ctx); } if let Some(keep_alive) = self.keep_alive { - host = keep_alive.with_child(host, ctx).build(ctx); + host = keep_alive.with_child(host, ctx).into_widget(ctx); } if let Some(h) = self.keep_alive_unsubscribe_handle { let arena = &mut ctx.tree.borrow_mut().arena; diff --git a/core/src/builtin_widgets/align.rs b/core/src/builtin_widgets/align.rs index 8a3bd819e..386130704 100644 --- a/core/src/builtin_widgets/align.rs +++ b/core/src/builtin_widgets/align.rs @@ -168,7 +168,7 @@ mod tests { const CHILD_SIZE: Size = Size::new(10., 10.); const WND_SIZE: Size = Size::new(100., 100.); - fn h_align(h_align: HAlign) -> impl WidgetBuilder { + fn h_align(h_align: HAlign) -> impl IntoWidgetStrict { fn_widget! { @HAlignWidget { h_align, @@ -176,7 +176,7 @@ mod tests { } } } - fn left_align() -> impl WidgetBuilder { h_align(HAlign::Left) } + fn left_align() -> impl IntoWidgetStrict { h_align(HAlign::Left) } widget_layout_test!( left_align, wnd_size = WND_SIZE, @@ -184,7 +184,7 @@ mod tests { { path = [0, 0], size == CHILD_SIZE, } ); - fn h_center_align() -> impl WidgetBuilder { h_align(HAlign::Center) } + fn h_center_align() -> impl IntoWidgetStrict { h_align(HAlign::Center) } widget_layout_test!( h_center_align, wnd_size = WND_SIZE, @@ -192,7 +192,7 @@ mod tests { { path = [0, 0], x == 45., size == CHILD_SIZE,} ); - fn right_align() -> impl WidgetBuilder { h_align(HAlign::Right) } + fn right_align() -> impl IntoWidgetStrict { h_align(HAlign::Right) } widget_layout_test!( right_align, wnd_size = WND_SIZE, @@ -200,7 +200,7 @@ mod tests { { path = [0, 0], x == 90., size == CHILD_SIZE,} ); - fn h_stretch_algin() -> impl WidgetBuilder { h_align(HAlign::Stretch) } + fn h_stretch_algin() -> impl IntoWidgetStrict { h_align(HAlign::Stretch) } widget_layout_test!( h_stretch_algin, wnd_size = WND_SIZE, @@ -208,7 +208,7 @@ mod tests { { path = [0, 0], x == 0., width == 100., height == 10.,} ); - fn v_align(v_align: VAlign) -> impl WidgetBuilder { + fn v_align(v_align: VAlign) -> impl IntoWidgetStrict { fn_widget! { @VAlignWidget { v_align, @@ -217,7 +217,7 @@ mod tests { } } - fn top_align() -> impl WidgetBuilder { v_align(VAlign::Top) } + fn top_align() -> impl IntoWidgetStrict { v_align(VAlign::Top) } widget_layout_test!( top_align, wnd_size = WND_SIZE, @@ -225,7 +225,7 @@ mod tests { { path = [0, 0], size == CHILD_SIZE,} ); - fn v_center_align() -> impl WidgetBuilder { v_align(VAlign::Center) } + fn v_center_align() -> impl IntoWidgetStrict { v_align(VAlign::Center) } widget_layout_test!( v_center_align, wnd_size = WND_SIZE, @@ -233,7 +233,7 @@ mod tests { { path = [0, 0], y == 45., size == CHILD_SIZE,} ); - fn bottom_align() -> impl WidgetBuilder { v_align(VAlign::Bottom) } + fn bottom_align() -> impl IntoWidgetStrict { v_align(VAlign::Bottom) } widget_layout_test!( bottom_align, wnd_size = WND_SIZE, @@ -241,7 +241,7 @@ mod tests { { path = [0, 0], y == 90., size == CHILD_SIZE,} ); - fn v_stretch_align() -> impl WidgetBuilder { v_align(VAlign::Stretch) } + fn v_stretch_align() -> impl IntoWidgetStrict { v_align(VAlign::Stretch) } widget_layout_test!( v_stretch_align, wnd_size = WND_SIZE, diff --git a/core/src/builtin_widgets/anchor.rs b/core/src/builtin_widgets/anchor.rs index 22aa36e24..1e0d1ba9b 100644 --- a/core/src/builtin_widgets/anchor.rs +++ b/core/src/builtin_widgets/anchor.rs @@ -205,7 +205,7 @@ mod test { const CHILD_SIZE: Size = Size::new(50., 50.); const WND_SIZE: Size = Size::new(100., 100.); - fn pixel_left_top() -> impl WidgetBuilder { + fn pixel_left_top() -> impl IntoWidgetStrict { fn_widget! { @MockBox { size: CHILD_SIZE, @@ -220,7 +220,7 @@ mod test { { path = [0, 0], x == 1., } ); - fn pixel_left_bottom() -> impl WidgetBuilder { + fn pixel_left_bottom() -> impl IntoWidgetStrict { fn_widget! { @MockBox { size: CHILD_SIZE, @@ -235,7 +235,7 @@ mod test { { path = [0, 0], x == 1., } ); - fn pixel_top_right() -> impl WidgetBuilder { + fn pixel_top_right() -> impl IntoWidgetStrict { fn_widget! { @MockBox { size: CHILD_SIZE, @@ -250,7 +250,7 @@ mod test { { path = [0, 0], x == 49.,} ); - fn pixel_bottom_right() -> impl WidgetBuilder { + fn pixel_bottom_right() -> impl IntoWidgetStrict { fn_widget! { @MockBox { size: CHILD_SIZE, diff --git a/core/src/builtin_widgets/box_decoration.rs b/core/src/builtin_widgets/box_decoration.rs index 5be1cad5e..fa963edf7 100644 --- a/core/src/builtin_widgets/box_decoration.rs +++ b/core/src/builtin_widgets/box_decoration.rs @@ -196,7 +196,7 @@ mod tests { } const SIZE: Size = Size::new(100., 100.); - fn with_border() -> impl WidgetBuilder { + fn with_border() -> impl IntoWidgetStrict { fn_widget! { @MockBox { size: SIZE, diff --git a/core/src/builtin_widgets/container.rs b/core/src/builtin_widgets/container.rs index 38db90e4f..16cae96aa 100644 --- a/core/src/builtin_widgets/container.rs +++ b/core/src/builtin_widgets/container.rs @@ -31,7 +31,7 @@ mod tests { use crate::test_helper::*; const SIZE: Size = Size::new(100., 100.); - fn smoke() -> impl WidgetBuilder { + fn smoke() -> impl IntoWidgetStrict { fn_widget! { @Container { size: SIZE }} } widget_layout_test!(smoke, size == SIZE,); diff --git a/core/src/builtin_widgets/cursor.rs b/core/src/builtin_widgets/cursor.rs index 73af27c35..ffa668d30 100644 --- a/core/src/builtin_widgets/cursor.rs +++ b/core/src/builtin_widgets/cursor.rs @@ -15,7 +15,7 @@ impl Declare for Cursor { impl ComposeChild for Cursor { type Child = Widget; - fn compose_child(this: impl StateWriter, child: Self::Child) -> impl WidgetBuilder { + fn compose_child(this: impl StateWriter, child: Self::Child) -> impl IntoWidgetStrict { fn_widget! { let save_cursor: Stateful> = Stateful::new(None); @$child { diff --git a/core/src/builtin_widgets/fitted_box.rs b/core/src/builtin_widgets/fitted_box.rs index b73dd23a6..0430ea0f9 100644 --- a/core/src/builtin_widgets/fitted_box.rs +++ b/core/src/builtin_widgets/fitted_box.rs @@ -189,7 +189,7 @@ mod tests { .test(); } - fn as_builtin_field() -> impl WidgetBuilder { + fn as_builtin_field() -> impl IntoWidgetStrict { fn_widget! { @MockBox { size: Size::new(200., 200.), diff --git a/core/src/builtin_widgets/focus_node.rs b/core/src/builtin_widgets/focus_node.rs index 8995c02f4..dae91e759 100644 --- a/core/src/builtin_widgets/focus_node.rs +++ b/core/src/builtin_widgets/focus_node.rs @@ -13,7 +13,7 @@ impl Declare for RequestFocus { impl ComposeChild for RequestFocus { type Child = Widget; - fn compose_child(this: impl StateWriter, child: Self::Child) -> impl WidgetBuilder { + fn compose_child(this: impl StateWriter, child: Self::Child) -> impl IntoWidgetStrict { fn_widget! { @$child { on_mounted: move |e| { @@ -21,7 +21,7 @@ impl ComposeChild for RequestFocus { $this.silent().handle = Some(handle); } } - .build(ctx!()) + .into_widget(ctx!()) .try_unwrap_state_and_attach(this, ctx!()) } } diff --git a/core/src/builtin_widgets/focus_scope.rs b/core/src/builtin_widgets/focus_scope.rs index 37824674b..38a9c7339 100644 --- a/core/src/builtin_widgets/focus_scope.rs +++ b/core/src/builtin_widgets/focus_scope.rs @@ -16,13 +16,15 @@ pub struct FocusScope { impl ComposeChild for FocusScope { type Child = Widget; - fn compose_child(this: impl StateWriter, child: Self::Child) -> impl WidgetBuilder { + fn compose_child( + this: impl StateWriter, child: Self::Child, + ) -> impl IntoWidgetStrict { fn_widget! { @ $child { on_mounted: move |e| e.window().add_focus_node(e.id, false, FocusType::Scope), on_disposed: move|e| e.window().remove_focus_node(e.id, FocusType::Scope), } - .build(ctx!()) + .into_widget(ctx!()) .try_unwrap_state_and_attach(this, ctx!()) } } diff --git a/core/src/builtin_widgets/global_anchor.rs b/core/src/builtin_widgets/global_anchor.rs index 5ae17094c..f8e6fcb3a 100644 --- a/core/src/builtin_widgets/global_anchor.rs +++ b/core/src/builtin_widgets/global_anchor.rs @@ -15,8 +15,9 @@ impl Declare for GlobalAnchor { impl ComposeChild for GlobalAnchor { type Child = Widget; - #[inline] - fn compose_child(this: impl StateWriter, child: Self::Child) -> impl WidgetBuilder { + fn compose_child( + this: impl StateWriter, child: Self::Child, + ) -> impl IntoWidgetStrict { fn_widget! { let wnd = ctx!().window(); let tick_of_layout_ready = wnd @@ -177,7 +178,7 @@ mod tests { use crate::test_helper::*; const WND_SIZE: Size = Size::new(100., 100.); - fn global_anchor() -> impl WidgetBuilder { + fn global_anchor() -> impl IntoWidgetStrict { fn_widget! { let parent = @MockBox { anchor: Anchor::left_top(10., 10.), diff --git a/core/src/builtin_widgets/has_focus.rs b/core/src/builtin_widgets/has_focus.rs index fe44014ad..f07f1601b 100644 --- a/core/src/builtin_widgets/has_focus.rs +++ b/core/src/builtin_widgets/has_focus.rs @@ -16,7 +16,7 @@ impl Declare for HasFocus { impl ComposeChild for HasFocus { type Child = Widget; - fn compose_child(this: impl StateWriter, child: Self::Child) -> impl WidgetBuilder { + fn compose_child(this: impl StateWriter, child: Self::Child) -> impl IntoWidgetStrict { fn_widget! { @ $child { on_focus_in: move|_| $this.write().focused = true, diff --git a/core/src/builtin_widgets/keep_alive.rs b/core/src/builtin_widgets/keep_alive.rs index a17e6f96b..255259f18 100644 --- a/core/src/builtin_widgets/keep_alive.rs +++ b/core/src/builtin_widgets/keep_alive.rs @@ -26,7 +26,9 @@ impl Declare for KeepAlive { impl ComposeChild for KeepAlive { type Child = Widget; #[inline] - fn compose_child(this: impl StateWriter, child: Self::Child) -> impl WidgetBuilder { + fn compose_child( + this: impl StateWriter, child: Self::Child, + ) -> impl IntoWidgetStrict { fn_widget! { let modifies = this.raw_modifies(); child.try_unwrap_state_and_attach(this, ctx!()).dirty_subscribe(modifies, ctx!()) @@ -52,11 +54,11 @@ mod tests { let mut wnd = TestWindow::new(fn_widget! { pipe! { if *$remove_widget { - Void.build(ctx!()) + Void.into_widget(ctx!()) } else { FatObj::new(Void) .keep_alive(pipe!(*$keep_alive)) - .build(ctx!()) + .into_widget(ctx!()) } } }); diff --git a/core/src/builtin_widgets/key.rs b/core/src/builtin_widgets/key.rs index e4e0ccfd7..db2ffa8cc 100644 --- a/core/src/builtin_widgets/key.rs +++ b/core/src/builtin_widgets/key.rs @@ -124,10 +124,12 @@ where impl ComposeChild for KeyWidget { type Child = Widget; #[inline] - fn compose_child(this: impl StateWriter, child: Self::Child) -> impl WidgetBuilder { + fn compose_child( + this: impl StateWriter, child: Self::Child, + ) -> impl IntoWidgetStrict { fn_widget! { let data: Box = Box::new(this); - child.attach_data(Queryable(data), ctx!()).build(ctx!()) + child.attach_data(Queryable(data), ctx!()).into_widget(ctx!()) } } } diff --git a/core/src/builtin_widgets/layout_box.rs b/core/src/builtin_widgets/layout_box.rs index 647958c1c..d0dd1a2a9 100644 --- a/core/src/builtin_widgets/layout_box.rs +++ b/core/src/builtin_widgets/layout_box.rs @@ -15,7 +15,7 @@ impl Declare for LayoutBox { impl ComposeChild for LayoutBox { type Child = Widget; - fn compose_child(this: impl StateWriter, child: Self::Child) -> impl WidgetBuilder { + fn compose_child(this: impl StateWriter, child: Self::Child) -> impl IntoWidgetStrict { fn_widget! { @ $child { on_performed_layout: move |e| { @@ -66,7 +66,7 @@ mod tests { use super::*; use crate::test_helper::*; - fn smoke() -> impl WidgetBuilder { + fn smoke() -> impl IntoWidgetStrict { fn_widget! { let mut first_box = @MockBox { size: Size::new(100., 200.) }; let second_box = @MockBox { size: pipe!($first_box.layout_size()) }; diff --git a/core/src/builtin_widgets/margin.rs b/core/src/builtin_widgets/margin.rs index a3199ede9..b3d17e0ac 100644 --- a/core/src/builtin_widgets/margin.rs +++ b/core/src/builtin_widgets/margin.rs @@ -114,7 +114,7 @@ mod tests { use super::*; use crate::test_helper::*; - fn smoke() -> impl WidgetBuilder { + fn smoke() -> impl IntoWidgetStrict { fn_widget! { @MockBox { margin: EdgeInsets::symmetrical(1., 1.), diff --git a/core/src/builtin_widgets/mix_builtin.rs b/core/src/builtin_widgets/mix_builtin.rs index a1a6349c5..1437be98e 100644 --- a/core/src/builtin_widgets/mix_builtin.rs +++ b/core/src/builtin_widgets/mix_builtin.rs @@ -351,7 +351,7 @@ impl ComposeChild for MixBuiltin { #[inline] fn compose_child( this: impl StateWriter, mut child: Self::Child, - ) -> impl WidgetBuilder { + ) -> impl IntoWidgetStrict { move |ctx: &BuildCtx| match this.try_into_value() { Ok(this) => { let mut this = Some(this); diff --git a/core/src/builtin_widgets/mouse_hover.rs b/core/src/builtin_widgets/mouse_hover.rs index c94cf86ad..1433bef89 100644 --- a/core/src/builtin_widgets/mouse_hover.rs +++ b/core/src/builtin_widgets/mouse_hover.rs @@ -17,7 +17,7 @@ impl Declare for MouseHover { impl ComposeChild for MouseHover { type Child = Widget; - fn compose_child(this: impl StateWriter, child: Self::Child) -> impl WidgetBuilder { + fn compose_child(this: impl StateWriter, child: Self::Child) -> impl IntoWidgetStrict { fn_widget! { @ $child { on_pointer_enter: move |_| $this.write().hover = true, diff --git a/core/src/builtin_widgets/padding.rs b/core/src/builtin_widgets/padding.rs index 046c54ba8..6f6e4d2be 100644 --- a/core/src/builtin_widgets/padding.rs +++ b/core/src/builtin_widgets/padding.rs @@ -69,7 +69,7 @@ mod tests { use super::*; use crate::test_helper::*; - fn smoke() -> impl WidgetBuilder { + fn smoke() -> impl IntoWidgetStrict { fn_widget! { @MockMulti { padding: EdgeInsets::only_left(1.), diff --git a/core/src/builtin_widgets/pointer_pressed.rs b/core/src/builtin_widgets/pointer_pressed.rs index 13e3b3544..c208e6b86 100644 --- a/core/src/builtin_widgets/pointer_pressed.rs +++ b/core/src/builtin_widgets/pointer_pressed.rs @@ -21,7 +21,9 @@ impl PointerPressed { impl ComposeChild for PointerPressed { type Child = Widget; - fn compose_child(this: impl StateWriter, child: Self::Child) -> impl WidgetBuilder { + fn compose_child( + this: impl StateWriter, child: Self::Child, + ) -> impl IntoWidgetStrict { fn_widget! { @ $child { on_pointer_down: move|_| $this.write().pointer_pressed = true, diff --git a/core/src/builtin_widgets/scrollable.rs b/core/src/builtin_widgets/scrollable.rs index ad9d57772..e527607b5 100644 --- a/core/src/builtin_widgets/scrollable.rs +++ b/core/src/builtin_widgets/scrollable.rs @@ -31,7 +31,9 @@ impl Declare for ScrollableWidget { impl ComposeChild for ScrollableWidget { type Child = Widget; - fn compose_child(this: impl StateWriter, child: Self::Child) -> impl WidgetBuilder { + fn compose_child( + this: impl StateWriter, child: Self::Child, + ) -> impl IntoWidgetStrict { fn_widget! { let mut view = @UnconstrainedBox { dir: pipe!(match $this.get_scrollable() { diff --git a/core/src/builtin_widgets/theme.rs b/core/src/builtin_widgets/theme.rs index ebdf8703f..18e91e23e 100644 --- a/core/src/builtin_widgets/theme.rs +++ b/core/src/builtin_widgets/theme.rs @@ -76,7 +76,7 @@ impl ComposeChild for ThemeWidget { #[inline] fn compose_child( this: impl StateWriter, mut child: Self::Child, - ) -> impl WidgetBuilder { + ) -> impl IntoWidgetStrict { use crate::prelude::*; fn_widget! { let theme = this.read().theme.clone(); @@ -91,7 +91,7 @@ impl ComposeChild for ThemeWidget { // node, because the subtree may be hold its id. // // A `Void` is cheap for a theme. - let p = Void.build(ctx!()).attach_data(Queryable(theme), ctx!()); + let p = Void.into_widget(ctx!()).attach_data(Queryable(theme), ctx!()); // shadow the context with the theme. let ctx = BuildCtx::new_with_data(Some(p.id()), ctx!().tree, themes); let child = child.gen_widget(&ctx); diff --git a/core/src/builtin_widgets/theme/compose_decorators.rs b/core/src/builtin_widgets/theme/compose_decorators.rs index 3abbcfa16..1e971cfa9 100644 --- a/core/src/builtin_widgets/theme/compose_decorators.rs +++ b/core/src/builtin_widgets/theme/compose_decorators.rs @@ -14,7 +14,7 @@ pub struct ComposeDecorators { /// `Theme` by a function. The trait implementation only as a default logic if /// no overwrite function in `Theme`. pub trait ComposeDecorator: Sized { - fn compose_decorator(this: State, host: Widget) -> impl WidgetBuilder; + fn compose_decorator(this: State, host: Widget) -> impl IntoWidgetStrict; } impl ComposeDecorators { @@ -51,7 +51,9 @@ mod tests { struct Size100Style; impl ComposeDecorator for Size100Style { - fn compose_decorator(_: State, host: Widget) -> impl WidgetBuilder { fn_widget!(host) } + fn compose_decorator(_: State, host: Widget) -> impl IntoWidgetStrict { + fn_widget!(host) + } } theme .compose_decorators @@ -62,7 +64,7 @@ mod tests { @ { host } } } - .build(ctx) + .into_widget(ctx) }); let w = fn_widget! { diff --git a/core/src/builtin_widgets/theme/icon_theme.rs b/core/src/builtin_widgets/theme/icon_theme.rs index ce412d4dc..6c97ca875 100644 --- a/core/src/builtin_widgets/theme/icon_theme.rs +++ b/core/src/builtin_widgets/theme/icon_theme.rs @@ -58,7 +58,7 @@ pub const CUSTOM_ICON_START: NamedSvg = NamedSvg::new(65536); pub struct NamedSvg(pub usize); impl Compose for NamedSvg { - fn compose(this: impl StateWriter) -> impl WidgetBuilder { + fn compose(this: impl StateWriter) -> impl IntoWidgetStrict { fn_widget! { @ { pipe!($this.of_or_miss(ctx!())) }} } } diff --git a/core/src/builtin_widgets/transform_widget.rs b/core/src/builtin_widgets/transform_widget.rs index 0e62542f4..5b3bd2545 100644 --- a/core/src/builtin_widgets/transform_widget.rs +++ b/core/src/builtin_widgets/transform_widget.rs @@ -45,7 +45,7 @@ mod tests { use super::*; use crate::test_helper::*; - fn smoke() -> impl WidgetBuilder { + fn smoke() -> impl IntoWidgetStrict { fn_widget! { @TransformWidget { transform: Transform::new(2., 0., 0., 2., 0., 0.), diff --git a/core/src/builtin_widgets/unconstrained_box.rs b/core/src/builtin_widgets/unconstrained_box.rs index d44e01bc3..7cdc56b25 100644 --- a/core/src/builtin_widgets/unconstrained_box.rs +++ b/core/src/builtin_widgets/unconstrained_box.rs @@ -78,7 +78,7 @@ mod tests { use super::*; use crate::test_helper::*; - fn smoke() -> impl WidgetBuilder { + fn smoke() -> impl IntoWidgetStrict { let size = Size::new(200., 200.); fn_widget! { @MockMulti { diff --git a/core/src/builtin_widgets/visibility.rs b/core/src/builtin_widgets/visibility.rs index 6ed17da6f..ee23fa130 100644 --- a/core/src/builtin_widgets/visibility.rs +++ b/core/src/builtin_widgets/visibility.rs @@ -13,7 +13,7 @@ impl Declare for Visibility { impl ComposeChild for Visibility { type Child = Widget; - fn compose_child(this: impl StateWriter, child: Self::Child) -> impl WidgetBuilder { + fn compose_child(this: impl StateWriter, child: Self::Child) -> impl IntoWidgetStrict { fn_widget! { @FocusScope { skip_descendants: pipe!(!$this.get_visible()), diff --git a/core/src/context/app_ctx.rs b/core/src/context/app_ctx.rs index aa7729d81..bac99a01d 100644 --- a/core/src/context/app_ctx.rs +++ b/core/src/context/app_ctx.rs @@ -17,7 +17,7 @@ use crate::{ clipboard::{Clipboard, MockClipboard}, prelude::FuturesLocalScheduler, timer::Timer, - widget::WidgetBuilder, + widget::IntoWidget, window::{ShellWindow, Window, WindowId}, }; @@ -67,7 +67,9 @@ impl AppCtx { #[track_caller] pub fn app_theme() -> &'static Theme { &Self::shared().app_theme } - pub fn new_window(shell_wnd: Box, content: impl WidgetBuilder) -> Rc { + pub fn new_window( + shell_wnd: Box, content: impl IntoWidget, + ) -> Rc { let wnd = Window::new(shell_wnd); let id = wnd.id(); diff --git a/core/src/context/build_ctx.rs b/core/src/context/build_ctx.rs index 0f9580673..ecab70e4c 100644 --- a/core/src/context/build_ctx.rs +++ b/core/src/context/build_ctx.rs @@ -190,7 +190,7 @@ mod tests { size: ZERO_SIZE, @ { Clone::clone_from(&mut *$c_themes.write(), ctx!().themes()); - Void.build(ctx!()) + Void } } }) diff --git a/core/src/events/dispatcher.rs b/core/src/events/dispatcher.rs index 2a70bb578..3a39a7026 100644 --- a/core/src/events/dispatcher.rs +++ b/core/src/events/dispatcher.rs @@ -283,7 +283,7 @@ mod tests { fn record_pointer( event_stack: Rc>>, widget: impl IntoWidgetStrict, - ) -> impl WidgetBuilder + IntoWidgetStrict { + ) -> impl IntoWidgetStrict + IntoWidgetStrict { let handler_ctor = move || { let stack = event_stack.clone(); @@ -421,7 +421,7 @@ mod tests { #[derive(Default)] struct EventRecord(Rc>>); impl Compose for EventRecord { - fn compose(this: impl StateWriter) -> impl WidgetBuilder { + fn compose(this: impl StateWriter) -> impl IntoWidgetStrict { fn_widget! { @MockBox { size: INFINITY_SIZE, @@ -461,7 +461,7 @@ mod tests { } impl Compose for EnterLeave { - fn compose(this: impl StateWriter) -> impl WidgetBuilder { + fn compose(this: impl StateWriter) -> impl IntoWidgetStrict { fn_widget! { @MockBox { size: INFINITY_SIZE, diff --git a/core/src/events/focus_mgr.rs b/core/src/events/focus_mgr.rs index c6a9e179f..aaebf1c71 100644 --- a/core/src/events/focus_mgr.rs +++ b/core/src/events/focus_mgr.rs @@ -682,7 +682,7 @@ mod tests { } impl Compose for EmbedFocus { - fn compose(this: impl StateWriter) -> impl WidgetBuilder { + fn compose(this: impl StateWriter) -> impl IntoWidgetStrict { fn_widget! { @MockBox { size: INFINITY_SIZE, @@ -839,9 +839,9 @@ mod tests { auto_focus: true, on_chars: move |e| $input_writer.write().push_str(&e.chars), size: Size::new(10., 10.), - }.build(ctx!()) + }.into_widget(ctx!()) } else { - Void.build(ctx!()) + Void.into_widget(ctx!()) } }} } @@ -879,7 +879,7 @@ mod tests { on_chars: move |e| if idx == 2 { $input_writer.write().push_str(&e.chars) }, size: Size::new(10., 10.), } - }.build(ctx!())) + }.into_widget(ctx!())) }).collect::>() } } diff --git a/core/src/events/keyboard.rs b/core/src/events/keyboard.rs index 2ec7e0d5f..652d56dd3 100644 --- a/core/src/events/keyboard.rs +++ b/core/src/events/keyboard.rs @@ -56,7 +56,7 @@ mod tests { struct Keys(Rc>>); impl Compose for Keys { - fn compose(this: impl StateWriter) -> impl WidgetBuilder { + fn compose(this: impl StateWriter) -> impl IntoWidgetStrict { fn_widget! { @MockBox { size: Size::zero(), diff --git a/core/src/overlay.rs b/core/src/overlay.rs index a3ea66326..c09308ca4 100644 --- a/core/src/overlay.rs +++ b/core/src/overlay.rs @@ -245,7 +245,7 @@ impl OverlayState { }; let build_ctx = BuildCtx::new(None, &wnd.widget_tree); let style = style.unwrap_or_else(|| OverlayStyle::of(&build_ctx)); - let w = this.wrap_style(w, style).build(&build_ctx); + let w = this.wrap_style(w, style).into_widget(&build_ctx); let wid = w.id(); *this.0.borrow_mut() = OverlayInnerState::Showing(wid, wnd.clone()); let root = wnd.widget_tree.borrow().root(); @@ -255,7 +255,7 @@ impl OverlayState { }); } - fn wrap_style(&self, w: Widget, style: OverlayStyle) -> impl WidgetBuilder { + fn wrap_style(&self, w: Widget, style: OverlayStyle) -> impl IntoWidgetStrict { let this = self.clone(); fn_widget! { let OverlayStyle { close_policy, mask_brush } = style; diff --git a/core/src/pipe.rs b/core/src/pipe.rs index 7abcf14f4..ed972117e 100644 --- a/core/src/pipe.rs +++ b/core/src/pipe.rs @@ -97,20 +97,17 @@ impl BoxPipe { } pub(crate) trait InnerPipe: Pipe { - // todo: remove the build function. - fn build_single( - self, ctx: &BuildCtx, build: impl Fn(Self::Value, &BuildCtx) -> Widget + 'static, - ) -> Widget + fn build_single(self, ctx: &BuildCtx) -> Widget where Self: Sized, - Self::Value: 'static, + Self::Value: IntoWidget + 'static, { let info = Sc::new(Cell::new(SinglePipeInfo { gen_id: ctx.tree.borrow().root(), multi_pos: 0 })); let info2 = info.clone(); let handle = ctx.handle(); let (w, modifies) = self.tick_unzip(move || pipe_priority_value(&info2, handle), ctx); - let w = build(w, ctx); + let w = w.into_widget(ctx); info.set(SinglePipeInfo { gen_id: w.id(), multi_pos: 0 }); let pipe_node = PipeNode::share_capture(w.id(), Box::new(info.clone()), ctx); @@ -120,7 +117,7 @@ pub(crate) trait InnerPipe: Pipe { handle.with_ctx(|ctx| { let id = info.host_id(); - let new_id = build(w, ctx).consume(); + let new_id = w.into_widget(ctx).consume(); query_info_outside_until(id, &info, ctx, |info| info.single_replace(id, new_id)); pipe_node.primary_transplant(id, new_id, ctx); @@ -150,7 +147,7 @@ pub(crate) trait InnerPipe: Pipe { .map(|w| w.into_widget(ctx)) .collect::>(); if widgets.is_empty() { - widgets.push(Void.build(ctx)); + widgets.push(Void.into_widget(ctx)); } widgets }; @@ -452,29 +449,6 @@ impl Pipe for ValuePipe { impl InnerPipe for T {} -crate::widget::multi_build_replace_impl! { - impl {#} for MapPipe - where - V: {#} + 'static, - S: InnerPipe, - S::Value: 'static, - F: FnMut(S::Value) -> V + 'static, - { - fn build(self, ctx: &BuildCtx) -> Widget { - self.build_single(ctx, |w, ctx| w.build(ctx)) - } - } - - - - impl {#} for Box> - { - fn build(self, ctx: &BuildCtx) -> Widget { - self.build_single(ctx, |w, ctx| w.build(ctx)) - } - } -} - impl IntoWidgetStrict for MapPipe where V: IntoWidget + 'static, @@ -482,9 +456,7 @@ where S::Value: 'static, F: FnMut(S::Value) -> V + 'static, { - fn into_widget_strict(self, ctx: &BuildCtx) -> Widget { - self.build_single(ctx, |w, ctx| w.into_widget(ctx)) - } + fn into_widget_strict(self, ctx: &BuildCtx) -> Widget { self.build_single(ctx) } } impl IntoWidgetStrict for FinalChain @@ -493,15 +465,11 @@ where S: InnerPipe, F: FnOnce(ValueStream) -> ValueStream + 'static, { - fn into_widget_strict(self, ctx: &BuildCtx) -> Widget { - self.build_single(ctx, |w, ctx| w.into_widget(ctx)) - } + fn into_widget_strict(self, ctx: &BuildCtx) -> Widget { self.build_single(ctx) } } impl + 'static> IntoWidgetStrict for Box> { - fn into_widget_strict(self, ctx: &BuildCtx) -> Widget { - self.build_single(ctx, |w, ctx| w.into_widget(ctx)) - } + fn into_widget_strict(self, ctx: &BuildCtx) -> Widget { self.build_single(ctx) } } impl IntoWidget for MapPipe, S, F> @@ -539,28 +507,7 @@ fn option_into_widget( if let Some(w) = w { w.into_widget(ctx) } else { Void.into_widget(ctx) } } }) - .build_single(ctx, |w, ctx| w.into_widget(ctx)) -} - -impl WidgetBuilder for MapPipe -where - S: InnerPipe, - S::Value: 'static, - F: FnMut(S::Value) -> Widget + 'static, -{ - fn build(self, ctx: &BuildCtx) -> Widget { self.build_single(ctx, |w, ctx| w.build(ctx)) } -} - -impl WidgetBuilder for FinalChain -where - S: InnerPipe, - F: FnOnce(ValueStream) -> ValueStream + 'static, -{ - fn build(self, ctx: &BuildCtx) -> Widget { self.build_single(ctx, |w, ctx| w.build(ctx)) } -} - -impl WidgetBuilder for Box> { - fn build(self, ctx: &BuildCtx) -> Widget { self.build_single(ctx, |w, ctx| w.build(ctx)) } + .build_single(ctx) } fn update_children_key_status(old: WidgetId, new: WidgetId, ctx: &BuildCtx) { @@ -955,13 +902,6 @@ impl RenderProxy for PipeNode { fn proxy(&self) -> Self::Target<'_> { &*self.as_ref().data } } -impl

From

for BoxPipe -where - P: Pipe + 'static, -{ - fn from(value: P) -> Self { BoxPipe::pipe(Box::new(value)) } -} - #[cfg(test)] mod tests { use std::{ @@ -1511,7 +1451,7 @@ mod tests { reset_test_env!(); let _ = fn_widget! { let v = Stateful::new(true); - let w = pipe!(*$v).map(move |_| Void.build(ctx!())); + let w = pipe!(*$v).map(move |_| Void.into_widget(ctx!())); w.into_widget(ctx!()) }; } diff --git a/core/src/state.rs b/core/src/state.rs index 2411192cc..46722c530 100644 --- a/core/src/state.rs +++ b/core/src/state.rs @@ -338,26 +338,6 @@ impl<'a, W> Drop for WriteRef<'a, W> { } } -impl ComposeBuilder for State { - #[inline] - fn build(self, ctx: &BuildCtx) -> Widget { Compose::compose(self).build(ctx) } -} - -impl> + 'static, C> ComposeChildBuilder for State

{ - #[inline] - fn build(self, ctx: &BuildCtx) -> Widget { ComposeChild::compose_child(self, None).build(ctx) } -} - -impl RenderBuilder for State { - #[inline] - fn build(self, ctx: &BuildCtx) -> Widget { - match self.0.into_inner() { - InnerState::Data(w) => w.into_inner().build(ctx), - InnerState::Stateful(w) => w.build(ctx), - } - } -} - impl IntoWidgetStrict for State { fn into_widget_strict(self, ctx: &BuildCtx) -> Widget { match self.0.into_inner() { @@ -369,14 +349,7 @@ impl IntoWidgetStrict for State { impl IntoWidgetStrict for State { #[inline] - fn into_widget_strict(self, ctx: &BuildCtx) -> Widget { Compose::compose(self).build(ctx) } -} - -impl> + 'static, C> IntoWidgetStrict for State { - #[inline] - fn into_widget_strict(self, ctx: &BuildCtx) -> Widget { - ComposeChild::compose_child(self, None).build(ctx) - } + fn into_widget_strict(self, ctx: &BuildCtx) -> Widget { Compose::compose(self).into_widget(ctx) } } impl MultiChild for T @@ -393,34 +366,6 @@ where { } -macro_rules! impl_compose_builder { - ($name:ident) => { - impl ComposeBuilder for $name - where - W: StateWriter, - WM: Fn(&mut W::Value) -> PartData + Clone + 'static, - V: Compose + 'static, - { - fn build(self, ctx: &crate::context::BuildCtx) -> Widget { Compose::compose(self).build(ctx) } - } - - impl ComposeChildBuilder for $name - where - W: StateWriter, - WM: Fn(&mut W::Value) -> PartData + Clone + 'static, - V: ComposeChild> + 'static, - { - #[inline] - fn build(self, ctx: &BuildCtx) -> Widget { - ComposeChild::compose_child(self, None).build(ctx) - } - } - }; -} - -impl_compose_builder!(MapWriter); -impl_compose_builder!(SplittedWriter); - #[cfg(test)] mod tests { use ribir_algo::Sc; @@ -510,7 +455,7 @@ mod tests { struct C; impl Compose for C { - fn compose(_: impl StateWriter) -> impl WidgetBuilder { + fn compose(_: impl StateWriter) -> impl IntoWidgetStrict { fn_widget! { Void } } } @@ -545,7 +490,9 @@ mod tests { struct CC; impl ComposeChild for CC { type Child = Option; - fn compose_child(_: impl StateWriter, _: Self::Child) -> impl WidgetBuilder { + fn compose_child( + _: impl StateWriter, _: Self::Child, + ) -> impl IntoWidgetStrict { fn_widget! { @{ Void } } } } diff --git a/core/src/state/map_state.rs b/core/src/state/map_state.rs index 4765a587a..4ed2da548 100644 --- a/core/src/state/map_state.rs +++ b/core/src/state/map_state.rs @@ -185,17 +185,6 @@ where fn proxy(&self) -> Self::Target<'_> { self.read() } } -impl RenderBuilder for MapWriter -where - Self: 'static, - S: StateWriter, - WM: Fn(&mut S::Value) -> PartData + Clone, - V: Render, -{ - #[inline] - fn build(self, ctx: &BuildCtx) -> Widget { self.clone_reader().build(ctx) } -} - impl IntoWidgetStrict for MapWriter where Self: StateReader, @@ -209,15 +198,5 @@ where Self: StateWriter, ::Value: Compose, { - fn into_widget_strict(self, ctx: &BuildCtx) -> Widget { Compose::compose(self).build(ctx) } -} - -impl IntoWidgetStrict for MapWriter -where - Self: StateWriter, - ::Value: ComposeChild>, -{ - fn into_widget_strict(self, ctx: &BuildCtx) -> Widget { - ComposeChild::compose_child(self, None).build(ctx) - } + fn into_widget_strict(self, ctx: &BuildCtx) -> Widget { Compose::compose(self).into_widget(ctx) } } diff --git a/core/src/state/splitted_state.rs b/core/src/state/splitted_state.rs index 2223bcdb6..aaac47337 100644 --- a/core/src/state/splitted_state.rs +++ b/core/src/state/splitted_state.rs @@ -148,18 +148,6 @@ where } } -impl RenderBuilder for SplittedWriter -where - O: StateWriter, - W: Fn(&mut O::Value) -> PartData + Clone + 'static, - V: Render, -{ - fn build(self, ctx: &BuildCtx) -> Widget { - MapWriterAsReader { origin: self.origin.clone_reader(), part_map: self.splitter.clone() } - .build(ctx) - } -} - impl IntoWidgetStrict for SplittedWriter where Self: StateWriter, @@ -173,15 +161,5 @@ where Self: StateWriter, ::Value: Compose, { - fn into_widget_strict(self, ctx: &BuildCtx) -> Widget { Compose::compose(self).build(ctx) } -} - -impl IntoWidgetStrict for SplittedWriter -where - Self: StateWriter, - ::Value: ComposeChild>, -{ - fn into_widget_strict(self, ctx: &BuildCtx) -> Widget { - ComposeChild::compose_child(self, None).build(ctx) - } + fn into_widget_strict(self, ctx: &BuildCtx) -> Widget { Compose::compose(self).into_widget(ctx) } } diff --git a/core/src/state/stateful.rs b/core/src/state/stateful.rs index c65993a30..34eddd0f5 100644 --- a/core/src/state/stateful.rs +++ b/core/src/state/stateful.rs @@ -198,42 +198,6 @@ impl Writer { pub fn into_inner(self) -> Stateful { self.0 } } -macro_rules! compose_builder_impl { - ($name:ident) => { - impl ComposeBuilder for $name { - #[inline] - fn build(self, ctx: &BuildCtx) -> Widget { Compose::compose(self).build(ctx) } - } - - impl> + 'static, C> ComposeChildBuilder for $name { - #[inline] - fn build(self, ctx: &BuildCtx) -> Widget { - ComposeChild::compose_child(self, None).build(ctx) - } - } - }; -} - -compose_builder_impl!(Stateful); -compose_builder_impl!(Writer); - -impl RenderBuilder for Stateful { - fn build(self, ctx: &BuildCtx) -> Widget { - match self.try_into_value() { - Ok(r) => r.build(ctx), - Err(s) => { - let w = s.data.clone().build(ctx); - w.dirty_subscribe(s.raw_modifies(), ctx) - } - } - } -} - -impl RenderBuilder for Writer { - #[inline] - fn build(self, ctx: &BuildCtx) -> Widget { self.0.build(ctx) } -} - impl Stateful { pub fn new(data: W) -> Self { Self { data: Sc::new(StateCell::new(data)), info: Sc::new(StatefulInfo::new()) } @@ -287,15 +251,7 @@ impl IntoWidgetStrict for Stateful { } impl IntoWidgetStrict for Stateful { - fn into_widget_strict(self, ctx: &BuildCtx) -> Widget { Compose::compose(self).build(ctx) } -} - -impl> + 'static, C> IntoWidgetStrict - for Stateful -{ - fn into_widget_strict(self, ctx: &BuildCtx) -> Widget { - ComposeChild::compose_child(self, None).build(ctx) - } + fn into_widget_strict(self, ctx: &BuildCtx) -> Widget { Compose::compose(self).into_widget(ctx) } } impl IntoWidgetStrict for Reader { diff --git a/core/src/test_helper.rs b/core/src/test_helper.rs index 9ac57d94c..a0f74e06e 100644 --- a/core/src/test_helper.rs +++ b/core/src/test_helper.rs @@ -41,13 +41,13 @@ macro_rules! reset_test_env { impl TestWindow { /// Create a 1024x1024 window for test - pub fn new(root: impl WidgetBuilder) -> Self { Self::new_wnd(root, None) } + pub fn new(root: impl IntoWidgetStrict) -> Self { Self::new_wnd(root, None) } - pub fn new_with_size(root: impl WidgetBuilder, size: Size) -> Self { + pub fn new_with_size(root: impl IntoWidgetStrict, size: Size) -> Self { Self::new_wnd(root, Some(size)) } - fn new_wnd(root: impl WidgetBuilder, size: Option) -> Self { + fn new_wnd(root: impl IntoWidgetStrict, size: Option) -> Self { let _ = NEW_TIMER_FN.set(Timer::new_timer_future); let wnd = AppCtx::new_window(Box::new(TestShellWindow::new(size)), root); wnd.run_frame_tasks(); diff --git a/core/src/widget.rs b/core/src/widget.rs index 83b1e54c9..10fcb004d 100644 --- a/core/src/widget.rs +++ b/core/src/widget.rs @@ -14,7 +14,7 @@ use crate::{context::*, prelude::*, render_helper::PureRender}; pub trait Compose: Sized { /// Describes the part of the user interface represented by this widget. /// Called by framework, should never directly call it. - fn compose(this: impl StateWriter) -> impl WidgetBuilder; + fn compose(this: impl StateWriter) -> impl IntoWidgetStrict; } pub struct HitTest { @@ -65,8 +65,7 @@ pub struct GenWidget(Box FnMut(&'a BuildCtx<'b>) -> Widget>); // The widget type marker. pub const COMPOSE: usize = 1; pub const RENDER: usize = 2; -pub const COMPOSE_CHILD: usize = 3; -pub const FN: usize = 4; +pub const FN: usize = 3; /// Defines a trait for converting any widget into a `Widget` type. Direct /// implementation of this trait is not recommended as it is automatically @@ -99,7 +98,7 @@ impl> IntoWidget for T { impl IntoWidgetStrict for C { #[inline] fn into_widget_strict(self, ctx: &BuildCtx) -> Widget { - Compose::compose(State::value(self)).build(ctx) + Compose::compose(State::value(self)).into_widget(ctx) } } @@ -110,10 +109,11 @@ impl IntoWidgetStrict for R { } } -impl> + 'static, C> IntoWidgetStrict for W { - #[inline] - fn into_widget_strict(self, ctx: &BuildCtx) -> Widget { - ComposeChild::compose_child(State::value(self), None).build(ctx) +impl>, C> Compose for W { + fn compose(this: impl StateWriter) -> impl IntoWidgetStrict { + fn_widget! { + ComposeChild::compose_child(this, None) + } } } @@ -130,43 +130,6 @@ impl IntoWidgetStrict for GenWidget { fn into_widget_strict(mut self, ctx: &BuildCtx) -> Widget { self.gen_widget(ctx) } } -/// Trait to build a indirect widget into widget tree with `BuildCtx` in the -/// build phase. You should not implement this trait directly, framework will -/// auto implement this. -/// -/// A indirect widget is a widget that is not `Compose`, `Render` and -/// `ComposeChild`, like function widget and `Pipe`. -pub trait WidgetBuilder { - fn build(self, ctx: &BuildCtx) -> Widget; -} - -/// Trait to build a compose widget into widget tree with `BuildCtx` in the -/// build phase. You should not implement this trait directly, implement -/// `Compose` trait instead. -pub trait ComposeBuilder { - fn build(self, ctx: &BuildCtx) -> Widget; -} - -/// Trait to build a render widget into widget tree with `BuildCtx` in the build -/// phase. You should not implement this trait directly, implement `Render` -/// trait instead. -pub trait RenderBuilder { - fn build(self, ctx: &BuildCtx) -> Widget; -} - -/// Trait to build a `ComposeChild` widget without child into widget tree with -/// `BuildCtx` in the build phase, only work if the child of `ComposeChild` is -/// `Option<>_` . You should not implement this trait directly, -/// implement `ComposeChild` trait instead. -pub trait ComposeChildBuilder { - fn build(self, ctx: &BuildCtx) -> Widget; -} - -/// Trait only for `Widget`, you should not implement this trait. -pub trait SelfBuilder { - fn build(self, ctx: &BuildCtx) -> Widget; -} - impl Widget { /// Consume the widget, and return its id. This means this widget already be /// append into its parent. @@ -202,24 +165,6 @@ impl Widget { pub(crate) fn from_id(id: WidgetId, ctx: &BuildCtx) -> Self { Self { id, handle: ctx.handle() } } } -impl SelfBuilder for Widget { - #[inline(always)] - fn build(self, _: &BuildCtx) -> Widget { self } -} - -impl WidgetBuilder for F -where - F: FnOnce(&BuildCtx) -> Widget, -{ - #[inline] - fn build(self, ctx: &BuildCtx) -> Widget { self(ctx) } -} - -impl WidgetBuilder for GenWidget { - #[inline] - fn build(mut self, ctx: &BuildCtx) -> Widget { self.gen_widget(ctx) } -} - impl GenWidget { #[inline] pub fn new(f: impl FnMut(&BuildCtx) -> Widget + 'static) -> Self { Self(Box::new(f)) } @@ -233,65 +178,12 @@ impl Widget + 'static> From for GenWidget { fn from(f: F) -> Self { Self::new(f) } } -impl ComposeBuilder for C { - #[inline] - fn build(self, ctx: &BuildCtx) -> Widget { Compose::compose(State::value(self)).build(ctx) } -} - -impl RenderBuilder for R { - fn build(self, ctx: &BuildCtx) -> Widget { Widget::new(Box::new(PureRender(self)), ctx) } -} - -impl> + 'static, C> ComposeChildBuilder for W { - #[inline] - fn build(self, ctx: &BuildCtx) -> Widget { - ComposeChild::compose_child(State::value(self), None).build(ctx) - } -} - pub(crate) fn hit_test_impl(ctx: &HitTestCtx, pos: Point) -> bool { ctx .box_rect() .map_or(false, |rect| rect.contains(pos)) } -macro_rules! _replace { - (@replace($n: path) [$($e:tt)*] {#} $($rest:tt)*) => { - $crate::widget::_replace!(@replace($n) [$($e)* $n] $($rest)*); - }; - (@replace($n: path) [$($e:tt)*] $first: tt $($rest:tt)*) => { - $crate::widget::_replace!(@replace($n) [$($e)* $first] $($rest)*); - }; - (@replace($i: path) [$($e:tt)*]) => { $($e)* }; - (@replace($n: path) $first: tt $($rest:tt)*) => { - $crate::widget::_replace!(@replace($n) [$first] $($rest)*); - }; -} - -macro_rules! multi_build_replace_impl { - ($($rest:tt)*) => { - $crate::widget::repeat_and_replace!([ - $crate::widget::ComposeBuilder, - $crate::widget::RenderBuilder, - $crate::widget::ComposeChildBuilder, - $crate::widget::WidgetBuilder - ] $($rest)*); - }; -} - -macro_rules! repeat_and_replace { - ([$first: path $(,$n: path)*] $($rest:tt)*) => { - $crate::widget::_replace!(@replace($first) $($rest)*); - $crate::widget::repeat_and_replace!([$($n),*] $($rest)*); - }; - ([] $($rest:tt)*) => { - }; -} - -pub(crate) use _replace; -pub(crate) use multi_build_replace_impl; -pub(crate) use repeat_and_replace; - impl Drop for Widget { fn drop(&mut self) { log::warn!("widget allocated but never used: {:?}", self.id); diff --git a/core/src/widget_children.rs b/core/src/widget_children.rs index 11a1dabc0..0d306e0e6 100644 --- a/core/src/widget_children.rs +++ b/core/src/widget_children.rs @@ -40,7 +40,9 @@ pub trait WithChild { /// and its child. pub trait ComposeChild: Sized { type Child; - fn compose_child(this: impl StateWriter, child: Self::Child) -> impl WidgetBuilder; + fn compose_child( + this: impl StateWriter, child: Self::Child, + ) -> impl IntoWidgetStrict; } /// A pair of object and its child without compose, this keep the type @@ -55,24 +57,14 @@ pub struct Pair { /// type. pub type WidgetOf = Pair; -impl RenderBuilder for BoxedSingleChild { - #[inline] - fn build(self, _: &BuildCtx) -> Widget { self.0 } -} - impl IntoWidgetStrict for BoxedMultiChild { #[inline] - fn into_widget_strict(self, ctx: &BuildCtx) -> Widget { self.build(ctx) } + fn into_widget_strict(self, _: &BuildCtx) -> Widget { self.0 } } impl IntoWidgetStrict for BoxedSingleChild { #[inline] - fn into_widget_strict(self, ctx: &BuildCtx) -> Widget { self.build(ctx) } -} - -impl RenderBuilder for BoxedMultiChild { - #[inline] - fn build(self, _: &BuildCtx) -> Widget { self.0 } + fn into_widget_strict(self, _: &BuildCtx) -> Widget { self.0 } } impl BoxedSingleChild { @@ -134,7 +126,9 @@ mod tests { impl ComposeChild for Page { type Child = PageTml; - fn compose_child(_: impl StateWriter, _: Self::Child) -> impl WidgetBuilder { + fn compose_child( + _: impl StateWriter, _: Self::Child, + ) -> impl IntoWidgetStrict { fn_widget!(Void) } } @@ -161,7 +155,9 @@ mod tests { impl ComposeChild for Parent { type Child = Option, Widget>>; - fn compose_child(_: impl StateWriter, _: Self::Child) -> impl WidgetBuilder { + fn compose_child( + _: impl StateWriter, _: Self::Child, + ) -> impl IntoWidgetStrict { fn_widget!(Void) } } @@ -196,7 +192,9 @@ mod tests { impl ComposeChild for A { type Child = Vec; - fn compose_child(_: impl StateWriter, _: Self::Child) -> impl WidgetBuilder { + fn compose_child( + _: impl StateWriter, _: Self::Child, + ) -> impl IntoWidgetStrict { fn_widget!(Void) } } @@ -277,7 +275,9 @@ mod tests { impl ComposeChild for P { type Child = WidgetOf>; - fn compose_child(_: impl StateWriter, _: Self::Child) -> impl WidgetBuilder { + fn compose_child( + _: impl StateWriter, _: Self::Child, + ) -> impl IntoWidgetStrict { fn_widget!(Void) } } @@ -296,19 +296,19 @@ mod tests { type Child = Widget; fn compose_child( _: impl StateWriter, child: Self::Child, - ) -> impl WidgetBuilder { + ) -> impl IntoWidgetStrict { fn_widget!(child) } } let _ = |ctx| -> Widget { let child = MockBox { size: ZERO_SIZE }.with_child(Void, ctx); - X.with_child(child, ctx).build(ctx) + X.with_child(child, ctx).into_widget(ctx) }; } const FIX_OPTION_TEMPLATE_EXPECT_SIZE: Size = Size::new(100., 200.); - fn fix_option_template() -> impl WidgetBuilder { + fn fix_option_template() -> impl IntoWidgetStrict { struct Field; #[derive(Template, Default)] @@ -320,7 +320,9 @@ mod tests { impl ComposeChild for Host { type Child = Option; - fn compose_child(_: impl StateWriter, _: Self::Child) -> impl WidgetBuilder { + fn compose_child( + _: impl StateWriter, _: Self::Child, + ) -> impl IntoWidgetStrict { fn_widget! { @MockBox { size: FIX_OPTION_TEMPLATE_EXPECT_SIZE } } } } diff --git a/core/src/widget_children/child_convert.rs b/core/src/widget_children/child_convert.rs index 386632ec3..0b27eac96 100644 --- a/core/src/widget_children/child_convert.rs +++ b/core/src/widget_children/child_convert.rs @@ -8,19 +8,28 @@ pub trait IntoChild { fn into_child(self, ctx: &BuildCtx) -> C; } -pub const INTO_CONVERT: usize = 0; +pub const SELF: usize = 0; -// `Into` conversion. -impl, C> IntoChild for T { +impl IntoChild for C { #[inline(always)] - fn into_child(self, _: &BuildCtx) -> C { self.into() } + fn into_child(self, _: &BuildCtx) -> C { self } +} + +impl IntoChild, SELF> for C { + #[inline(always)] + fn into_child(self, _: &BuildCtx) -> Option { Some(self) } +} + +impl Widget + 'static> IntoChild for F { + #[inline] + fn into_child(self, _: &BuildCtx) -> GenWidget { GenWidget::new(self) } } // All possible widget conversions. macro_rules! impl_into_widget_child { ($($m:ident),*) => { $( - // `IntoWidgetStrict` is utilized here to prevent conflicts with the `Into` trait bounds. + // `IntoWidgetStrict` is utilized here to prevent conflicts with the `Self` impl> IntoChild for T { #[inline(always)] fn into_child(self, ctx: &BuildCtx) -> Widget { self.into_widget_strict(ctx) } @@ -29,12 +38,11 @@ macro_rules! impl_into_widget_child { }; } -impl_into_widget_child!(COMPOSE, RENDER, COMPOSE_CHILD, FN); +impl_into_widget_child!(COMPOSE, RENDER, FN); macro_rules! impl_into_option_widget_child { ($($m: ident), *) => { $( - // `IntoWidgetStrict` is utilized here to prevent conflicts with the `Into` trait bounds. impl> IntoChild, $m> for Option { #[inline(always)] fn into_child(self, ctx: &BuildCtx) -> Option { @@ -42,7 +50,6 @@ macro_rules! impl_into_option_widget_child { } } - // `IntoWidgetStrict` is utilized here to prevent conflicts with the `Into` trait bounds. impl> IntoChild, $m> for T { #[inline(always)] fn into_child(self, ctx: &BuildCtx) -> Option { @@ -53,7 +60,7 @@ macro_rules! impl_into_option_widget_child { }; } -impl_into_option_widget_child!(COMPOSE, RENDER, COMPOSE_CHILD, FN); +impl_into_option_widget_child!(COMPOSE, RENDER, FN); impl IntoChild for MapPipe, S, F> where @@ -80,6 +87,6 @@ impl + 'static> IntoChild fn into_child(self, ctx: &BuildCtx) -> Widget { self.into_widget(ctx) } } -impl IntoChild, FN> for T { - fn into_child(self, _: &BuildCtx) -> BoxPipe { BoxPipe::value(self) } +impl IntoChild, 0> for P { + fn into_child(self, _: &BuildCtx) -> BoxPipe { BoxPipe::pipe(Box::new(self)) } } diff --git a/core/src/widget_children/compose_child_impl.rs b/core/src/widget_children/compose_child_impl.rs index 0269b8f8f..997ee553b 100644 --- a/core/src/widget_children/compose_child_impl.rs +++ b/core/src/widget_children/compose_child_impl.rs @@ -1,4 +1,4 @@ -use child_convert::INTO_CONVERT; +use child_convert::SELF; use super::*; // Template use to construct child of a widget. @@ -26,104 +26,42 @@ where } } -macro_rules! vec_with_child { - ($($m:ident),*) => { - $( - impl WithChild for Vec - where - C: IntoChild, - { - type Target = Self; - - #[inline] - #[track_caller] - fn with_child(mut self, child: C, ctx: &BuildCtx) -> Self::Target { - self.push(child.into_child(ctx)); - self - } - } - )* - }; -} - -macro_rules! vec_with_iter_child { - ($($m:ident),*) => { - $( - impl WithChild for Vec - where - C: IntoIterator, - C::Item: IntoChild, - { - type Target = Self; - - #[inline] - #[track_caller] - fn with_child(mut self, child: C, ctx: &BuildCtx) -> Self::Target { - self.extend(child.into_iter().map(|v| v.into_child(ctx))); - self - } - } - )* - }; -} -vec_with_child!(INTO_CONVERT, COMPOSE, RENDER, COMPOSE_CHILD, FN); -vec_with_iter_child!(INTO_CONVERT, COMPOSE, RENDER, COMPOSE_CHILD, FN); +stateless_with_child!(3); -impl WithChild for W +impl WithChild for P where - W: StateWriter, - W::Value: ComposeChild, - Child: Template, - Child::Builder: WithChild, + P: StateWriter, + P::Value: ComposeChild, + T: Template, + T::Builder: WithChild, { - type Target = Pair; - - #[inline] - #[track_caller] - fn with_child(self, c: C, ctx: &BuildCtx) -> Self::Target { - let builder = Child::builder(); - let child = builder.with_child(c, ctx); + type Target = Pair; + fn with_child(self, child: C, ctx: &BuildCtx) -> Self::Target { + let child = T::builder().with_child(child, ctx); Pair { parent: self, child } } } -impl WithChild for W +stateless_with_child!(5); + +impl WithChild for W where W: StateWriter, - W::Value: ComposeChild>, - Child: Template, - Child::Builder: WithChild, + W::Value: ComposeChild>, + T: Template, + T::Builder: WithChild, { - type Target = Pair; + type Target = Pair; #[track_caller] fn with_child(self, c: C, ctx: &BuildCtx) -> Self::Target { - let builder = Child::builder(); + let builder = T::builder(); let child = builder.with_child(c, ctx); Pair { parent: self, child } } } +stateless_with_child!(7); -macro_rules! stateless_with_child { - ($($n: literal), *) => { - $( - impl WithChild for T - where - T: ComposeChild, - State: WithChild, - { - type Target = as WithChild>::Target; - - #[track_caller] - fn with_child(self, child: C, ctx: &BuildCtx) -> Self::Target { - State::value(self).with_child(child, ctx) - } - } - )* - }; -} - -// marker 5, 6, 7 for stateless parent -stateless_with_child!(2, 3, 4); +fat_obj_with_child!(2, 3, 4, 5, 6, 7); impl WithChild for Pair where @@ -137,52 +75,16 @@ where } } -macro_rules! fat_obj_with_child { - ($($n:literal),*) => { - $( - impl WithChild for FatObj - where - W: WithChild, - { - type Target = FatObj; - - #[track_caller] - fn with_child(self, child: C, ctx: &BuildCtx) -> Self::Target { - self.map( - #[cfg_attr(feature = "nightly", track_caller)] - |host| host.with_child(child, ctx), - ) - } - } - )* - }; -} - -fat_obj_with_child!(2, 3, 4, 5, 6, 7, 8, 9); - -impl WidgetBuilder for Pair -where - W: StateWriter, - W::Value: ComposeChild, - Child: From, -{ - #[inline] - fn build(self, ctx: &BuildCtx) -> Widget { - let Self { parent, child } = self; - ComposeChild::compose_child(parent, child.into()).build(ctx) - } -} - -impl IntoWidgetStrict for Pair +impl IntoWidgetStrict for Pair where W: StateWriter, W::Value: ComposeChild, - ::Child: From, + C: IntoChild<::Child, 0>, { #[inline] fn into_widget_strict(self, ctx: &BuildCtx) -> Widget { let Self { parent, child } = self; - ComposeChild::compose_child(parent, child.into()).build(ctx) + ComposeChild::compose_child(parent, child.into_child(ctx)).into_widget(ctx) } } @@ -200,6 +102,49 @@ impl TemplateBuilder for Vec { fn build_tml(self) -> Self::Target { self } } +macro_rules! vec_with_child { + ($($m:ident),*) => { + $( + impl WithChild for Vec + where + C: IntoChild, + { + type Target = Self; + + #[inline] + #[track_caller] + fn with_child(mut self, child: C, ctx: &BuildCtx) -> Self::Target { + self.push(child.into_child(ctx)); + self + } + } + )* + }; +} + +macro_rules! vec_with_iter_child { + ($($m:ident),*) => { + $( + impl WithChild for Vec + where + C: IntoIterator, + C::Item: IntoChild, + { + type Target = Self; + + #[inline] + #[track_caller] + fn with_child(mut self, child: C, ctx: &BuildCtx) -> Self::Target { + self.extend(child.into_iter().map(|v| v.into_child(ctx))); + self + } + } + )* + }; +} +vec_with_child!(SELF, COMPOSE, RENDER, FN); +vec_with_iter_child!(SELF, COMPOSE, RENDER, FN); + // todo: remove it, keep it for backward compatibility. impl WithChild for State where @@ -223,10 +168,11 @@ where if let Some(style) = style { style(Box::new(self), host, ctx) } else { - ComposeDecorator::compose_decorator(self, host).build(ctx) + ComposeDecorator::compose_decorator(self, host).into_widget(ctx) } } } + impl WithChild for T where T: ComposeDecorator, @@ -239,6 +185,44 @@ where } } +fat_obj_with_child!(8, 9); + +macro_rules! stateless_with_child { + ($n:literal) => { + impl WithChild for P + where + P: ComposeChild, + State

: WithChild, + { + type Target = as WithChild>::Target; + + fn with_child(self, child: C, ctx: &BuildCtx) -> Self::Target { + State::value(self).with_child(child, ctx) + } + } + }; +} + +macro_rules! fat_obj_with_child { + ($($n:literal),*) => { + $( + impl WithChild for FatObj + where + W: WithChild, + { + type Target = FatObj; + + fn with_child(self, child: C, ctx: &BuildCtx) -> Self::Target { + self.map(|host| host.with_child(child, ctx)) + } + } + )* + }; +} + +use fat_obj_with_child; +use stateless_with_child; + #[cfg(test)] mod tests { use super::*; @@ -253,7 +237,9 @@ mod tests { impl ComposeChild for P { type Child = PTml; - fn compose_child(_: impl StateWriter, _: Self::Child) -> impl WidgetBuilder { + fn compose_child( + _: impl StateWriter, _: Self::Child, + ) -> impl IntoWidgetStrict { fn_widget!(Void) } } @@ -264,13 +250,15 @@ mod tests { impl ComposeChild for X { type Child = Widget; - fn compose_child(_: impl StateWriter, _: Self::Child) -> impl WidgetBuilder { + fn compose_child( + _: impl StateWriter, _: Self::Child, + ) -> impl IntoWidgetStrict { fn_widget!(Void) } } #[test] - fn template_fill_template() { let _ = |ctx| P.with_child(Void, ctx).build(ctx); } + fn template_fill_template() { let _ = |ctx| P.with_child(Void, ctx).into_widget(ctx); } #[test] fn pair_compose_child() { @@ -287,7 +275,9 @@ mod tests { impl ComposeChild for PipeParent { type Child = BoxPipe; - fn compose_child(_: impl StateWriter, _: Self::Child) -> impl WidgetBuilder { + fn compose_child( + _: impl StateWriter, _: Self::Child, + ) -> impl IntoWidgetStrict { fn_widget!(Void) } } @@ -295,7 +285,7 @@ mod tests { #[test] fn compose_pipe_child() { let _value_child = fn_widget! { - @PipeParent { @ { 0 } } + @PipeParent { @ { BoxPipe::value(0) } } }; let _pipe_child = fn_widget! { diff --git a/core/src/widget_children/multi_child_impl.rs b/core/src/widget_children/multi_child_impl.rs index 50bfb6273..4dee2a597 100644 --- a/core/src/widget_children/multi_child_impl.rs +++ b/core/src/widget_children/multi_child_impl.rs @@ -73,9 +73,9 @@ macro_rules! impl_pipe_iter_widget_child { }; } -impl_widget_child!(COMPOSE, RENDER, COMPOSE_CHILD, FN); -impl_iter_widget_child!(COMPOSE, RENDER, COMPOSE_CHILD, FN); -impl_pipe_iter_widget_child!(COMPOSE, RENDER, COMPOSE_CHILD, FN); +impl_widget_child!(COMPOSE, RENDER, FN); +impl_iter_widget_child!(COMPOSE, RENDER, FN); +impl_pipe_iter_widget_child!(COMPOSE, RENDER, FN); impl WithChild for T where @@ -99,11 +99,7 @@ impl WithChild for MultiPair { } } -impl WidgetBuilder for MultiPair { - fn build(self, ctx: &BuildCtx) -> Widget { self.into_widget_strict(ctx) } -} - -impl IntoWidgetStrict for MultiPair { +impl IntoWidgetStrict for MultiPair { fn into_widget_strict(self, ctx: &BuildCtx) -> Widget { let MultiPair { parent, children } = self; let leaf = parent.id().single_leaf(&ctx.tree.borrow().arena); diff --git a/core/src/widget_tree/layout_info.rs b/core/src/widget_tree/layout_info.rs index 27bed9a60..7f0a8fe15 100644 --- a/core/src/widget_tree/layout_info.rs +++ b/core/src/widget_tree/layout_info.rs @@ -343,9 +343,9 @@ mod tests { @MockMulti { on_performed_layout: move |_| *$root_layout_cnt.write() += 1, @ { pipe!($child_box.size.is_empty()).map(move|b| if b { - MockBox { size: Size::new(1., 1.) }.build(ctx!()) + MockBox { size: Size::new(1., 1.) }.into_widget(ctx!()) } else { - child_box.clone_writer().into_inner().build(ctx!()) + child_box.clone_writer().into_inner().into_widget(ctx!()) }) } } diff --git a/core/src/window.rs b/core/src/window.rs index 0c5252d46..f6cbfd233 100644 --- a/core/src/window.rs +++ b/core/src/window.rs @@ -299,9 +299,9 @@ impl Window { window } - pub fn set_content_widget(&self, root: impl WidgetBuilder) -> &Self { + pub fn set_content_widget(&self, root: impl IntoWidget) -> &Self { let build_ctx = BuildCtx::new(None, &self.widget_tree); - let root = root.build(&build_ctx); + let root = root.into_widget(&build_ctx); self .widget_tree .borrow_mut() diff --git a/dev-helper/src/widget_test.rs b/dev-helper/src/widget_test.rs index 46c621d79..45dacbb14 100644 --- a/dev-helper/src/widget_test.rs +++ b/dev-helper/src/widget_test.rs @@ -92,7 +92,7 @@ macro_rules! widget_test_suit { /// use ribir_core::{ prelude::*, test_helper::* }; /// use ribir_dev_helper::*; /// -/// fn my_widget() -> impl WidgetBuilder { +/// fn my_widget() -> impl IntoWidgetStrict { /// fn_widget!{ /// @MockBox { /// size: Size::new(100., 100.), @@ -104,12 +104,12 @@ macro_rules! widget_test_suit { /// } /// /// // only use to avoid conflict. -/// fn my_widget_a() -> impl WidgetBuilder { my_widget() } +/// fn my_widget_a() -> impl IntoWidgetStrict { my_widget() } /// /// // Only test the whole widget size. /// widget_layout_test!(my_widget_a, width == 100., height == 100.,); /// -/// fn my_widget_b() -> impl WidgetBuilder { my_widget() } +/// fn my_widget_b() -> impl IntoWidgetStrict { my_widget() } /// // Only test the whole widget size but with a window size. /// widget_layout_test!( /// my_widget_b, @@ -118,7 +118,7 @@ macro_rules! widget_test_suit { /// height == 10., /// ); /// -/// fn my_widget_c() -> impl WidgetBuilder { my_widget() } +/// fn my_widget_c() -> impl IntoWidgetStrict { my_widget() } /// // Test two widget layout information. /// widget_layout_test!( /// my_widget_c, diff --git a/docs/en/get_started/quick_start.md b/docs/en/get_started/quick_start.md index 586902bbd..8b8a68496 100644 --- a/docs/en/get_started/quick_start.md +++ b/docs/en/get_started/quick_start.md @@ -545,7 +545,7 @@ The first situation is when the subscription's lifecycle should be shorter than ```rust use ribir::prelude::*; -fn show_name(name: State) -> impl WidgetBuilder { +fn show_name(name: State) -> impl IntoWidgetStrict { fn_widget!{ let text = @Text { text: "Hi, Guest!" }; let u = watch!($name.to_string()).subscribe(move |name| { @@ -597,7 +597,7 @@ impl Counter { } impl Compose for Counter { - fn compose(this: impl StateWriter) -> impl WidgetBuilder { + fn compose(this: impl StateWriter) -> impl IntoWidgetStrict { fn_widget! { @Row { @FilledButton { diff --git a/docs/en/practice_todos_app/develop_a_todos_app.md b/docs/en/practice_todos_app/develop_a_todos_app.md index c5c61850c..db8d96bb8 100644 --- a/docs/en/practice_todos_app/develop_a_todos_app.md +++ b/docs/en/practice_todos_app/develop_a_todos_app.md @@ -184,7 +184,7 @@ Then, add the following code to `ui.rs` to describe `Todos` as a widget: use ribir::prelude::*; impl Compose for Todos { - fn compose(this: impl StateWriter) -> impl WidgetBuilder { + fn compose(this: impl StateWriter) -> impl IntoWidgetStrict { fn_widget! { @Column { align_items: Align::Center, @@ -332,7 +332,7 @@ Next, let's look at the implementation of `task_item`: ... -fn task_item(task: S) -> impl WidgetBuilder +fn task_item(task: S) -> impl IntoWidgetStrict where S: StateWriter + 'static, S::OriginWriter: StateWriter, @@ -573,7 +573,7 @@ use ribir::prelude::{svgs, *}; use std::time::Duration; impl Compose for Todos { - fn compose(this: impl StateWriter) -> impl WidgetBuilder { + fn compose(this: impl StateWriter) -> impl IntoWidgetStrict { fn_widget! { @Column { align_items: Align::Center, @@ -666,7 +666,7 @@ fn task_lists(this: &impl StateWriter, cond: fn(&Task) -> bool) - .into() } -fn task_item(task: S) -> impl WidgetBuilder +fn task_item(task: S) -> impl IntoWidgetStrict where S: StateWriter + 'static, S::OriginWriter: StateWriter, diff --git a/docs/zh/get_started/quick_start.md b/docs/zh/get_started/quick_start.md index 912fd147f..ddf017fd8 100644 --- a/docs/zh/get_started/quick_start.md +++ b/docs/zh/get_started/quick_start.md @@ -546,7 +546,7 @@ fn main() { ```rust use ribir::prelude::*; -fn show_name(name: State) -> impl WidgetBuilder { +fn show_name(name: State) -> impl IntoWidgetStrict { fn_widget!{ let text = @Text { text: "Hi, Guest!" }; let u = watch!($name.to_string()).subscribe(move |name| { @@ -596,7 +596,7 @@ impl Counter { } impl Compose for Counter { - fn compose(this: impl StateWriter) -> impl WidgetBuilder { + fn compose(this: impl StateWriter) -> impl IntoWidgetStrict { fn_widget! { @Row { @FilledButton { diff --git a/docs/zh/practice_todos_app/develop_a_todos_app.md b/docs/zh/practice_todos_app/develop_a_todos_app.md index da1b1d80a..79b3aaf35 100644 --- a/docs/zh/practice_todos_app/develop_a_todos_app.md +++ b/docs/zh/practice_todos_app/develop_a_todos_app.md @@ -186,7 +186,7 @@ fn main() { use ribir::prelude::*; impl Compose for Todos { - fn compose(this: impl StateWriter) -> impl WidgetBuilder { + fn compose(this: impl StateWriter) -> impl IntoWidgetStrict { fn_widget! { @Column { align_items: Align::Center, @@ -335,7 +335,7 @@ let _hint_capture_writer = || $this.write(); ... -fn task_item(task: S) -> impl WidgetBuilder +fn task_item(task: S) -> impl IntoWidgetStrict where S: StateWriter + 'static, S::OriginWriter: StateWriter, @@ -576,7 +576,7 @@ use ribir::prelude::{svgs, *}; use std::time::Duration; impl Compose for Todos { - fn compose(this: impl StateWriter) -> impl WidgetBuilder { + fn compose(this: impl StateWriter) -> impl IntoWidgetStrict { fn_widget! { @Column { align_items: Align::Center, @@ -669,7 +669,7 @@ fn task_lists(this: &impl StateWriter, cond: fn(&Task) -> bool) - .into() } -fn task_item(task: S) -> impl WidgetBuilder +fn task_item(task: S) -> impl IntoWidgetStrict where S::OriginWriter: StateWriter, { diff --git a/examples/counter/src/lib.rs b/examples/counter/src/lib.rs index c806322f2..179be072e 100644 --- a/examples/counter/src/lib.rs +++ b/examples/counter/src/lib.rs @@ -1,6 +1,6 @@ use ribir::prelude::*; -pub fn counter() -> impl WidgetBuilder { +pub fn counter() -> impl IntoWidgetStrict { fn_widget! { let cnt = Stateful::new(0); @Row { diff --git a/examples/messages/src/messages.rs b/examples/messages/src/messages.rs index 53d76f943..ff7cf5050 100644 --- a/examples/messages/src/messages.rs +++ b/examples/messages/src/messages.rs @@ -13,7 +13,7 @@ struct MessageList { messages: Vec, } -pub fn messages() -> impl WidgetBuilder { +pub fn messages() -> impl IntoWidgetStrict { fn_widget! { MessageList { messages: vec![ @@ -43,7 +43,7 @@ pub fn messages() -> impl WidgetBuilder { } impl Compose for MessageList { - fn compose(this: impl StateWriter) -> impl WidgetBuilder { + fn compose(this: impl StateWriter) -> impl IntoWidgetStrict { fn_widget! { @Column { background: Palette::of(ctx!()).surface(), diff --git a/examples/storybook/src/storybook.rs b/examples/storybook/src/storybook.rs index fa023cddc..c3cd718c9 100644 --- a/examples/storybook/src/storybook.rs +++ b/examples/storybook/src/storybook.rs @@ -19,7 +19,7 @@ fn header() -> impl IntoWidgetStrict { } } -fn content() -> impl WidgetBuilder + IntoWidgetStrict { +fn content() -> impl IntoWidgetStrict + IntoWidgetStrict { fn actions_show() -> GenWidget { fn_widget! { @VScrollBar { @@ -333,7 +333,7 @@ fn content() -> impl WidgetBuilder + IntoWidgetStrict { } } -pub fn storybook() -> impl WidgetBuilder { +pub fn storybook() -> impl IntoWidgetStrict { fn_widget! { @Column { background: Palette::of(ctx!()).surface_container_low(), diff --git a/examples/todos/src/ui.rs b/examples/todos/src/ui.rs index e6f2e10ab..e7aabcbbc 100644 --- a/examples/todos/src/ui.rs +++ b/examples/todos/src/ui.rs @@ -3,7 +3,7 @@ use ribir::prelude::*; use crate::todos::{Task, Todos}; impl Compose for Todos { - fn compose(this: impl StateWriter) -> impl WidgetBuilder { + fn compose(this: impl StateWriter) -> impl IntoWidgetStrict { fn_widget! { @Column { align_items: Align::Center, @@ -79,7 +79,7 @@ fn task_lists(this: &impl StateWriter, cond: fn(&Task) -> bool) - let item = task_item_widget(task.clone_writer(), stagger.clone_writer()); @$item { on_double_tap: move |_| *$editing.write() = Some(id) - }.build(ctx!()) + }.into_widget(ctx!()) } }); @@ -96,7 +96,7 @@ fn task_lists(this: &impl StateWriter, cond: fn(&Task) -> bool) - fn input( text: Option, mut on_submit: impl FnMut(CowArc) + 'static, -) -> impl WidgetBuilder + IntoWidgetStrict { +) -> impl IntoWidgetStrict + IntoWidgetStrict { fn_widget! { let input = @Input { }; if let Some(text) = text { @@ -120,7 +120,9 @@ fn input( } } } -fn task_item_widget(task: S, stagger: Writer>>) -> impl WidgetBuilder +fn task_item_widget( + task: S, stagger: Writer>>, +) -> impl IntoWidgetStrict where S: StateWriter + 'static, S::OriginWriter: StateWriter, @@ -156,7 +158,7 @@ where watch!($checkbox.checked) .distinct_until_changed() .subscribe(move |v| $task.write().complete = v); - CustomEdgeWidget(checkbox.build(ctx!())) + CustomEdgeWidget(checkbox.into_widget(ctx!())) })) @Trailing(EdgeWidget::Icon({ let icon = svgs::CLOSE; @@ -169,7 +171,7 @@ where } } -pub fn todos() -> impl WidgetBuilder { +pub fn todos() -> impl IntoWidgetStrict { let todos = if cfg!(not(target_arch = "wasm32")) { let todos = State::value(Todos::load()); // save changes to disk every 5 seconds . diff --git a/examples/wordle_game/src/ui.rs b/examples/wordle_game/src/ui.rs index 14b04a891..92d4799a3 100644 --- a/examples/wordle_game/src/ui.rs +++ b/examples/wordle_game/src/ui.rs @@ -2,7 +2,7 @@ use ribir::prelude::*; use crate::wordle::{CharHint, Wordle, WordleChar}; -pub fn wordle_game() -> impl WidgetBuilder { +pub fn wordle_game() -> impl IntoWidgetStrict { fn_widget! { @ { Wordle::new(5, 5) } } } @@ -120,7 +120,7 @@ impl Wordle { }; } - fn char_grid(&self, row: usize, col: usize) -> impl WidgetBuilder + IntoWidget { + fn char_grid(&self, row: usize, col: usize) -> impl IntoWidgetStrict + IntoWidget { let char_hint = self.char_hint(row, col); let c = char_hint.map(|c| c.char).unwrap_or('\0'); let hint = char_hint.and_then(|c| c.hint); @@ -148,7 +148,7 @@ impl Wordle { } impl Compose for Wordle { - fn compose(this: impl StateWriter) -> impl WidgetBuilder { + fn compose(this: impl StateWriter) -> impl IntoWidgetStrict { fn_widget! { let state_bar = @Text { text: "" }; let keyboard = this.keyboard(state_bar.clone_writer()); diff --git a/macros/src/child_template.rs b/macros/src/child_template.rs index 109ff29a0..16436ec54 100644 --- a/macros/src/child_template.rs +++ b/macros/src/child_template.rs @@ -7,8 +7,7 @@ use syn::{ }; const BUILDER: &str = "Builder"; -const ASSOCIATED_TEMPLATE: &str = "AssociatedTemplate"; - +const TEMPLATE: &str = "Template"; fn with_child_generics(generics: &syn::Generics, child_ty: &Type, m: usize) -> syn::Generics { let mut gen = generics.clone(); gen.params.push(parse_quote!(_C)); @@ -34,6 +33,16 @@ pub(crate) fn derive_child_template(input: &mut syn::DeriveInput) -> syn::Result fn builder() -> Self::Builder { <_>::default() } } + impl #g_impl IntoChild<#name #g_ty, 0> for #builder #g_ty { + #[inline] + fn into_child(self, _: &BuildCtx) -> #name #g_ty { self.build_tml() } + } + + impl #g_impl IntoChild, 0> for #builder #g_ty { + #[inline] + fn into_child(self, _: &BuildCtx) -> Option<#name #g_ty> { Some(self.build_tml()) } + } + impl #g_impl std::convert::From<#builder #g_ty> for #name #g_ty #g_where { #[inline] #[track_caller] @@ -56,8 +65,8 @@ pub(crate) fn derive_child_template(input: &mut syn::DeriveInput) -> syn::Result }; let ty = option_type_extract(&f.ty).unwrap_or(&f.ty); - for m in 0..5 { - let with_m = 5 * f_idx + m; + for m in 0..4 { + let with_m = 4 * f_idx + m; let gen = with_child_generics(generics, ty, m); let (g_impl, _, g_where) = gen.split_for_impl(); tokens.extend(quote! { @@ -150,7 +159,7 @@ pub(crate) fn derive_child_template(input: &mut syn::DeriveInput) -> syn::Result }); } Fields::Unit => { - let err_str = format!("Can't derive `{ASSOCIATED_TEMPLATE}` for a empty template.",); + let err_str = format!("Can't derive `{TEMPLATE}` for a empty template.",); return Err(syn::Error::new(Span::call_site(), err_str)); } } @@ -177,8 +186,8 @@ pub(crate) fn derive_child_template(input: &mut syn::DeriveInput) -> syn::Result let f = unnamed.first().unwrap(); let ty = &f.ty; let v_name = &v.ident; - for m in 0..5 { - let with_m = 5 * i + m; + for m in 0..4 { + let with_m = 4 * i + m; let gen = with_child_generics(generics, ty, m); let (g_impl, _, g_where) = gen.split_for_impl(); tokens.extend(quote! { @@ -199,7 +208,7 @@ pub(crate) fn derive_child_template(input: &mut syn::DeriveInput) -> syn::Result }); } syn::Data::Union(u) => { - let err_str = format!("`{ASSOCIATED_TEMPLATE}` not support for Union"); + let err_str = format!("`{TEMPLATE}` not support for Union"); return Err(syn::Error::new(u.union_token.span(), err_str)); } } diff --git a/ribir/src/app.rs b/ribir/src/app.rs index 9f723da6a..5c271511b 100644 --- a/ribir/src/app.rs +++ b/ribir/src/app.rs @@ -182,7 +182,7 @@ impl App { /// /// Upon being dropped, it creates a new window with the `root` widget and /// then calls `App::exec`. -pub struct AppRunGuard { +pub struct AppRunGuard> { root: Option, wnd_attrs: Option, } @@ -192,7 +192,9 @@ impl App { /// theme to create an application and use the `root` widget to create a /// window, then run the application. #[track_caller] - pub fn run(root: W) -> AppRunGuard { AppRunGuard::new(root) } + pub fn run>(root: W) -> AppRunGuard { + AppRunGuard::new(root) + } /// Get a event sender of the application event loop, you can use this to send /// event. @@ -202,7 +204,7 @@ impl App { /// Note: This is exclusive to the web platform. #[cfg(target_family = "wasm")] pub async fn new_with_canvas( - root: impl WidgetBuilder, canvas: web_sys::HtmlCanvasElement, attrs: WindowAttributes, + root: impl IntoWidgetStrict, canvas: web_sys::HtmlCanvasElement, attrs: WindowAttributes, ) -> std::rc::Rc { let app = unsafe { App::shared_mut() }; let event_loop = app.event_loop.as_ref().expect( @@ -214,8 +216,8 @@ impl App { } /// create a new window with the `root` widget - pub async fn new_window( - root: impl WidgetBuilder, attrs: WindowAttributes, + pub async fn new_window( + root: impl IntoWidget, attrs: WindowAttributes, ) -> std::rc::Rc { let app = unsafe { App::shared_mut() }; let event_loop = app.event_loop.as_ref().expect( @@ -313,7 +315,7 @@ impl App { } } -impl AppRunGuard { +impl> AppRunGuard { fn new(root: W) -> Self { static ONCE: std::sync::Once = std::sync::Once::new(); assert!(!ONCE.is_completed(), "App::run can only be called once."); @@ -398,7 +400,7 @@ impl AppRunGuard { } } -impl Drop for AppRunGuard { +impl> Drop for AppRunGuard { fn drop(&mut self) { let root = self.root.take().unwrap(); let attr = self.wnd_attrs.take().unwrap(); @@ -590,7 +592,7 @@ mod tests { log: Rc>>, } impl Compose for LogImeEvent { - fn compose(this: impl StateWriter) -> impl WidgetBuilder { + fn compose(this: impl StateWriter) -> impl IntoWidgetStrict { fn_widget! { @MockBox { size: INFINITY_SIZE, diff --git a/tests/benches/core_bench.rs b/tests/benches/core_bench.rs index d081817cb..87fc2f8a0 100644 --- a/tests/benches/core_bench.rs +++ b/tests/benches/core_bench.rs @@ -8,7 +8,7 @@ pub struct Embed { } impl Compose for Embed { - fn compose(this: impl StateWriter) -> impl WidgetBuilder { + fn compose(this: impl StateWriter) -> impl IntoWidgetStrict { fn_widget! { let recursive_child: Widget = if $this.depth > 1 { let width = $this.width; @@ -35,7 +35,7 @@ pub struct Recursive { } impl Compose for Recursive { - fn compose(this: impl StateWriter) -> impl WidgetBuilder { + fn compose(this: impl StateWriter) -> impl IntoWidgetStrict { fn_widget! { @MockMulti { @{ diff --git a/tests/benches/widgets_bench.rs b/tests/benches/widgets_bench.rs index 51e7c75f8..3a6585bd7 100644 --- a/tests/benches/widgets_bench.rs +++ b/tests/benches/widgets_bench.rs @@ -1,7 +1,7 @@ use criterion::{criterion_group, criterion_main, Bencher, Criterion}; use ribir::{core::test_helper::*, prelude::*}; -fn widget_bench(b: &mut Bencher, w: impl WidgetBuilder) { +fn widget_bench(b: &mut Bencher, w: impl IntoWidgetStrict) { let mut wnd = TestWindow::new(w); b.iter(|| wnd.draw_frame()); AppCtx::remove_wnd(wnd.id()) diff --git a/tests/child_template_derive_test.rs b/tests/child_template_derive_test.rs index 6ab85869e..d2ed69173 100644 --- a/tests/child_template_derive_test.rs +++ b/tests/child_template_derive_test.rs @@ -17,7 +17,7 @@ struct ChildTemplateOfP { impl ComposeChild for P { type Child = ChildTemplateOfP; - fn compose_child(_: impl StateWriter, _: Self::Child) -> impl WidgetBuilder { + fn compose_child(_: impl StateWriter, _: Self::Child) -> impl IntoWidgetStrict { fn_widget!(Void) } } @@ -32,7 +32,7 @@ struct TupleStructTemplate(ChildA, Option, Option); impl ComposeChild for P2 { type Child = TupleStructTemplate; - fn compose_child(_: impl StateWriter, _: Self::Child) -> impl WidgetBuilder { + fn compose_child(_: impl StateWriter, _: Self::Child) -> impl IntoWidgetStrict { fn_widget!(Void) } } @@ -50,7 +50,7 @@ enum EnumTml { impl ComposeChild for P3 { type Child = EnumTml; - fn compose_child(_: impl StateWriter, _: Self::Child) -> impl WidgetBuilder { + fn compose_child(_: impl StateWriter, _: Self::Child) -> impl IntoWidgetStrict { fn_widget!(Void) } } diff --git a/tests/path_child_test.rs b/tests/path_child_test.rs index f38c495d4..eed442b5c 100644 --- a/tests/path_child_test.rs +++ b/tests/path_child_test.rs @@ -7,7 +7,7 @@ enum AB { const SIZE_ONE: Size = Size::new(1., 1.); impl Compose for AB { - fn compose(this: impl StateWriter) -> impl WidgetBuilder { + fn compose(this: impl StateWriter) -> impl IntoWidgetStrict { fn_widget! { @SizedBox { size: match *$this { @@ -33,10 +33,10 @@ fn path_widget() { let _ = fn_widget! { AB::b() }; } -fn tuple_widget() -> impl WidgetBuilder { +fn tuple_widget() -> impl IntoWidgetStrict { struct TupleBox(Size); impl Compose for TupleBox { - fn compose(this: impl StateWriter) -> impl WidgetBuilder { + fn compose(this: impl StateWriter) -> impl IntoWidgetStrict { fn_widget! { @SizedBox { size: pipe!($this.0), diff --git a/tests/rdl_macro_test.rs b/tests/rdl_macro_test.rs index 2157e91e1..df8f7c862 100644 --- a/tests/rdl_macro_test.rs +++ b/tests/rdl_macro_test.rs @@ -7,14 +7,14 @@ use ribir::{ use ribir_dev_helper::*; use winit::event::{DeviceId, ElementState, MouseButton, WindowEvent}; -fn simplest_leaf_rdl() -> impl WidgetBuilder { +fn simplest_leaf_rdl() -> impl IntoWidgetStrict { fn_widget! { rdl!{ SizedBox { size: Size::new(500.,500.) } } } } widget_layout_test!(simplest_leaf_rdl, width == 500., height == 500.,); -fn with_child_rdl() -> impl WidgetBuilder { +fn with_child_rdl() -> impl IntoWidgetStrict { fn_widget! { rdl!{ Row { @@ -25,7 +25,7 @@ fn with_child_rdl() -> impl WidgetBuilder { } widget_layout_test!(with_child_rdl, width == 500., height == 500.,); -fn with_builtin_child_rdl() -> impl WidgetBuilder { +fn with_builtin_child_rdl() -> impl IntoWidgetStrict { fn_widget! { rdl!{ SizedBox { size: Size::new(500.,500.), @@ -35,7 +35,7 @@ fn with_builtin_child_rdl() -> impl WidgetBuilder { } widget_layout_test!(with_builtin_child_rdl, width == 520., height == 520.,); -fn rdl_with_child() -> impl WidgetBuilder { +fn rdl_with_child() -> impl IntoWidgetStrict { fn_widget! { let single_p = rdl!{ SizedBox { size: Size::new(500.,500.) }}; rdl!{ $single_p { rdl!{ Void } } } @@ -43,7 +43,7 @@ fn rdl_with_child() -> impl WidgetBuilder { } widget_layout_test!(rdl_with_child, width == 500., height == 500.,); -fn single_rdl_has_builtin_with_child() -> impl WidgetBuilder { +fn single_rdl_has_builtin_with_child() -> impl IntoWidgetStrict { fn_widget! { let single_p = rdl!{ SizedBox { size: Size::new(500.,500.), @@ -54,7 +54,7 @@ fn single_rdl_has_builtin_with_child() -> impl WidgetBuilder { } widget_layout_test!(single_rdl_has_builtin_with_child, width == 520., height == 520.,); -fn multi_child_rdl_has_builtin_with_child() -> impl WidgetBuilder { +fn multi_child_rdl_has_builtin_with_child() -> impl IntoWidgetStrict { fn_widget! { let multi_p = rdl!{ Flex { margin: EdgeInsets::all(10.) @@ -64,7 +64,7 @@ fn multi_child_rdl_has_builtin_with_child() -> impl WidgetBuilder { } widget_layout_test!(multi_child_rdl_has_builtin_with_child, width == 20., height == 20.,); -fn compose_child_rdl_has_builtin_with_child() -> impl WidgetBuilder { +fn compose_child_rdl_has_builtin_with_child() -> impl IntoWidgetStrict { fn_widget! { let multi_p = rdl!{ Row { margin: EdgeInsets::all(10.) }}; rdl!{ $multi_p { rdl!{ Void {} }} } @@ -72,7 +72,7 @@ fn compose_child_rdl_has_builtin_with_child() -> impl WidgetBuilder { } widget_layout_test!(compose_child_rdl_has_builtin_with_child, width == 20., height == 20.,); -fn access_rdl_widget() -> impl WidgetBuilder { +fn access_rdl_widget() -> impl IntoWidgetStrict { fn_widget! { let b = rdl!{ SizedBox {size: Size::new(500.,500.)}}; rdl!{ Row { @@ -83,7 +83,7 @@ fn access_rdl_widget() -> impl WidgetBuilder { } widget_layout_test!(access_rdl_widget, width == 1000., height == 500.,); -fn access_builtin_rdl_widget() -> impl WidgetBuilder { +fn access_builtin_rdl_widget() -> impl IntoWidgetStrict { fn_widget! { let mut b = rdl!{ SizedBox { size: Size::new(100.,100.), @@ -105,7 +105,7 @@ fn access_builtin_rdl_widget() -> impl WidgetBuilder { } widget_layout_test!(access_builtin_rdl_widget, width == 240., height == 120.,); -fn dollar_as_rdl_parent() -> impl WidgetBuilder { +fn dollar_as_rdl_parent() -> impl IntoWidgetStrict { fn_widget! { let b = rdl!{SizedBox { size: Size::new(500.,500.) }}; rdl!{ $b { rdl!{ Void {}} } } @@ -113,7 +113,7 @@ fn dollar_as_rdl_parent() -> impl WidgetBuilder { } widget_layout_test!(dollar_as_rdl_parent, width == 500., height == 500.,); -fn dollar_as_middle_parent() -> impl WidgetBuilder { +fn dollar_as_middle_parent() -> impl IntoWidgetStrict { fn_widget! { let b = rdl!{ SizedBox { size: Size::new(500.,500.) }}; rdl!{ Row { rdl!{ $b { rdl!{ Void {} } } } } } @@ -121,7 +121,7 @@ fn dollar_as_middle_parent() -> impl WidgetBuilder { } widget_layout_test!(dollar_as_middle_parent, width == 500., height == 500.,); -fn pipe_as_field_value() -> impl WidgetBuilder { +fn pipe_as_field_value() -> impl IntoWidgetStrict { let size = Stateful::new(Size::zero()); let size2 = size.clone_watcher(); let w = fn_widget! { @@ -132,7 +132,7 @@ fn pipe_as_field_value() -> impl WidgetBuilder { } widget_layout_test!(pipe_as_field_value, width == 100., height == 100.,); -fn pipe_as_builtin_field_value() -> impl WidgetBuilder { +fn pipe_as_builtin_field_value() -> impl IntoWidgetStrict { let margin = Stateful::new(EdgeInsets::all(0.)); let margin2 = margin.clone_watcher(); @@ -147,7 +147,7 @@ fn pipe_as_builtin_field_value() -> impl WidgetBuilder { } widget_layout_test!(pipe_as_builtin_field_value, width == 100., height == 100.,); -fn pipe_with_ctx() -> impl WidgetBuilder { +fn pipe_with_ctx() -> impl IntoWidgetStrict { let scale = Stateful::new(1.); let scale2 = scale.clone_writer(); let w = fn_widget! { @@ -160,7 +160,7 @@ fn pipe_with_ctx() -> impl WidgetBuilder { } widget_layout_test!(pipe_with_ctx, width == 36., height == 36.,); -fn pipe_with_builtin_field() -> impl WidgetBuilder { +fn pipe_with_builtin_field() -> impl IntoWidgetStrict { fn_widget! { let mut box1 = @SizedBox { size: Size::zero(), margin: EdgeInsets::all(1.) }; let box2 = @SizedBox { size: $box1.size, margin: pipe!($box1.margin) }; @@ -172,7 +172,7 @@ fn pipe_with_builtin_field() -> impl WidgetBuilder { } widget_layout_test!(pipe_with_builtin_field, width == 4., height == 2.,); -fn capture_closure_used_ctx() -> impl WidgetBuilder { +fn capture_closure_used_ctx() -> impl IntoWidgetStrict { fn_widget! { let size_box = @SizedBox { size: ZERO_SIZE }; @ $size_box { @@ -291,14 +291,14 @@ fn pipe_as_multi_child() { assert_layout_result_by_path!(wnd, { path = [0], width == 300., height == 100., }); } -fn at_in_widget_macro() -> impl WidgetBuilder { +fn at_in_widget_macro() -> impl IntoWidgetStrict { fn_widget! { @SizedBox { size: Size::new(100., 100.) } } } widget_layout_test!(at_in_widget_macro, width == 100., height == 100.,); -fn at_as_variable_in_widget() -> impl WidgetBuilder { +fn at_as_variable_in_widget() -> impl IntoWidgetStrict { fn_widget! { let size = Size::new(100., 100.); let row = @Row {}; @@ -312,7 +312,7 @@ fn at_as_variable_in_widget() -> impl WidgetBuilder { } widget_layout_test!(at_as_variable_in_widget, width == 200., height == 100.,); -fn at_as_variable_in_rdl() -> impl WidgetBuilder { +fn at_as_variable_in_rdl() -> impl IntoWidgetStrict { fn_widget! { let size = Size::new(100., 100.); let row = @Row {}; @@ -326,7 +326,7 @@ fn at_as_variable_in_rdl() -> impl WidgetBuilder { } widget_layout_test!(at_as_variable_in_rdl, width == 200., height == 100.,); -fn access_builtin_field_by_dollar() -> impl WidgetBuilder { +fn access_builtin_field_by_dollar() -> impl IntoWidgetStrict { fn_widget! { let size = Size::new(100., 100.); let mut box1 = @SizedBox { size, margin: EdgeInsets::all(10.) }; @@ -354,7 +354,7 @@ fn closure_in_fn_widget_capture() { assert_eq!(&**hi_res2.read(), "hi"); } -fn at_embed_in_expression() -> impl WidgetBuilder { +fn at_embed_in_expression() -> impl IntoWidgetStrict { fn_widget! { @Row { @{ (0..3).map(|_| { @@ -559,7 +559,7 @@ fn bind_fields() { assert_eq!(size, Size::new(8., 4.)); } -fn local_var_not_bind() -> impl WidgetBuilder { +fn local_var_not_bind() -> impl IntoWidgetStrict { const EXPECT_SIZE: Size = Size::new(5., 5.); const BE_CLIPPED_SIZE: Size = Size::new(500., 500.); @@ -756,7 +756,7 @@ fn fix_subscribe_cancel_after_widget_drop() { assert_eq!(*notify_cnt.read(), 3); } -fn fix_local_assign_tuple() -> impl WidgetBuilder { +fn fix_local_assign_tuple() -> impl IntoWidgetStrict { fn_widget! { let _sized = @SizedBox { size: Size::new(1., 1.) }; let sized_box2 = @SizedBox { diff --git a/themes/material/src/lib.rs b/themes/material/src/lib.rs index dd3cf7ccc..56727e94d 100644 --- a/themes/material/src/lib.rs +++ b/themes/material/src/lib.rs @@ -262,7 +262,7 @@ fn override_compose_decorator(theme: &mut FullTheme) { .transition(transitions::LINEAR.of(ctx!()), ctx!()); thumb } - .build(ctx) + .into_widget(ctx) }); styles.override_compose_decorator::(|this, host, ctx| { fn_widget! { @@ -275,7 +275,7 @@ fn override_compose_decorator(theme: &mut FullTheme) { thumb } - .build(ctx) + .into_widget(ctx) }); styles.override_compose_decorator::(|style, host, ctx| { fn_widget! { @@ -304,7 +304,7 @@ fn override_compose_decorator(theme: &mut FullTheme) { .transition(transitions::EASE_IN.of(ctx!()), ctx!()); indicator } - .build(ctx) + .into_widget(ctx) }); styles.override_compose_decorator::(move |style, host, ctx| { fn_widget! { @@ -322,7 +322,7 @@ fn override_compose_decorator(theme: &mut FullTheme) { } } } - .build(ctx) + .into_widget(ctx) }); styles.override_compose_decorator::(move |style, host, ctx| { fn_widget! { @@ -345,7 +345,7 @@ fn override_compose_decorator(theme: &mut FullTheme) { } } } - .build(ctx) + .into_widget(ctx) }); styles.override_compose_decorator::(move |style, host, ctx| { fn_widget! { @@ -368,7 +368,7 @@ fn override_compose_decorator(theme: &mut FullTheme) { } } } - .build(ctx) + .into_widget(ctx) }); styles.override_compose_decorator::(move |style, host, ctx| { fn_widget! { @@ -391,7 +391,7 @@ fn override_compose_decorator(theme: &mut FullTheme) { } } } - .build(ctx) + .into_widget(ctx) }); let textfield = TextFieldThemeSuit::from_theme(&theme.palette, &theme.typography_theme); theme.custom_styles.set_custom_style(textfield); diff --git a/themes/material/src/ripple.rs b/themes/material/src/ripple.rs index 3a50c45be..0b6c16150 100644 --- a/themes/material/src/ripple.rs +++ b/themes/material/src/ripple.rs @@ -39,7 +39,7 @@ pub enum RippleBound { impl ComposeChild for Ripple { type Child = Widget; - fn compose_child(this: impl StateWriter, child: Self::Child) -> impl WidgetBuilder { + fn compose_child(this: impl StateWriter, child: Self::Child) -> impl IntoWidgetStrict { fn_widget! { let mut container = @Stack { fit: StackFit::Passthrough }; let ripple_at = $this.ripple_at.clone_writer(); diff --git a/themes/material/src/state_layer.rs b/themes/material/src/state_layer.rs index 17eab510e..f6e7ef86e 100644 --- a/themes/material/src/state_layer.rs +++ b/themes/material/src/state_layer.rs @@ -22,7 +22,7 @@ pub struct InteractiveLayer { } impl Compose for StateLayer { - fn compose(this: impl StateWriter) -> impl WidgetBuilder { + fn compose(this: impl StateWriter) -> impl IntoWidgetStrict { fn_widget! { @PathPaintKit { path: pipe!($this.path.clone()), @@ -35,7 +35,7 @@ impl Compose for StateLayer { impl ComposeChild for InteractiveLayer { type Child = Widget; - fn compose_child(this: impl StateWriter, child: Self::Child) -> impl WidgetBuilder { + fn compose_child(this: impl StateWriter, child: Self::Child) -> impl IntoWidgetStrict { fn_widget! { let mut host = @$child { }; let layer = @IgnorePointer { diff --git a/widgets/src/avatar.rs b/widgets/src/avatar.rs index 1f7ac8394..ac7e6018b 100644 --- a/widgets/src/avatar.rs +++ b/widgets/src/avatar.rs @@ -49,7 +49,7 @@ impl CustomStyle for AvatarStyle { pub struct AvatarDecorator; impl ComposeDecorator for AvatarDecorator { - fn compose_decorator(_: State, host: Widget) -> impl WidgetBuilder { fn_widget!(host) } + fn compose_decorator(_: State, host: Widget) -> impl IntoWidgetStrict { fn_widget!(host) } } #[derive(Template)] @@ -61,7 +61,7 @@ pub enum AvatarTemplate { impl ComposeChild for Avatar { type Child = AvatarTemplate; - fn compose_child(this: impl StateWriter, child: Self::Child) -> impl WidgetBuilder { + fn compose_child(this: impl StateWriter, child: Self::Child) -> impl IntoWidgetStrict { fn_widget! { @ { let AvatarStyle { diff --git a/widgets/src/buttons.rs b/widgets/src/buttons.rs index 8ba14b1a8..3155d1442 100644 --- a/widgets/src/buttons.rs +++ b/widgets/src/buttons.rs @@ -47,7 +47,7 @@ pub struct ButtonTemplate { impl ComposeChild for ButtonImpl { type Child = ButtonTemplate; - fn compose_child(this: impl StateWriter, child: Self::Child) -> impl WidgetBuilder { + fn compose_child(this: impl StateWriter, child: Self::Child) -> impl IntoWidgetStrict { let ButtonTemplate { icon, label } = child; fn_widget! { @ConstrainedBox { diff --git a/widgets/src/buttons/button.rs b/widgets/src/buttons/button.rs index 3eb501baf..c34d2b162 100644 --- a/widgets/src/buttons/button.rs +++ b/widgets/src/buttons/button.rs @@ -33,7 +33,7 @@ pub struct ButtonDecorator { } impl ComposeDecorator for ButtonDecorator { - fn compose_decorator(_: State, host: Widget) -> impl WidgetBuilder { fn_widget!(host) } + fn compose_decorator(_: State, host: Widget) -> impl IntoWidgetStrict { fn_widget!(host) } } /// Button usage @@ -70,7 +70,7 @@ pub struct Button { impl ComposeChild for Button { type Child = ButtonTemplate; - fn compose_child(this: impl StateWriter, child: Self::Child) -> impl WidgetBuilder { + fn compose_child(this: impl StateWriter, child: Self::Child) -> impl IntoWidgetStrict { let ButtonTemplate { icon, label } = &child; let button_type = match (&icon, &label) { (Some(_), Some(_)) => ButtonType::BOTH, diff --git a/widgets/src/buttons/fab_button.rs b/widgets/src/buttons/fab_button.rs index 5d018706c..9246df739 100644 --- a/widgets/src/buttons/fab_button.rs +++ b/widgets/src/buttons/fab_button.rs @@ -35,7 +35,7 @@ pub struct FabButtonDecorator { } impl ComposeDecorator for FabButtonDecorator { - fn compose_decorator(_: State, host: Widget) -> impl WidgetBuilder { fn_widget!(host) } + fn compose_decorator(_: State, host: Widget) -> impl IntoWidgetStrict { fn_widget!(host) } } /// FabButton usage @@ -81,7 +81,7 @@ pub struct FabButton { impl ComposeChild for FabButton { type Child = ButtonTemplate; - fn compose_child(this: impl StateWriter, child: Self::Child) -> impl WidgetBuilder { + fn compose_child(this: impl StateWriter, child: Self::Child) -> impl IntoWidgetStrict { let ButtonTemplate { icon, label } = &child; let button_type = match (&icon, &label) { (Some(_), Some(_)) => ButtonType::BOTH, diff --git a/widgets/src/buttons/filled_button.rs b/widgets/src/buttons/filled_button.rs index b81011b5e..a94bf086f 100644 --- a/widgets/src/buttons/filled_button.rs +++ b/widgets/src/buttons/filled_button.rs @@ -35,7 +35,7 @@ pub struct FilledButtonDecorator { } impl ComposeDecorator for FilledButtonDecorator { - fn compose_decorator(_: State, host: Widget) -> impl WidgetBuilder { fn_widget!(host) } + fn compose_decorator(_: State, host: Widget) -> impl IntoWidgetStrict { fn_widget!(host) } } /// FilledButton usage @@ -81,7 +81,7 @@ pub struct FilledButton { impl ComposeChild for FilledButton { type Child = ButtonTemplate; - fn compose_child(this: impl StateWriter, child: Self::Child) -> impl WidgetBuilder { + fn compose_child(this: impl StateWriter, child: Self::Child) -> impl IntoWidgetStrict { let ButtonTemplate { icon, label } = &child; let button_type = match (&icon, &label) { (Some(_), Some(_)) => ButtonType::BOTH, diff --git a/widgets/src/buttons/outlined_button.rs b/widgets/src/buttons/outlined_button.rs index 93f06a03e..53ada7bcb 100644 --- a/widgets/src/buttons/outlined_button.rs +++ b/widgets/src/buttons/outlined_button.rs @@ -37,7 +37,7 @@ pub struct OutlinedButtonDecorator { } impl ComposeDecorator for OutlinedButtonDecorator { - fn compose_decorator(_: State, host: Widget) -> impl WidgetBuilder { fn_widget!(host) } + fn compose_decorator(_: State, host: Widget) -> impl IntoWidgetStrict { fn_widget!(host) } } /// OutlinedButton usage @@ -83,7 +83,7 @@ pub struct OutlinedButton { impl ComposeChild for OutlinedButton { type Child = ButtonTemplate; - fn compose_child(this: impl StateWriter, child: Self::Child) -> impl WidgetBuilder { + fn compose_child(this: impl StateWriter, child: Self::Child) -> impl IntoWidgetStrict { let ButtonTemplate { icon, label } = &child; let button_type = match (&icon, &label) { (Some(_), Some(_)) => ButtonType::BOTH, diff --git a/widgets/src/checkbox.rs b/widgets/src/checkbox.rs index 6f83d0aed..0146a47ed 100644 --- a/widgets/src/checkbox.rs +++ b/widgets/src/checkbox.rs @@ -50,13 +50,17 @@ pub enum CheckboxTemplate { } impl ComposeDecorator for CheckBoxDecorator { - fn compose_decorator(_: State, host: Widget) -> impl WidgetBuilder { fn_widget!(host) } + fn compose_decorator(_: State, host: Widget) -> impl IntoWidgetStrict { + fn_widget!(host) + } } impl ComposeChild for Checkbox { type Child = Option; - fn compose_child(this: impl StateWriter, child: Self::Child) -> impl WidgetBuilder { + fn compose_child( + this: impl StateWriter, child: Self::Child, + ) -> impl IntoWidgetStrict { fn_widget! { let CheckBoxStyle { icon_size, @@ -77,7 +81,7 @@ impl ComposeChild for Checkbox { } }} } - }.build(ctx!()); + }.into_widget(ctx!()); let checkbox = if let Some(child) = child { let label = |label: Label| @Text { @@ -97,7 +101,7 @@ impl ComposeChild for Checkbox { }, } } - }.build(ctx!()) + }.into_widget(ctx!()) } else { icon }; @@ -129,7 +133,7 @@ mod tests { use super::*; - fn checked() -> impl WidgetBuilder { + fn checked() -> impl IntoWidgetStrict { fn_widget! { @Checkbox { checked: true } } } widget_test_suit!( @@ -140,7 +144,7 @@ mod tests { comparison = 0.001 ); - fn unchecked() -> impl WidgetBuilder { + fn unchecked() -> impl IntoWidgetStrict { fn_widget! { @Checkbox {} } } widget_test_suit!( @@ -151,7 +155,7 @@ mod tests { comparison = 0.001 ); - fn indeterminate() -> impl WidgetBuilder { + fn indeterminate() -> impl IntoWidgetStrict { fn_widget! { @Checkbox { checked: true, diff --git a/widgets/src/icon.rs b/widgets/src/icon.rs index 47f069ec0..b5c83ae5e 100644 --- a/widgets/src/icon.rs +++ b/widgets/src/icon.rs @@ -14,7 +14,7 @@ pub struct Icon { impl ComposeChild for Icon { type Child = Widget; - fn compose_child(this: impl StateWriter, child: Self::Child) -> impl WidgetBuilder { + fn compose_child(this: impl StateWriter, child: Self::Child) -> impl IntoWidgetStrict { fn_widget! { @SizedBox { size: pipe!($this.size), @@ -37,7 +37,7 @@ macro_rules! define_fixed_size_icon { impl ComposeChild for $name { type Child = Widget; fn compose_child(_: impl StateWriter, child: Self::Child) - -> impl WidgetBuilder + -> impl IntoWidgetStrict { fn_widget! { let icon = @Icon { size: IconSize::of(ctx!()).$field }; diff --git a/widgets/src/input.rs b/widgets/src/input.rs index 1127c9a1b..27a96db9c 100644 --- a/widgets/src/input.rs +++ b/widgets/src/input.rs @@ -261,7 +261,7 @@ impl ComposeChild for Input { type Child = Option; fn compose_child( this: impl StateWriter, placeholder: Self::Child, - ) -> impl WidgetBuilder { + ) -> impl IntoWidgetStrict { fn_widget! { let text = @Text { text: pipe!($this.text.clone()), @@ -288,7 +288,7 @@ impl ComposeChild for TextArea { type Child = Option; fn compose_child( this: impl StateWriter, placeholder: Self::Child, - ) -> impl WidgetBuilder { + ) -> impl IntoWidgetStrict { fn_widget! { let text = @Text { text: pipe!($this.text.clone()), @@ -404,7 +404,7 @@ where } }; - let text_widget = text.build(ctx!()); + let text_widget = text.into_widget(ctx!()); let text_widget = bind_point_listener( this.clone_writer(), text_widget, diff --git a/widgets/src/input/caret.rs b/widgets/src/input/caret.rs index 5a94090f0..79d5c39ec 100644 --- a/widgets/src/input/caret.rs +++ b/widgets/src/input/caret.rs @@ -7,7 +7,7 @@ pub struct Caret { } impl Compose for Caret { - fn compose(this: impl StateWriter) -> impl WidgetBuilder { + fn compose(this: impl StateWriter) -> impl IntoWidgetStrict { let blink_interval = Duration::from_millis(500); fn_widget! { let icon = $this.icon; diff --git a/widgets/src/input/selected_text.rs b/widgets/src/input/selected_text.rs index a4217de6d..5637810ce 100644 --- a/widgets/src/input/selected_text.rs +++ b/widgets/src/input/selected_text.rs @@ -18,7 +18,7 @@ impl CustomStyle for SelectedHighLightStyle { } impl Compose for SelectedHighLight { - fn compose(this: impl StateWriter) -> impl WidgetBuilder { + fn compose(this: impl StateWriter) -> impl IntoWidgetStrict { fn_widget! { let color = SelectedHighLightStyle::of(ctx!()).brush; @Stack { diff --git a/widgets/src/input/text_selectable.rs b/widgets/src/input/text_selectable.rs index 6faa4b4e4..78570bd05 100644 --- a/widgets/src/input/text_selectable.rs +++ b/widgets/src/input/text_selectable.rs @@ -135,7 +135,9 @@ pub(crate) fn bind_point_listener( impl ComposeChild for TextSelectable { type Child = FatObj>; - fn compose_child(this: impl StateWriter, text: Self::Child) -> impl WidgetBuilder { + fn compose_child( + this: impl StateWriter, text: Self::Child, + ) -> impl IntoWidgetStrict { let src = text.into_inner(); fn_widget! { @@ -162,7 +164,7 @@ impl ComposeChild for TextSelectable { } } }; - let text_widget = text.build(ctx!()); + let text_widget = text.into_widget(ctx!()); let text_widget = bind_point_listener( this.clone_writer(), text_widget, diff --git a/widgets/src/layout/constrained_box.rs b/widgets/src/layout/constrained_box.rs index e0f5cd8e1..7e8417a4d 100644 --- a/widgets/src/layout/constrained_box.rs +++ b/widgets/src/layout/constrained_box.rs @@ -28,7 +28,7 @@ mod tests { use super::*; use crate::prelude::*; - fn outside_fixed_clamp() -> impl WidgetBuilder { + fn outside_fixed_clamp() -> impl IntoWidgetStrict { fn_widget! { @SizedBox { size: Size::new(50., 50.), @@ -44,7 +44,7 @@ mod tests { {path =[0,0,0], width == 50., height == 50.,} ); - fn expand_one_axis() -> impl WidgetBuilder { + fn expand_one_axis() -> impl IntoWidgetStrict { fn_widget! { @Container { size: Size::new(256., 50.), @@ -62,7 +62,7 @@ mod tests { { path = [0, 0], width==256., height == 20. ,} ); - fn expand_both() -> impl WidgetBuilder { + fn expand_both() -> impl IntoWidgetStrict { fn_widget! { @Container { size: Size::new(256., 50.), diff --git a/widgets/src/layout/expanded.rs b/widgets/src/layout/expanded.rs index 0b3a26d2f..6862128c8 100644 --- a/widgets/src/layout/expanded.rs +++ b/widgets/src/layout/expanded.rs @@ -14,7 +14,7 @@ pub struct Expanded { impl ComposeChild for Expanded { type Child = Widget; #[inline] - fn compose_child(this: impl StateWriter, child: Self::Child) -> impl WidgetBuilder { + fn compose_child(this: impl StateWriter, child: Self::Child) -> impl IntoWidgetStrict { fn_widget! { @ConstrainedBox { clamp: BoxClamp { @@ -37,7 +37,7 @@ mod tests { use super::*; use crate::prelude::*; - fn expand_child_size_zero() -> impl WidgetBuilder { + fn expand_child_size_zero() -> impl IntoWidgetStrict { let size = Size::new(100., 50.); fn_widget! { @Row { @@ -60,7 +60,7 @@ mod tests { { path = [0, 2], width == 0., height == 50.,} ); - fn one_line_expanded() -> impl WidgetBuilder { + fn one_line_expanded() -> impl IntoWidgetStrict { let size = Size::new(100., 50.); fn_widget! { @Row { @@ -87,7 +87,7 @@ mod tests { { path = [0, 3], rect == ribir_geom::rect(300., 0., 200., 50.),} ); - fn wrap_expanded() -> impl WidgetBuilder { + fn wrap_expanded() -> impl IntoWidgetStrict { let size = Size::new(100., 50.); fn_widget! { @Row { diff --git a/widgets/src/layout/flex.rs b/widgets/src/layout/flex.rs index 675f507b6..b092979cd 100644 --- a/widgets/src/layout/flex.rs +++ b/widgets/src/layout/flex.rs @@ -370,7 +370,7 @@ mod tests { use super::*; use crate::prelude::*; - fn horizontal_line() -> impl WidgetBuilder { + fn horizontal_line() -> impl IntoWidgetStrict { fn_widget! { @Flex { @{ @@ -381,7 +381,7 @@ mod tests { } widget_layout_test!(horizontal_line, width == 100., height == 20.,); - fn vertical_line() -> impl WidgetBuilder { + fn vertical_line() -> impl IntoWidgetStrict { fn_widget! { @Flex { direction: Direction::Vertical, @@ -391,7 +391,7 @@ mod tests { } widget_layout_test!(vertical_line, width == 10., height == 200.,); - fn row_wrap() -> impl WidgetBuilder { + fn row_wrap() -> impl IntoWidgetStrict { let size = Size::new(200., 20.); fn_widget! { @Flex { @@ -409,7 +409,7 @@ mod tests { {path = [0, 2], rect == ribir_geom::rect(0., 20., 200., 20.),} ); - fn reverse_row_wrap() -> impl WidgetBuilder { + fn reverse_row_wrap() -> impl IntoWidgetStrict { let size = Size::new(200., 20.); fn_widget! { @Flex { @@ -428,7 +428,7 @@ mod tests { { path = [0, 2], rect == ribir_geom::rect(0., 0., 200., 20.),} ); - fn main_axis_gap() -> impl WidgetBuilder { + fn main_axis_gap() -> impl IntoWidgetStrict { fn_widget! { @Row { item_gap: 15., @@ -446,7 +446,7 @@ mod tests { { path = [0, 2], rect == ribir_geom::rect(230., 0., 30., 20.),} ); - fn main_axis_reverse_gap() -> impl WidgetBuilder { + fn main_axis_reverse_gap() -> impl IntoWidgetStrict { fn_widget! { @Row { item_gap: 15., @@ -465,7 +465,7 @@ mod tests { { path = [0, 2], rect == ribir_geom::rect(0., 0., 30., 20.),} ); - fn main_axis_expand() -> impl WidgetBuilder { + fn main_axis_expand() -> impl IntoWidgetStrict { fn_widget! { @Row { item_gap: 15., @@ -493,7 +493,7 @@ mod tests { { path = [0, 4], rect == ribir_geom::rect(470., 0., 30., 20.),} ); - fn cross_axis_gap() -> impl WidgetBuilder { + fn cross_axis_gap() -> impl IntoWidgetStrict { let size = Size::new(200., 20.); fn_widget! { @Flex { @@ -513,7 +513,7 @@ mod tests { { path = [0, 2], rect == ribir_geom::rect(0., 30., 200., 20.),} ); - fn cross_align(align: Align) -> impl WidgetBuilder { + fn cross_align(align: Align) -> impl IntoWidgetStrict { fn_widget! { @Row { align_items: align, @@ -524,7 +524,7 @@ mod tests { } } - fn start_cross_align() -> impl WidgetBuilder { cross_align(Align::Start) } + fn start_cross_align() -> impl IntoWidgetStrict { cross_align(Align::Start) } widget_layout_test!( start_cross_align, { path =[0], width == 300., height == 40., } @@ -533,7 +533,7 @@ mod tests { { path =[0, 2], rect == ribir_geom::rect(200., 0., 100., 40.),} ); - fn center_cross_align() -> impl WidgetBuilder { cross_align(Align::Center) } + fn center_cross_align() -> impl IntoWidgetStrict { cross_align(Align::Center) } widget_layout_test!( center_cross_align, { path =[0], width == 300., height == 40., } @@ -542,7 +542,7 @@ mod tests { { path =[0, 2], rect == ribir_geom::rect(200., 0., 100., 40.),} ); - fn end_cross_align() -> impl WidgetBuilder { cross_align(Align::End) } + fn end_cross_align() -> impl IntoWidgetStrict { cross_align(Align::End) } widget_layout_test!( end_cross_align, { path =[0], width == 300., height == 40., } @@ -551,7 +551,7 @@ mod tests { { path =[0, 2], rect == ribir_geom::rect(200., 0., 100., 40.),} ); - fn stretch_cross_align() -> impl WidgetBuilder { cross_align(Align::Stretch) } + fn stretch_cross_align() -> impl IntoWidgetStrict { cross_align(Align::Stretch) } widget_layout_test!( stretch_cross_align, wnd_size = Size::new(500., 40.), @@ -561,7 +561,7 @@ mod tests { { path =[0, 2], rect == ribir_geom::rect(200., 0., 100., 40.),} ); - fn main_align(justify_content: JustifyContent) -> impl WidgetBuilder { + fn main_align(justify_content: JustifyContent) -> impl IntoWidgetStrict { let item_size = Size::new(100., 20.); fn_widget! { @SizedBox { @@ -577,7 +577,7 @@ mod tests { } } - fn start_main_align() -> impl WidgetBuilder { main_align(JustifyContent::Start) } + fn start_main_align() -> impl IntoWidgetStrict { main_align(JustifyContent::Start) } widget_layout_test!( start_main_align, wnd_size = Size::new(500., 500.), @@ -587,7 +587,7 @@ mod tests { { path =[0, 0, 2], x == 200.,} ); - fn center_main_align() -> impl WidgetBuilder { main_align(JustifyContent::Center) } + fn center_main_align() -> impl IntoWidgetStrict { main_align(JustifyContent::Center) } widget_layout_test!( center_main_align, wnd_size = Size::new(500., 500.), @@ -597,7 +597,7 @@ mod tests { { path =[0, 0, 2], x == 300.,} ); - fn end_main_align() -> impl WidgetBuilder { main_align(JustifyContent::End) } + fn end_main_align() -> impl IntoWidgetStrict { main_align(JustifyContent::End) } widget_layout_test!( end_main_align, wnd_size = Size::new(500., 500.), @@ -607,7 +607,7 @@ mod tests { { path =[0, 0, 2], x == 400.,} ); - fn space_between_align() -> impl WidgetBuilder { main_align(JustifyContent::SpaceBetween) } + fn space_between_align() -> impl IntoWidgetStrict { main_align(JustifyContent::SpaceBetween) } widget_layout_test!( space_between_align, wnd_size = Size::new(500., 500.), @@ -617,7 +617,7 @@ mod tests { { path =[0, 0, 2], x == 400.,} ); - fn space_around_align() -> impl WidgetBuilder { main_align(JustifyContent::SpaceAround) } + fn space_around_align() -> impl IntoWidgetStrict { main_align(JustifyContent::SpaceAround) } const AROUND_SPACE: f32 = 200.0 / 3.0; widget_layout_test!( space_around_align, @@ -628,7 +628,7 @@ mod tests { { path =[0, 0, 2], x == 2.5 * AROUND_SPACE+ 200.,} ); - fn space_evenly_align() -> impl WidgetBuilder { main_align(JustifyContent::SpaceEvenly) } + fn space_evenly_align() -> impl IntoWidgetStrict { main_align(JustifyContent::SpaceEvenly) } widget_layout_test!( space_evenly_align, wnd_size = Size::new(500., 500.), @@ -638,7 +638,7 @@ mod tests { { path =[0, 0, 2], x == 350.,} ); - fn flex_expand() -> impl WidgetBuilder { + fn flex_expand() -> impl IntoWidgetStrict { fn_widget! { @SizedBox { size: Size::new(500., 25.), diff --git a/widgets/src/layout/sized_box.rs b/widgets/src/layout/sized_box.rs index 8cb899066..c3658031a 100644 --- a/widgets/src/layout/sized_box.rs +++ b/widgets/src/layout/sized_box.rs @@ -31,7 +31,7 @@ mod tests { use super::*; use crate::prelude::*; - fn fix_size() -> impl WidgetBuilder { + fn fix_size() -> impl IntoWidgetStrict { let size: Size = Size::new(100., 100.); fn_widget! { @SizedBox { @@ -42,7 +42,7 @@ mod tests { } widget_layout_test!(fix_size, width == 100., height == 100.,); - fn shrink_size() -> impl WidgetBuilder { + fn shrink_size() -> impl IntoWidgetStrict { fn_widget! { @SizedBox { size: ZERO_SIZE, @@ -56,7 +56,7 @@ mod tests { { path = [0, 0], size == ZERO_SIZE,} ); - fn expanded_size() -> impl WidgetBuilder { + fn expanded_size() -> impl IntoWidgetStrict { fn_widget! { @SizedBox { size: INFINITY_SIZE, @@ -71,6 +71,6 @@ mod tests { { path = [0, 0], size == INFINITY_SIZE,} ); - fn empty_box() -> impl WidgetBuilder { fn_widget!(SizedBox { size: Size::new(10., 10.) }) } + fn empty_box() -> impl IntoWidgetStrict { fn_widget!(SizedBox { size: Size::new(10., 10.) }) } widget_layout_test!(empty_box, width == 10., height == 10.,); } diff --git a/widgets/src/layout/stack.rs b/widgets/src/layout/stack.rs index 86bd1e67f..0dac84520 100644 --- a/widgets/src/layout/stack.rs +++ b/widgets/src/layout/stack.rs @@ -73,7 +73,7 @@ mod tests { use super::*; use crate::prelude::*; const FIVE: Size = Size::new(5., 5.); - fn smoke() -> impl WidgetBuilder { + fn smoke() -> impl IntoWidgetStrict { let one = Size::new(1., 1.); let five = Size::new(5., 5.); fn_widget! { diff --git a/widgets/src/link.rs b/widgets/src/link.rs index d498235c2..87cc431b6 100644 --- a/widgets/src/link.rs +++ b/widgets/src/link.rs @@ -13,7 +13,7 @@ pub struct Link { impl ComposeChild for Link { type Child = Widget; - fn compose_child(this: impl StateWriter, child: Self::Child) -> impl WidgetBuilder { + fn compose_child(this: impl StateWriter, child: Self::Child) -> impl IntoWidgetStrict { fn_widget! { @ $child { on_tap: move |_| { diff --git a/widgets/src/lists.rs b/widgets/src/lists.rs index d5f18ec69..df7283861 100644 --- a/widgets/src/lists.rs +++ b/widgets/src/lists.rs @@ -128,13 +128,13 @@ pub struct Lists; #[derive(Declare)] pub struct ListsDecorator {} impl ComposeDecorator for ListsDecorator { - fn compose_decorator(_: State, host: Widget) -> impl WidgetBuilder { fn_widget!(host) } + fn compose_decorator(_: State, host: Widget) -> impl IntoWidgetStrict { fn_widget!(host) } } impl ComposeChild for Lists { type Child = Vec; - fn compose_child(_: impl StateWriter, child: Self::Child) -> impl WidgetBuilder { + fn compose_child(_: impl StateWriter, child: Self::Child) -> impl IntoWidgetStrict { fn_widget! { @ListsDecorator { @Column { @ { child } } @@ -251,7 +251,7 @@ pub struct ListItemTml { impl ComposeChild for ListItem { type Child = ListItemTml; - fn compose_child(this: impl StateWriter, child: Self::Child) -> impl WidgetBuilder { + fn compose_child(this: impl StateWriter, child: Self::Child) -> impl IntoWidgetStrict { let ListItemTml { headline, supporting, leading, trailing } = child; fn_widget! { @@ -378,7 +378,7 @@ pub struct ListItemDecorator { } impl ComposeDecorator for ListItemDecorator { - fn compose_decorator(_: State, host: Widget) -> impl WidgetBuilder { + fn compose_decorator(_: State, host: Widget) -> impl IntoWidgetStrict { fn_widget! { host } } } diff --git a/widgets/src/scrollbar.rs b/widgets/src/scrollbar.rs index 3516101dd..fcbb8e2dd 100644 --- a/widgets/src/scrollbar.rs +++ b/widgets/src/scrollbar.rs @@ -29,7 +29,7 @@ pub struct HScrollBarThumbDecorator { } impl ComposeDecorator for HScrollBarThumbDecorator { - fn compose_decorator(this: State, host: Widget) -> impl WidgetBuilder { + fn compose_decorator(this: State, host: Widget) -> impl IntoWidgetStrict { fn_widget! { @$host { anchor: pipe!($this.offset).map(Anchor::left) } } } } @@ -42,14 +42,14 @@ pub struct VScrollBarThumbDecorator { } impl ComposeDecorator for VScrollBarThumbDecorator { - fn compose_decorator(this: State, host: Widget) -> impl WidgetBuilder { + fn compose_decorator(this: State, host: Widget) -> impl IntoWidgetStrict { fn_widget! { @$host { anchor: pipe!($this.offset).map(Anchor::top) } } } } impl ComposeChild for HScrollBar { type Child = Widget; - fn compose_child(this: impl StateWriter, child: Self::Child) -> impl WidgetBuilder { + fn compose_child(this: impl StateWriter, child: Self::Child) -> impl IntoWidgetStrict { fn_widget! { let mut scrolling = @ScrollableWidget { scrollable: Scrollable::X, @@ -92,7 +92,7 @@ pub struct VScrollBar { impl ComposeChild for VScrollBar { type Child = Widget; - fn compose_child(this: impl StateWriter, child: Self::Child) -> impl WidgetBuilder { + fn compose_child(this: impl StateWriter, child: Self::Child) -> impl IntoWidgetStrict { fn_widget! { let mut scrolling = @ScrollableWidget { scrollable: Scrollable::Y, @@ -135,7 +135,7 @@ pub struct BothScrollbar { impl ComposeChild for BothScrollbar { type Child = Widget; - fn compose_child(this: impl StateWriter, child: Self::Child) -> impl WidgetBuilder { + fn compose_child(this: impl StateWriter, child: Self::Child) -> impl IntoWidgetStrict { fn_widget! { let mut scrolling = @ScrollableWidget { scrollable: Scrollable::Both, @@ -178,7 +178,7 @@ pub struct HRawScrollbar { } impl Compose for HRawScrollbar { - fn compose(this: impl StateWriter) -> impl WidgetBuilder { + fn compose(this: impl StateWriter) -> impl IntoWidgetStrict { fn_widget! { @ { let scrolling = $this.scrolling.clone_watcher(); @@ -239,7 +239,7 @@ pub struct VRawScrollbar { } impl Compose for VRawScrollbar { - fn compose(this: impl StateWriter) -> impl WidgetBuilder { + fn compose(this: impl StateWriter) -> impl IntoWidgetStrict { fn_widget! { @ { let scrolling = $this.scrolling.clone_watcher(); @@ -311,7 +311,7 @@ mod test { use super::*; use crate::layout::{Column, ConstrainedBox}; - fn content_expand_so_all_view_can_scroll() -> impl WidgetBuilder { + fn content_expand_so_all_view_can_scroll() -> impl IntoWidgetStrict { fn_widget! { @ConstrainedBox { clamp: BoxClamp::EXPAND_BOTH, diff --git a/widgets/src/tabs.rs b/widgets/src/tabs.rs index 2ba4cd21e..0efac5ed9 100644 --- a/widgets/src/tabs.rs +++ b/widgets/src/tabs.rs @@ -104,7 +104,7 @@ impl CustomStyle for TabsStyle { pub struct TabsDecorator {} impl ComposeDecorator for TabsDecorator { - fn compose_decorator(_: State, host: Widget) -> impl WidgetBuilder { fn_widget!(host) } + fn compose_decorator(_: State, host: Widget) -> impl IntoWidgetStrict { fn_widget!(host) } } #[derive(Template)] @@ -125,7 +125,7 @@ pub struct TabPane(pub GenWidget); pub struct TabDecorator {} impl ComposeDecorator for TabDecorator { - fn compose_decorator(_: State, host: Widget) -> impl WidgetBuilder { fn_widget!(host) } + fn compose_decorator(_: State, host: Widget) -> impl IntoWidgetStrict { fn_widget!(host) } } #[derive(Declare)] @@ -136,7 +136,7 @@ pub struct IndicatorDecorator { } impl ComposeDecorator for IndicatorDecorator { - fn compose_decorator(this: State, host: Widget) -> impl WidgetBuilder { + fn compose_decorator(this: State, host: Widget) -> impl IntoWidgetStrict { fn_widget! { @ $host{ anchor: pipe!{ @@ -225,7 +225,7 @@ impl Tabs { impl ComposeChild for Tabs { type Child = Vec; - fn compose_child(this: impl StateWriter, child: Self::Child) -> impl WidgetBuilder { + fn compose_child(this: impl StateWriter, child: Self::Child) -> impl IntoWidgetStrict { let mut headers = vec![]; let mut panes = vec![]; diff --git a/widgets/src/text.rs b/widgets/src/text.rs index fff2fa1ed..af51da2ba 100644 --- a/widgets/src/text.rs +++ b/widgets/src/text.rs @@ -74,7 +74,7 @@ macro_rules! define_text_with_theme_style { } impl Compose for $name { - fn compose(this: impl StateWriter) -> impl WidgetBuilder { + fn compose(this: impl StateWriter) -> impl IntoWidgetStrict { fn_widget! { @Text { text: pipe!($this.text.clone()), diff --git a/widgets/src/text_field.rs b/widgets/src/text_field.rs index 512b86823..d7da0e3c2 100644 --- a/widgets/src/text_field.rs +++ b/widgets/src/text_field.rs @@ -104,7 +104,7 @@ type TextFieldThemeProxy = ThemeSuitProxy; impl ComposeChild for TextFieldThemeProxy { type Child = Widget; - fn compose_child(this: impl StateWriter, child: Self::Child) -> impl WidgetBuilder { + fn compose_child(this: impl StateWriter, child: Self::Child) -> impl IntoWidgetStrict { fn_widget! { @ $child { on_tap: move |_| { @@ -274,7 +274,7 @@ impl ComposeChild for TextField { type Child = Option; fn compose_child( this: impl StateWriter, config: Self::Child, - ) -> impl WidgetBuilder { + ) -> impl IntoWidgetStrict { fn_widget! { let mut config = config.unwrap_or_default(); take_option_field!({leading_icon, trailing_icon}, config); @@ -384,7 +384,7 @@ struct TextFieldLabel { } impl Compose for TextFieldLabel { - fn compose(this: impl StateWriter) -> impl WidgetBuilder { + fn compose(this: impl StateWriter) -> impl IntoWidgetStrict { fn_widget! { let label = @Text { v_align: VAlign::Top, @@ -403,7 +403,7 @@ impl Compose for TextFieldLabel { fn build_content_area( this: impl StateWriter, theme: State, mut config: TextFieldTml, -) -> impl WidgetBuilder + IntoWidgetStrict { +) -> impl IntoWidgetStrict + IntoWidgetStrict { fn_widget! { take_option_field!({label, prefix, suffix, placeholder}, config); let mut content_area = @Column { diff --git a/widgets/src/transform_box.rs b/widgets/src/transform_box.rs index 83e71fe12..0e87cc292 100644 --- a/widgets/src/transform_box.rs +++ b/widgets/src/transform_box.rs @@ -45,7 +45,7 @@ mod tests { use super::*; use crate::prelude::*; - fn smoke() -> impl WidgetBuilder { + fn smoke() -> impl IntoWidgetStrict { fn_widget! { @TransformBox { matrix: Transform::new(2., 0., 0., 2., 0., 0.),