Commit Graph

61 Commits

Author SHA1 Message Date
Daniel McNab 8c25fea640
Make `DynMessage` a struct, use trait upcasting (bump MSRV to 1.86) (#920)
With trait upcasting stabilised in Rust 1.86, we can make use of it in
`DynMessage`.

This also makes `DynMessage` into a struct, because that reduces the
risk of Rust Analyzer messing things up; it liked to confuse the
`Message` trait with the `Message` generic. That is, the prior state was
effectively `trait View<Message = Box<dyn Message>>`, which sometimes
led to things like: `Box<dyn Box<dyn Message>>`.
2025-04-17 16:30:58 +00:00
Olivier FAURE 125dab7949
Document more items (#899)
Make missing_docs annotations more granular.
2025-03-21 14:50:16 +00:00
Bruce Mitchener f72f556e9e
docs: Missing backticks (#900) 2025-03-19 18:34:29 +00:00
Olivier FAURE bc8e9fecd2
Switch to Edition 2024 (#880)
I've ignored most of the changes and the projects still compile and test
fine. Changes I did commit:

Add `+ use<>` after functions.
Remove `ref mut` from some patterns.
Bump MSRV.
Apply new rustfmt format.
2025-03-05 13:15:47 +00:00
Daniel McNab 8147465350
Make Xilem Core unconditionally `no_std` (#877)
This removes the need to ignore `unused_qualifications`.

The `extern crate std` isn't *strictly* needed, but it will make future
debugging easier (you can do `println` or `dbg!`, for example).
2025-02-24 16:21:58 +00:00
Daniel McNab 24c18686ae
Bump the CI latest stable Rust to 1.85, typos 1.29.9 (#876)
Note that this doesn't do the update to the 2024 edition

This has also lead to
https://github.com/linebender/linebender.github.io/pull/90
2025-02-24 15:08:14 +00:00
Daniel McNab 3fe3ef6150
Migrate to v5 of the Linebender lint set (#867)
See linebender/linebender.github.io#88 (and some other earlier PRs)

A follow up like https://github.com/linebender/vello/pull/806 will also
be needed, but that can come later.
2025-02-17 09:54:29 +00:00
Daniel McNab de92da4320
Fix `clippy::default_trait_access` (#868)
This is a new addition to the "editor period lints". See #867 for
context.
2025-02-14 18:22:29 +00:00
Olivier FAURE 066d4319e8
Use nightly rustfmt to format imports (#838) 2025-01-20 13:19:26 +00:00
Olivier FAURE 9ffc650983
Remove `Box<dyn Widget>` from a few places (#837)
Having `Box<dyn Widget>` implement the `Widget` trait is a crutch that
makes a bunch of things more complicated.

It leads to double-boxing in cases when the `dyn Widget` is itself a
`Box<dyn Widget>` (especially since the arena's current implementation
boxes all widgets by default), makes it harder to reason about
downcasting, and ends up producing a lot of code to handle the edge
cases.

On the xilem side, `Box<dyn Widget>` is slightly redundant with
`DynWidget`.

This PR still leaves a lot of boxing. On the long term, we'd like for
the arena to pack arbitrary widgets efficiently using some kind of
archetype scheme, but in the meantime, boxing will have to do.

Changes in this PR:
- New `FromDynWidget` trait that maybe-downcasts widgets to a
maybe-sized `Widget` type.
- Most places that accept `Widget` now accept `Widget + ?Sized`.
- Remove `impl Widget for Box<dyn Widget>`.
- Replace all instances of `WidgetPod<Box<dyn Widget>>` with
`WidgetPod<dyn Widget>`.
- Replace all instances of `xilem::Pod<Box<dyn Widget>>` with
`xilem::Pod<dyn Widget>`.
- Rename WidgetPod to WidgetBox in xilem_core example to avoid
ambiguity.
2025-01-20 12:52:08 +00:00
Bruce Mitchener adcbafbd8e
Update to git Parley and Vello. (#798)
This brings the new releases of Color and Peniko and start making sure
things are good for the upcoming releases of Parley and Vello.
2024-12-20 14:52:05 +00:00
Bruce Mitchener 326cb2bdbe
ci: Update stable Rust and typos (#793) 2024-12-18 23:37:11 +00:00
Philipp Mildenberger e0fee7425c
Eliminate needless lifetimes (#723)
Result from `__CARGO_FIX_YOLO=1 cargo clippy --fix`.
As newest nightly clippy bleats about all of this.
2024-11-29 14:00:11 +00:00
Kaur Kuut af96e784e3
Update to Linebender lint set v2. (#758)
Some examples needed minor adjustments and `xilem_web` needed an
exception.
2024-11-23 11:34:37 +00:00
Daniel McNab ecc7217808
Fix `missing_assert_message` and `missing_errors_doc` in Xilem Core (#748) 2024-11-14 10:33:05 +00:00
Daniel McNab 628659d35c
Fix `clippy::use_self` in Xilem Core (#747)
All fixes except for removing the `expect`s are results from `cargo
fix`.
2024-11-14 09:20:23 +00:00
Daniel McNab 6af19494cd
Fix `shadow_unrelated` in Xilem Core (#745)
Note, this fix is only excluding the false positives as a result of:
https://github.com/rust-lang/rust-clippy/issues/10780

When/if the fix for that
(https://github.com/rust-lang/rust-clippy/pull/13677) trickles onto
stable, we can remove the expects.
2024-11-12 17:55:48 +00:00
Daniel McNab 0e9d2ec40f
Fix `unused_qualifications` in Xilem Core (#743)
Most of the change is remove the `expect` and run `cargo fix`.

For the orphan view, I've added a blanket exception. At the moment, this
only applies to String, but the

I did try using `#![no_implicit_prelude]` in that module, but there are
a lot of useful things in the implicit prelude, it was worse than the
exception.
2024-11-12 15:30:57 +00:00
Daniel McNab 41207effce
Make Xilem Views `must_use` (#742)
Also fixes `unused_qualifications` as an easy fix.

---------

Co-authored-by: Kaur Kuut <strom@nevermore.ee>
2024-11-12 11:12:27 +00:00
Daniel McNab 751bd62765
Fix `elided_lifetimes_in_path` in Xilem Core (#740) 2024-11-12 11:12:12 +00:00
Daniel McNab 5c61ac195b
Fix `missing_debug_implementations` in Xilem Core (#739)
This also updates to use `core::error::Error` now that it is stable.
2024-11-11 16:51:27 +00:00
Philipp Mildenberger 23f04ca370
xilem_core: implement `View` for `Rc<impl View>` (#732)
I needed this in xilem_web, I could've used `Arc` as well, but I think
it's fine to add this for consistency when an `Arc` is not needed.

It's basically copy-pasta of the `Arc`. (I don't think a macro is worth
it here?). Had to fix some resulting issues in the `Templated` view (due
to ambiguity?).

---------

Co-authored-by: Daniel McNab <36049421+DJMcNab@users.noreply.github.com>
2024-11-11 14:10:47 +00:00
Daniel McNab 18a6805ddc
Scope exceptions to the Linebender lint set (#730)
This allows exceptions to be burned down on a per-crate basis, rather
than needing to be addressed across the whole codebase at once.

Additionally, this now follows completely the Linebender lint set,
except for the unexpected-cfgs. I don't think I've introduced any
behaviour changes in this PR.
2024-11-09 08:37:56 +00:00
Kaur Kuut 419f8f115e
Match CI doc testing with docs.rs. (#726)
* Treat doc warnings as errors. Historically we've not done so due to
various `rustdoc` bugs giving false positives but I got it to pass
without failure right now, so perhaps better times have arrived.
* Target only `x86_64-unknown-linux-gnu` on docs.rs as we don't have any
platform specific docs.
* Properly enable example scraping for `xilem`, `xilem_core`, and
`masonry`. Fully disable it for `xilem_web` which does not have examples
as Cargo defines them.
* Pass `--all-features` at docs.rs to match our CI and reduce the
maintenance burden of manually syncing the features list.
* Enable the `doc_auto_cfg` feature for docs.rs which will show a little
tip next to feature gated functionality informing of the crate feature
flag.
* Replaced `[!TIP]` with `💡 Tip` that was inside `<div
class="rustdoc-hidden" />`. The GitHub specific tip causes a `rustdoc`
error and [didn't even render
properly](ac2ca38785/masonry/src/doc/01_creating_app.md).
* Updated `01_creating_app.md` just enough to get `rustdoc` to pass, but
that file needs a bunch of more work, as it is outdated.
2024-11-05 11:25:36 +00:00
Philipp Mildenberger 53a5354c2d
xilem_web: Rewrite modifiers (`Attributes`, `Classes` and `Styles`), and cleanup/extend docs (#699)
Previously the modifier systems had design issues i.e. bugs (non-deleted
styles/classes/attributes), and were unnecessary complex.
This aims to solve this (partly) by not using separate traits, but
concrete types and a different mechanism that is closer to how
`ElementSplice` works.

There's a few fundamental properties that composable type-based
modifiers need to support to avoid surprising/buggy behavior:

* Minimize actual changes to the underlying element, as DOM traffic is
expensive.
* Be compatible to memoization: e.g. a `Rotate` view should still be
applicable to possibly memoized transform values of the underlying
element.
* Recreation when the underlying element has changed (e.g. with a change
of variants of a `OneOf`).

To support all this, the modifier system needs to retain modifiers for
each modifier-view, and track its changes of the corresponding view.
Previously all elements were directly written and separated with markers
into a `Vec` to limit the boundaries of such views, but this had issues,
when e.g. all modifiers were deleted (e.g. clearing a `Vec` of classes),
by not reacting to this (I noticed that issue in the todomvc example
with the footer).

With this PR, the count of modifiers of a modifier-view are directly
stored either (hardcoded) in the view impl or its view state, which
cleans up the concrete modifier elements (such as `AttributeModifier`,
not including a separate `Marker` variant), and makes it less prone for
errors (and is slightly less memory-intensive).

The API to use these modifiers in modifier-views was also redesigned to
hopefully be more straight-forward/idiomatic. But as mentioned above
there's still challenges, which introduce complexity (which I'd like to
hide at least for simpler cases than these modifiers, likely in a future
PR).
All of this should now be documented in the new `modifier` module, where
now the modifiers `Attributes`, `Classes` and `Styles` reside. Other
views (like events) may also end up there...

One interesting aspect compared to the previous system is the use of a
new trait `With` for modifiers.
Instead of (roughly) `Element: WithStyle`, it works with `Element:
With<Styles>`.
This prevents all kinds of reimplementations of something like
`WithStyle` for elements.
This gets especially visible in the `one_of` module, which now can be
covered by a single blanket implementation.

Further the cargo-feature "hydration" was deleted, as it causes more
headaches to maintain than it really brings benefits (minimally less
binary size), depending on the future, it may or may not make sense to
reintroduce this.
2024-10-23 18:24:43 +00:00
Philipp Mildenberger 4817f24e86
Clippy pass, cosmetic fixes, and `rust-version.workspace=true` for web examples (#689)
Phew, fixing (future) clippy-lints is grunt-work (I enabled
`unnameable_types` for this), this is by far not complete, mostly
xilem-side, but at least a small step towards enabling more of our lint
set.

There's a few "drive-by fixes" like hiding `View::ViewState` types in
Xilem (I don't think we generally want to expose these), or exposing
event types in xilem_web.

I would suggest disabling the `allow_attributes_without_reason` lint for
now, so that we can update the rust version. I feel like adding comments
next to these is just unnecessary extra-work. I think adding more
reasons should probably be a separate pass, after a rust version update,
so that `#[allow(..., reason="")]` is supported.
2024-10-20 15:57:22 +00:00
Olivier FAURE 3d8c7950e4
Reorder imports across project (#690)
Split off from #637.
2024-10-20 14:54:13 +00:00
Philipp Mildenberger bad934b21a
xilem: Change `View::rebuild` to not return the element, and cleanup imports and `Mut` (#681)
It's possible to avoid returning the `ViewElement::Mut` in
`View::rebuild`, while having access to the element *after* a child view
was rebuilt.

This PR removes that again making the signature a little bit cleaner,
and also cleans up a lot of other stuff:
* `Mut<'_, Self::Element>` can be shortened to `Mut<Self::Element>`
* `use xilem::core::*` instead of `use xilem_core::*`, this is
especially useful in the examples, to avoid newcomers giving the
impression, that an additional dependency xilem_core is needed.
* Various cosmetic stuff, like one typo fix, empty line between
doc-comment (as (nightly) clippy currently bleats for me)

For more context see
https://xi.zulipchat.com/#narrow/stream/354396-xilem/topic/.E2.9C.94.20.60.26mut.20ViewElement.3A.3AMut.3C'_.3E.60.20in.20.60View.3A.3Arebuild.60.3F
2024-10-17 11:56:31 +00:00
Bruce Mitchener cc32727e9d
docs: Fix some missing backticks. (#672) 2024-10-15 09:26:27 +00:00
Olivier FAURE 25218291d0
Reserve ability to create Pod to ViewCtx (#597)
This is another intermediary PR for the "restrict widget creation to
Mutate pass" feature.

The basic idea is that, in the near future, it will be impossible to
create a WidgetPod without a handle to the arena. In my current WIP
code, that handle is passed through ViewCtx. Therefore, this PR changes
all the sites in xilem that create a Pod and has them use a ViewCtx
method instead.

I've tested most xilem examples and they all worked (except for
variable_clock, which currently panics in the last main commit).
2024-09-18 20:53:31 +00:00
Daniel McNab 0d56c592f5
Add the `lens` component (#587)
See
https://xi.zulipchat.com/#narrow/stream/354396-xilem/topic/Lens.20View

Usage:
```rust
fn app_logic(state: &mut FlightPlanner) -> impl WidgetView<FlightPlanner> {
    lens(date_picker, state, |state| &mut state.date)
}

struct FlightPlanner {
    date: Date,
    available_flights: Vec<Flight>,
}
```

Also extends the docs features in Xilem Core, and increases the
complexity threshold

---------

Co-authored-by: Kaur Kuut <strom@nevermore.ee>
Co-authored-by: Philipp Mildenberger <philipp@mildenberger.me>
2024-09-18 08:10:50 +00:00
Jared O'Connell c563029372
Fix minor grammar error in sequence (#586) 2024-09-13 04:13:34 +00:00
Daniel McNab 7be4dd2a2f
Xilem example for http cats API, requiring `worker`s and `image` component (#571)
This example is inspired by:
https://troz.net/post/2024/swiftui-mac-2024/

Current status:
- Lists status code
- Can select status code
- Downloads image from status code
- Shows image from status code

This adds two new features to Xilem:
- The worker view, which is the obvious extension to `task` for multiple
operations
- The `image` view, which just uses Masonry `Image`.

It also fixes a the Masonry Image view's layout to use the already
extant but unused method.
2024-09-03 19:02:07 +00:00
Olivier FAURE 3cceb60f72
Improve lints for debug prints (#551) 2024-08-25 11:10:50 +00:00
Bruce Mitchener 81b3aee40d
Don't use doc comments for VSCode markers. (#543) 2024-08-25 08:00:17 +00:00
Philipp Mildenberger 8ecdd876dc
Fix doc links by either correcting the item name, or making these public (#499)
I don't think anything speaks against making the items public in
masonry?
2024-08-09 16:11:02 +00:00
Jared O'Connell 2dc7b80153
Mason Only Add While Active (#496)
It's jarring for the example to automatically add to the button count,
so this makes it so it only increments while active is true.

---------

Co-authored-by: Daniel McNab <36049421+DJMcNab@users.noreply.github.com>
2024-08-09 15:50:35 +00:00
Philipp Mildenberger 2f23ee117a
xilem_web: Change `events::OnResize` to be a `ResizeObserver` (#494)
Since
[`on_resize`](https://developer.mozilla.org/en-US/docs/Web/API/Window/resize_event)
on an `Element` is not really useful as it won't be called, we can reuse
this event listener with a
[`ResizeObserver`](https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver/ResizeObserver)
on itself, to be actually useful.
2024-08-09 08:40:24 +00:00
Philipp Mildenberger 24427bbb44
Use `ViewMarker` trait instead of the generic `Marker` to allow `impl ViewSequence` as return type (#472)
This allows returning `impl ViewSequence` as this was previously not
possibly as the `Marker` generic parameter couldn't be named (easily) in
`ViewSequence<..., Marker>`.

This also provides specialized `ViewSequence`s for xilem
(`WidgetViewSequence` and `FlexSequence`) as well as for xilem_web
(`DomFragment`). Additional doc-tests/documentation and a small example
(in `counter`) for xilem_web is provided as well.

This has the drawback to not being able to reeimplement `ViewSequence`
for types that already implement `View`, which was previously possible
(as seen by the now removed `NoElementView` `ViewSequence`
implementation).
And additionally by introducing more boilerplate by having to implement
`ViewMarker` for every type that implements `View`.

---------

Co-authored-by: Daniel McNab <36049421+DJMcNab@users.noreply.github.com>
2024-08-05 10:53:19 +00:00
Bruce Mitchener b35162b82e
Enable `clippy::doc_markdown` for non-masonry crates. (#480)
Co-authored-by: Daniel McNab <36049421+DJMcNab@users.noreply.github.com>
2024-08-02 07:42:36 +00:00
Bruce Mitchener dd938d4af4
Fix doc warnings in xilem_core, xilem_web (#478) 2024-08-02 06:50:10 +00:00
Philipp Mildenberger 210afb4048
xilem_core: Refactor Memoization (add `Frozen` view, fix force-rebuild in `Arc`, and cleanup `Memoize`) (#451)
This adds a `force` which is basically a specialized `Memoize` without
any bound data.
This also cleans up `Memoize` a little bit (mostly code-aesthetic stuff,
but also adds `State` and `Action` params to the view, so that it
doesn't offer weird surprises when composing it with views like
`Adapt`).

The `Arc` view is also fixed, as it didn't support force rebuilding yet,
which is relevant for e.g. async, e.g. the `MemoizedAwait` view would
not work inside an `Arc<impl View>` currently.

---------

Co-authored-by: Daniel McNab <36049421+DJMcNab@users.noreply.github.com>
2024-08-01 11:21:56 +00:00
Daniel McNab f5c976c79d
Rename mentions of Zulip Stream to Channel (#470)
See
https://blog.zulip.com/2024/07/25/zulip-9-0-released/#streams-renamed-to-channels
2024-07-31 12:49:54 +00:00
Daniel McNab d70076262d
Update dependencies and bump to Rust 1.80 (#450)
There is one "semi-false-positive" lint triggered, which I have fixed.
Otherwise, the required
```
cargo upgrade --ignore-rust-version
cargo update
```
2024-07-26 13:02:41 +00:00
Daniel McNab 5e07dcebad
Support `OneOf` in Xilem (#445)
This uses the interface in Xilem Core from #394 and #436

Some thoughts:
1) You only need to specify the number of items in a single match arm.
I.e.
    ```rust
    fn my_view(){
        match x {
            0 => OneOf3(...),
            1=> OneOf9(...),
            _=> OneOf9(...),
        }
    }
    ```
    works. We probably should rename `OneOf9` back again in that case.
2) The example currently isn't that interesting. Any suggestions for a
more suitable state machine would be welcome.
2024-07-24 09:12:04 +00:00
Daniel McNab 5f38922d1b
Correctly set `rust-version` in all `Cargo.toml`s (#438)
Discovered in #432; this would otherwise cause errors for users of
nightly (or 1.81 beta, due to be released next week)
2024-07-19 14:42:27 +00:00
Daniel McNab 0844e3c431
Change the `OneOf` views to not use macros (#436)
This still needs to be implemented in Xilem.

But I think this is an improvement overall
2024-07-19 14:14:30 +00:00
Philipp Mildenberger 4fdcb26eb9
Add a `FlexElement` to support explicit spacers and flex parameters for `Flex` in xilem (#428)
Takes ideas from #235 (in particular the masonry side).

This implements support for explicit spacers in the `Flex` view and flex
parameters for views (see examples `flex` and `mason` for more details).
It also adds a way (`AnyFlexChild`) to dynamically switch between
spacers and widgets (with optional flex parameters).
`masonry::widget::Flex::layout` is also updated to be in sync with
current druid.

---------

Co-authored-by: Daniel McNab <36049421+DJMcNab@users.noreply.github.com>
2024-07-19 08:00:41 +00:00
Daniel McNab f11b64892c
Import our intended set of lints (#432)
See discussion in [#linebender > Standard Lint
set](https://xi.zulipchat.com/#narrow/stream/419691-linebender/topic/Standard.20Lint.20set)

Of note: I have taken steps to ensure that this can be practically
reviewed by *not* applying most of the lints.
The commented out lints make good follow-ups

---------

Co-authored-by: Olivier FAURE <couteaubleu@gmail.com>
2024-07-18 08:58:16 +00:00
Daniel McNab 7f40266bd8
Integrate `tokio` for async communication with Xilem (#423)
Supercedes https://github.com/linebender/xilem/pull/411

This is designed with #417 in mind, to not lock-in to our event loop.

---------

Co-authored-by: Philipp Mildenberger <philipp@mildenberger.me>
2024-07-18 07:38:28 +00:00