diff --git a/xilem_core/src/view.rs b/xilem_core/src/view.rs index 75e491a875..93c1d41f67 100644 --- a/xilem_core/src/view.rs +++ b/xilem_core/src/view.rs @@ -164,5 +164,15 @@ pub trait View: crate::map_action(self, f) } + #[doc(hidden)] + /// An identity function, that lets us assert that + /// the receiver always implements WidgetView<..> + fn check_impl_view(self) -> Self + where + Self: Sized, + { + self + } + // fn debug_name? } diff --git a/xilem_masonry/src/view/button.rs b/xilem_masonry/src/view/button.rs index a161eaca73..736f8dc4de 100644 --- a/xilem_masonry/src/view/button.rs +++ b/xilem_masonry/src/view/button.rs @@ -74,16 +74,19 @@ use crate::{Pod, ViewCtx, WidgetView}; /// ``` pub fn button< State: ViewArgument, - Action, + Action: 'static, V: WidgetView, - F: Fn(Arg<'_, State>) -> Action + Send + 'static, + F: Fn(Arg<'_, State>) -> Action + Send + Sync + 'static, >( child: V, callback: F, ) -> Button< State, Action, - impl for<'a> Fn(Arg<'_, State>, Option) -> MessageResult + Send + 'static, + impl for<'a> Fn(Arg<'_, State>, Option) -> MessageResult + + Send + + Sync + + 'static, V, > { Button { @@ -95,6 +98,7 @@ pub fn button< disabled: false, phantom: PhantomData, } + .check_impl_widget_view() } /// A button with default styled text. @@ -102,7 +106,7 @@ pub fn button< /// This is equivalent to `button(label(text), callback)`, and is useful for /// making buttons quickly from string literals. /// For more advanced text styling, prefer [`button`]. -pub fn text_button( +pub fn text_button( text: impl Into, callback: impl Fn(Arg<'_, State>) -> Action + Send + Sync + 'static, ) -> Button< @@ -127,7 +131,7 @@ pub fn text_button( /// Similarly, there is not currently long-press support. /// /// For more documentation and examples, see [`button`]. -pub fn button_any_pointer>( +pub fn button_any_pointer>( child: V, callback: impl Fn(Arg<'_, State>, Option) -> Action + Send + Sync + 'static, ) -> Button< diff --git a/xilem_masonry/src/view/checkbox.rs b/xilem_masonry/src/view/checkbox.rs index 9983017b6a..c38bfe2612 100644 --- a/xilem_masonry/src/view/checkbox.rs +++ b/xilem_masonry/src/view/checkbox.rs @@ -8,6 +8,7 @@ use masonry::parley::StyleProperty; use masonry::parley::style::{FontStack, FontWeight}; use masonry::widgets::{self, CheckboxToggled}; +use crate::WidgetView as _; use crate::core::{Arg, MessageCtx, MessageResult, Mut, View, ViewArgument, ViewMarker}; use crate::{Pod, ViewCtx}; @@ -30,13 +31,13 @@ use crate::{Pod, ViewCtx}; /// }) /// # } /// ``` -pub fn checkbox( +pub fn checkbox( label: impl Into, checked: bool, callback: F, ) -> Checkbox where - F: Fn(Arg<'_, State>, bool) -> Action + Send + 'static, + F: Fn(Arg<'_, State>, bool) -> Action + Send + Sync + 'static, State: ViewArgument, { Checkbox { @@ -49,6 +50,7 @@ where disabled: false, phantom: PhantomData, } + .check_impl_widget_view() } /// The [`View`] created by [`checkbox`] from a `label`, a bool value and a callback. diff --git a/xilem_masonry/src/view/flex.rs b/xilem_masonry/src/view/flex.rs index 330161bf3b..ec70babc97 100644 --- a/xilem_masonry/src/view/flex.rs +++ b/xilem_masonry/src/view/flex.rs @@ -82,7 +82,7 @@ use crate::{AnyWidgetView, Pod, ViewCtx, WidgetView}; /// .cross_axis_alignment(CrossAxisAlignment::Center) /// } /// ``` -pub fn flex>( +pub fn flex>( axis: Axis, sequence: Seq, ) -> Flex { @@ -94,6 +94,7 @@ pub fn flex>( fill_major_axis: false, phantom: PhantomData, } + .check_impl_widget_view() } /// A layout where the children are laid out in a row. @@ -102,7 +103,7 @@ pub fn flex>( /// [`direction`](Flex::direction). /// We recommend reading that type's documentation for a detailed /// explanation of this component's layout model. -pub fn flex_row>( +pub fn flex_row>( sequence: Seq, ) -> Flex { flex(Axis::Horizontal, sequence) @@ -114,7 +115,7 @@ pub fn flex_row>( /// [`direction`](Flex::direction). /// We recommend reading that type's documentation for a detailed /// explanation of this component's layout model. -pub fn flex_col>( +pub fn flex_col>( sequence: Seq, ) -> Flex { flex(Axis::Vertical, sequence) @@ -451,17 +452,17 @@ impl ElementSplice for FlexSplice<'_, '_> { /// } /// ``` pub trait FlexSequence: - ViewSequence + ViewSequence + Send + Sync { } impl FlexSequence for Seq where - Seq: ViewSequence + Seq: ViewSequence + Send + Sync { } /// A trait which extends a [`WidgetView`] with methods to provide parameters for a flex item, or being able to use it interchangeably with a spacer. -pub trait FlexExt: WidgetView { +pub trait FlexExt: WidgetView { /// Applies [`impl Into`](`FlexParams`) to this view, can be used as child of a [`Flex`] [`View`] /// /// # Examples @@ -515,7 +516,10 @@ pub trait FlexExt: WidgetView { } } -impl> FlexExt for V {} +impl> FlexExt + for V +{ +} /// A `WidgetView` that can be used within a [`Flex`] [`View`]. pub struct FlexItem { diff --git a/xilem_masonry/src/view/grid.rs b/xilem_masonry/src/view/grid.rs index 35c736eb77..c788f03b05 100644 --- a/xilem_masonry/src/view/grid.rs +++ b/xilem_masonry/src/view/grid.rs @@ -46,7 +46,7 @@ pub use masonry::widgets::GridParams; /// .gap(GRID_GAP) /// ``` /// Also see Calculator example [here](https://github.com/linebender/xilem/blob/main/xilem/examples/calc.rs) to learn more about grid layout. -pub fn grid>( +pub fn grid>( sequence: Seq, width: i32, height: i32, @@ -57,6 +57,7 @@ pub fn grid>( width, phantom: PhantomData, } + .check_impl_widget_view() } /// The [`View`] created by [`grid`] from a sequence, which also consumes custom width and height. @@ -286,19 +287,19 @@ impl ElementSplice for GridSplice<'_, '_> { /// `GridSequence` is what allows an input to the grid that contains all the grid elements. pub trait GridSequence: - ViewSequence + ViewSequence + Send + Sync { } impl GridSequence for Seq where - Seq: ViewSequence, + Seq: ViewSequence + Send + Sync, State: ViewArgument, { } /// A trait which extends a [`WidgetView`] with methods to provide parameters for a grid item -pub trait GridExt: WidgetView { +pub trait GridExt: WidgetView { /// Applies [`impl Into`](`GridParams`) to this view. This allows the view /// to be placed as a child within a [`Grid`] [`View`]. /// @@ -352,7 +353,10 @@ pub trait GridExt: WidgetView { } } -impl> GridExt for V {} +impl> GridExt + for V +{ +} /// A child widget within a [`Grid`] view. pub struct GridElement { diff --git a/xilem_masonry/src/view/indexed_stack.rs b/xilem_masonry/src/view/indexed_stack.rs index 2450aaab19..9f72682823 100644 --- a/xilem_masonry/src/view/indexed_stack.rs +++ b/xilem_masonry/src/view/indexed_stack.rs @@ -10,7 +10,7 @@ use crate::core::{ AppendVec, Arg, ElementSplice, MessageCtx, MessageResult, Mut, SuperElement, View, ViewArgument, ViewElement, ViewMarker, ViewSequence, }; -use crate::{Pod, ViewCtx}; +use crate::{Pod, ViewCtx, WidgetView}; /// An `IndexedStack` displays one of several children elements at a time. /// @@ -50,7 +50,11 @@ use crate::{Pod, ViewCtx}; /// ) /// .active(state.tab); /// ``` -pub fn indexed_stack>( +pub fn indexed_stack< + State: ViewArgument, + Action: 'static, + Seq: IndexedStackSequence, +>( sequence: Seq, ) -> IndexedStack { IndexedStack { @@ -58,6 +62,7 @@ pub fn indexed_stack for IndexedStackSplice<'_, '_> { /// `IndexedStackSequence` is what allows an input to the indexed stack that contains all the stack elements. pub trait IndexedStackSequence: - ViewSequence + ViewSequence + Send + Sync { } impl IndexedStackSequence for Seq where - Seq: ViewSequence, + Seq: ViewSequence + Send + Sync, State: ViewArgument, { } diff --git a/xilem_masonry/src/view/label.rs b/xilem_masonry/src/view/label.rs index 42deceb8e0..6cd3d23ac4 100644 --- a/xilem_masonry/src/view/label.rs +++ b/xilem_masonry/src/view/label.rs @@ -7,7 +7,7 @@ use masonry::parley::{FontFamily, GenericFamily}; use masonry::widgets; use crate::core::{Arg, MessageCtx, MessageResult, Mut, View, ViewArgument, ViewMarker}; -use crate::{Pod, TextAlign, ViewCtx}; +use crate::{Pod, TextAlign, ViewCtx, WidgetView}; /// A non-interactive text element. /// # Example @@ -33,13 +33,13 @@ use crate::{Pod, TextAlign, ViewCtx}; /// # } /// ``` pub fn label(label: impl Into) -> Label { - Label { + WidgetView::<()>::check_impl_widget_view(Label { label: label.into(), text_alignment: TextAlign::default(), text_size: masonry::theme::TEXT_SIZE_NORMAL, weight: FontWeight::NORMAL, font: FontStack::Single(FontFamily::Generic(GenericFamily::SystemUi)), - } + }) } /// The [`View`] created by [`label`] from a text which `impl Into<`[`ArcStr`]`>`. diff --git a/xilem_masonry/src/view/portal.rs b/xilem_masonry/src/view/portal.rs index dc71bbe172..0b48ba07ac 100644 --- a/xilem_masonry/src/view/portal.rs +++ b/xilem_masonry/src/view/portal.rs @@ -11,7 +11,7 @@ use crate::{Pod, ViewCtx, WidgetView}; /// A view which puts `child` into a scrollable region. /// /// This corresponds to the Masonry [`Portal`](masonry::widgets::Portal) widget. -pub fn portal(child: Child) -> Portal +pub fn portal(child: Child) -> Portal where State: ViewArgument, Child: WidgetView, @@ -20,6 +20,7 @@ where child, phantom: PhantomData, } + .check_impl_widget_view() } /// The [`View`] created by [`portal`]. diff --git a/xilem_masonry/src/view/progress_bar.rs b/xilem_masonry/src/view/progress_bar.rs index 9e2c2f5c4a..eb14c40580 100644 --- a/xilem_masonry/src/view/progress_bar.rs +++ b/xilem_masonry/src/view/progress_bar.rs @@ -4,13 +4,13 @@ use masonry::widgets; use crate::core::{Arg, MessageCtx, MessageResult, Mut, View, ViewArgument, ViewMarker}; -use crate::{Pod, ViewCtx}; +use crate::{Pod, ViewCtx, WidgetView}; /// A view which displays a progress bar. /// /// This can be for showing progress of a task or a download. pub fn progress_bar(progress: Option) -> ProgressBar { - ProgressBar { progress } + WidgetView::<()>::check_impl_widget_view(ProgressBar { progress }) } /// The [`View`] created by [`progress_bar`]. diff --git a/xilem_masonry/src/view/prose.rs b/xilem_masonry/src/view/prose.rs index 61ad345a10..c4dee293c4 100644 --- a/xilem_masonry/src/view/prose.rs +++ b/xilem_masonry/src/view/prose.rs @@ -9,10 +9,12 @@ use masonry::properties::{ContentColor, DisabledContentColor, LineBreaking}; use masonry::widgets; use crate::core::{Arg, MessageCtx, MessageResult, Mut, View, ViewArgument, ViewMarker}; -use crate::{Color, Pod, TextAlign, ViewCtx}; +use crate::{Color, Pod, TextAlign, ViewCtx, WidgetView}; /// A view which displays selectable text. -pub fn prose(content: impl Into) -> Prose { +pub fn prose( + content: impl Into, +) -> Prose { Prose { content: content.into(), text_color: None, @@ -23,6 +25,7 @@ pub fn prose(content: impl Into) -> Prose weight: FontWeight::NORMAL, phantom: PhantomData, } + .check_impl_widget_view() } /// A version of [`prose`] suitable for including in the same line @@ -31,7 +34,9 @@ pub fn prose(content: impl Into) -> Prose /// Note that setting [`text_alignment`](Prose::text_alignment) on the result /// will be meaningless. #[doc(alias = "span")] -pub fn inline_prose(content: impl Into) -> Prose { +pub fn inline_prose( + content: impl Into, +) -> Prose { prose(content).line_break_mode(LineBreaking::Overflow) } diff --git a/xilem_masonry/src/view/resize_observer.rs b/xilem_masonry/src/view/resize_observer.rs index 782653aa7f..8c4a05af5c 100644 --- a/xilem_masonry/src/view/resize_observer.rs +++ b/xilem_masonry/src/view/resize_observer.rs @@ -72,6 +72,7 @@ where on_resize, phantom: PhantomData, } + .check_impl_widget_view() } /// The [`View`] created by [`resize_observer`]. diff --git a/xilem_masonry/src/view/sized_box.rs b/xilem_masonry/src/view/sized_box.rs index cccf1d746d..3fa84492bf 100644 --- a/xilem_masonry/src/view/sized_box.rs +++ b/xilem_masonry/src/view/sized_box.rs @@ -43,6 +43,7 @@ where width: None, phantom: PhantomData, } + .check_impl_widget_view() } /// The [`View`] created by [`sized_box`]. diff --git a/xilem_masonry/src/view/slider.rs b/xilem_masonry/src/view/slider.rs index 3d8500551f..b40895de8f 100644 --- a/xilem_masonry/src/view/slider.rs +++ b/xilem_masonry/src/view/slider.rs @@ -42,6 +42,7 @@ where disabled: false, phantom: PhantomData, } + .check_impl_widget_view() } impl Slider { diff --git a/xilem_masonry/src/view/spinner.rs b/xilem_masonry/src/view/spinner.rs index 09ab656f7f..b8c11ea4ae 100644 --- a/xilem_masonry/src/view/spinner.rs +++ b/xilem_masonry/src/view/spinner.rs @@ -4,7 +4,7 @@ use masonry::widgets; use crate::core::{Arg, MessageCtx, MessageResult, Mut, View, ViewArgument, ViewMarker}; -use crate::{Pod, ViewCtx}; +use crate::{Pod, ViewCtx, WidgetView}; /// An indefinite spinner. /// @@ -34,7 +34,7 @@ use crate::{Pod, ViewCtx}; /// } /// ``` pub fn spinner() -> Spinner { - Spinner + WidgetView::<()>::check_impl_widget_view(Spinner) } /// The [`View`] created by [`spinner`]. diff --git a/xilem_masonry/src/view/split.rs b/xilem_masonry/src/view/split.rs index 346863e1ce..e3f3c42e82 100644 --- a/xilem_masonry/src/view/split.rs +++ b/xilem_masonry/src/view/split.rs @@ -42,7 +42,7 @@ use crate::{Pod, ViewCtx, WidgetView}; /// .split_point(0.25) /// ``` /// -pub fn split( +pub fn split( child1: ChildA, child2: ChildB, ) -> Split @@ -63,6 +63,7 @@ where child2, phantom: PhantomData, } + .check_impl_widget_view() } /// The [`View`] created by [`split`]. diff --git a/xilem_masonry/src/view/task.rs b/xilem_masonry/src/view/task.rs index c40f3c6581..9dc0fa84e0 100644 --- a/xilem_masonry/src/view/task.rs +++ b/xilem_masonry/src/view/task.rs @@ -32,11 +32,12 @@ pub fn task( on_event: H, ) -> Task where - F: Fn(MessageProxy, Arg<'_, State>) -> Fut, + F: Fn(MessageProxy, Arg<'_, State>) -> Fut + 'static, Fut: Future + Send + 'static, H: Fn(Arg<'_, State>, M) -> Action + 'static, M: AnyDebug + Send + 'static, State: ViewArgument, + Action: 'static, { const { assert!( @@ -50,6 +51,7 @@ where on_event, message: PhantomData, } + .check_impl_view() } /// Launch a task which will run until the view is no longer in the tree. diff --git a/xilem_masonry/src/view/text_input.rs b/xilem_masonry/src/view/text_input.rs index 674cae0001..50cdb708d5 100644 --- a/xilem_masonry/src/view/text_input.rs +++ b/xilem_masonry/src/view/text_input.rs @@ -80,7 +80,10 @@ type Callback = /// .insert_newline(InsertNewline::OnEnter) /// # } /// ``` -pub fn text_input(contents: String, on_changed: F) -> TextInput +pub fn text_input( + contents: String, + on_changed: F, +) -> TextInput where F: Fn(Arg<'_, State>, String) -> Action + Send + Sync + 'static, State: ViewArgument, @@ -102,6 +105,7 @@ where // not clipping clip: true, } + .check_impl_widget_view() } /// The [`View`] created by [`text_input`]. diff --git a/xilem_masonry/src/view/transform.rs b/xilem_masonry/src/view/transform.rs index 3bb2f5446d..53bb019e69 100644 --- a/xilem_masonry/src/view/transform.rs +++ b/xilem_masonry/src/view/transform.rs @@ -19,7 +19,7 @@ use crate::{Pod, ViewCtx, WidgetView}; /// Transformations apply in order. /// That is, calling [`rotate`](Transformed::rotate) then [`translate`](Transformed::translate) /// will move the rotated widget. -pub fn transformed(child: Child) -> Transformed +pub fn transformed(child: Child) -> Transformed where Child: WidgetView, State: ViewArgument, @@ -29,13 +29,14 @@ where transform: Affine::IDENTITY, phantom: PhantomData, } + .check_impl_widget_view() } /// The view for [`transformed`]. pub struct Transformed { child: V, transform: Affine, - phantom: PhantomData<(State, Action)>, + phantom: PhantomData Action>, } impl Transformed { diff --git a/xilem_masonry/src/view/variable_label.rs b/xilem_masonry/src/view/variable_label.rs index c73a5279b6..c29ccd3db7 100644 --- a/xilem_masonry/src/view/variable_label.rs +++ b/xilem_masonry/src/view/variable_label.rs @@ -9,15 +9,15 @@ use crate::core::{ Arg, MessageCtx, MessageResult, Mut, View, ViewArgument, ViewId, ViewMarker, ViewPathTracker, }; use crate::view::{Label, label}; -use crate::{Pod, TextAlign, ViewCtx}; +use crate::{Pod, TextAlign, ViewCtx, WidgetView}; /// A view for displaying non-editable text, with a variable [weight](masonry::parley::style::FontWeight). pub fn variable_label(text: impl Into) -> VariableLabel { - VariableLabel { + WidgetView::<()>::check_impl_widget_view(VariableLabel { label: label(text), target_weight: FontWeight::NORMAL, over_millis: 0., - } + }) } /// The [`View`] created by [`variable_label`]. diff --git a/xilem_masonry/src/view/virtual_scroll.rs b/xilem_masonry/src/view/virtual_scroll.rs index 34f5092b23..311eb37dd7 100644 --- a/xilem_masonry/src/view/virtual_scroll.rs +++ b/xilem_masonry/src/view/virtual_scroll.rs @@ -5,7 +5,6 @@ use std::collections::HashMap; use std::marker::PhantomData; use std::ops::Range; -use masonry::core::{Widget, WidgetPod}; use masonry::util::debug_panic; use masonry::widgets::{self, VirtualScrollAction}; use private::VirtualScrollState; @@ -19,7 +18,7 @@ use crate::{Pod, ViewCtx, WidgetView}; /// /// See its documentation for details. pub struct VirtualScroll { - phantom: PhantomData (WidgetPod, State, Action, ChildrenViews)>, + phantom: PhantomData (State, Action, ChildrenViews)>, func: F, valid_range: Range, } @@ -56,14 +55,16 @@ pub fn virtual_scroll( ) -> VirtualScroll where ChildrenViews: WidgetView, - F: Fn(Arg<'_, State>, i64) -> ChildrenViews + 'static, + F: Fn(Arg<'_, State>, i64) -> ChildrenViews + Send + Sync + 'static, State: ViewArgument, + Action: 'static, { VirtualScroll { phantom: PhantomData, func, valid_range, } + .check_impl_widget_view() } /// Component for a [`VirtualScroll`] with unlimited children. @@ -80,6 +81,7 @@ where ChildrenViews: WidgetView, F: Fn(Arg<'_, State>, i64) -> ChildrenViews + 'static, State: ViewArgument, + Action: 'static, { VirtualScroll { phantom: PhantomData, diff --git a/xilem_masonry/src/view/worker.rs b/xilem_masonry/src/view/worker.rs index 934286687f..0cfb0e9a61 100644 --- a/xilem_masonry/src/view/worker.rs +++ b/xilem_masonry/src/view/worker.rs @@ -45,12 +45,14 @@ pub fn worker( Dummy, > where - F: Fn(MessageProxy, UnboundedReceiver) -> Fut, + F: Fn(MessageProxy, UnboundedReceiver) -> Fut + 'static, + V: Send + 'static, Fut: Future + Send + 'static, S: Fn(Arg<'_, State>, UnboundedSender) + 'static, H: Fn(Arg<'_, State>, M) -> Action + 'static, M: AnyDebug + Send + 'static, State: ViewArgument, + Action: 'static, { const { assert!( @@ -69,6 +71,7 @@ where on_response, message: PhantomData, } + .check_impl_view() } /// A version of [`worker`] which can store its message sender in the environment. @@ -81,13 +84,15 @@ pub fn env_worker( on_response: H, ) -> Worker where - F: Fn(MessageProxy, UnboundedReceiver) -> Fut, + F: Fn(MessageProxy, UnboundedReceiver) -> Fut + 'static, + V: Send + 'static, Fut: Future + Send + 'static, - S: Fn(Arg<'_, State>, &mut Res, UnboundedSender), + S: Fn(Arg<'_, State>, &mut Res, UnboundedSender) + 'static, H: Fn(Arg<'_, State>, M) -> Action + 'static, M: AnyDebug + Send + 'static, Res: Resource, State: ViewArgument, + Action: 'static, { const { assert!( @@ -102,6 +107,7 @@ where on_response, message: PhantomData, } + .check_impl_view() } /// An internal struct used to make [`env_worker`]/[`worker`] work. @@ -133,12 +139,14 @@ pub fn worker_raw( > where // TODO(DJMcNab): Accept app_state here - F: Fn(MessageProxy, UnboundedReceiver) -> Fut, + F: Fn(MessageProxy, UnboundedReceiver) -> Fut + 'static, + V: Send + 'static, Fut: Future + Send + 'static, S: Fn(Arg<'_, State>, UnboundedSender) + 'static, H: Fn(Arg<'_, State>, M) -> Action + 'static, M: AnyDebug + Send + 'static, State: ViewArgument, + Action: 'static, { Worker { init_future, @@ -150,6 +158,7 @@ where }, message: PhantomData, } + .check_impl_view() } /// The View type for [`worker`], [`env_worker`] and [`worker_raw`]. See its documentation for details. @@ -166,7 +175,6 @@ impl View for Worker where Res: Resource, - Action: 'static, F: Fn(MessageProxy, UnboundedReceiver) -> Fut + 'static, V: Send + 'static, Fut: Future + Send + 'static, @@ -174,6 +182,7 @@ where H: Fn(Arg<'_, State>, M) -> Action + 'static, M: AnyDebug + Send + 'static, State: ViewArgument, + Action: 'static, { type Element = NoElement; diff --git a/xilem_masonry/src/view/zstack.rs b/xilem_masonry/src/view/zstack.rs index df259c6640..486bc5224c 100644 --- a/xilem_masonry/src/view/zstack.rs +++ b/xilem_masonry/src/view/zstack.rs @@ -34,13 +34,14 @@ use crate::{Pod, ViewCtx, WidgetView}; /// )) /// } /// ``` -pub fn zstack>( +pub fn zstack>( sequence: Seq, ) -> ZStack { ZStack { sequence, alignment: UnitPoint::CENTER, } + .check_impl_widget_view() } /// A view container that lays the child widgets on top of each other. @@ -157,7 +158,7 @@ where // --- MARK: ZStackExt /// A trait that extends a [`WidgetView`] with methods to provide parameters for a parent [`ZStack`]. -pub trait ZStackExt: WidgetView { +pub trait ZStackExt: WidgetView { /// Applies [`ChildAlignment`] to this view. /// This allows the view to override the default alignment of the parent [`ZStack`]. /// This can only be used on views that are direct children of a [`ZStack`]. @@ -171,7 +172,10 @@ pub trait ZStackExt: WidgetView { } } -impl> ZStackExt for V {} +impl> ZStackExt + for V +{ +} /// A wrapper around a [`WidgetView`], with a specified [`ChildAlignment`]. /// This struct is most often constructed indirectly using [`ZStackExt::alignment`]. @@ -329,13 +333,13 @@ impl SuperElement, ViewCtx> for ZStac /// A trait implementing `ViewSequence` for `ZStackElement`. pub trait ZStackSequence: - ViewSequence + ViewSequence + Send + Sync { } impl ZStackSequence for Seq where - Seq: ViewSequence, + Seq: ViewSequence + Send + Sync, State: ViewArgument, { } diff --git a/xilem_masonry/src/widget_view.rs b/xilem_masonry/src/widget_view.rs index ea0ee45374..e3b2e9ad7f 100644 --- a/xilem_masonry/src/widget_view.rs +++ b/xilem_masonry/src/widget_view.rs @@ -9,7 +9,7 @@ use crate::view::{Prop, Transformed, transformed}; use crate::{AnyWidgetView, Pod, ViewCtx}; #[expect(missing_docs, reason = "TODO - Document these items")] -pub trait WidgetView: +pub trait WidgetView: View> + Send + Sync { type Widget: Widget + FromDynWidget + ?Sized; @@ -79,9 +79,19 @@ pub trait WidgetView: phantom: std::marker::PhantomData, } } + + #[doc(hidden)] + /// An identity function, that lets us assert that + /// the receiver always implements WidgetView<..> + fn check_impl_widget_view(self) -> Self + where + Self: Sized, + { + self + } } -impl WidgetView for V +impl WidgetView for V where V: View> + Send + Sync, W: Widget + FromDynWidget + ?Sized, @@ -108,6 +118,15 @@ where pub trait WidgetViewSequence: ViewSequence> { + #[doc(hidden)] + /// An identity function, that lets us assert that + /// the receiver always implements WidgetViewSequence<..> + fn check_impl_widget_view_seq(self) -> Self + where + Self: Sized, + { + self + } } impl WidgetViewSequence for Seq