linebender / xilem

An experimental Rust native UI framework
Apache License 2.0
3.14k stars 92 forks source link

xilem_core: Add `OneOf` views as statically typed alternative to `AnyView` #394

Closed Philipp-M closed 1 week ago

Philipp-M commented 2 weeks ago

This ports the OneOfN views from xilem_web to xilem_core. The new marking mechanism for the ViewSequence makes it possible to use the same type as well for an implementation of ViewSequence, which is provided here as well. Because of ambiguity, and needing to specify the explicit type when OneOf(impl View) would be used, where an impl ViewSequence is expected, we have decided to not provide a ViewSequence impl, so that it's not ambiguous, and not necessary to specify the concrete type. We could instead add separate types for a ViewSequence instead like OneSeqOf2.

Since macros make this unfortunately not super readable, for reviewers of the code this pre-macro version may be better to look at, the only difference to this, is that this has slightly enhanced doc comments, and obviously more than just OneOf2.

Philipp-M commented 2 weeks ago

This does not yet provide an implementation for xilem (masonry) itself, I'd prefer doing that in a different PR, but I can add that here when it's deemed necessary.

Philipp-M commented 1 week ago

about using a shared context (and state) types for all of these.

Yeah that cleans up all of this a little bit, and also makes the macro more readable...

Philipp-M commented 1 week ago

I also think we should get this hooked up in Xilem proper very soon, to check that this actually covers all use cases.

Yes I can do that in case no one else does this before. I'd like to finish the xilem_web port though before focusing on xilem, which apart from the orphan views and minimal cleanup just means a generic Message on the View AFAICS. At least in xilem_web I (think I) have tested all the use-cases I currently target this for.

Philipp-M commented 1 week ago

Thanks for the thorough assistance and in-depth review!

I think this is in a good state now, so I'm going to merge this, and add more xilem specific stuff related to this later.