Commit Graph

52 Commits

Author SHA1 Message Date
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
Olivier FAURE e7ed917ca8
Implement very basic widget inspector (#820) 2025-01-15 17:10:20 +00:00
Olivier FAURE 51a355615f
Document most items in Masonry (#815)
Move `#[allow(missing_docs)]` to two modules. Missing docs now warn
everywhere else by default.

Remove `#[expect(rustdoc::broken_intra_doc_links)]` and fix all broken
links.
2025-01-13 17:36:31 +00:00
Olivier FAURE 5ed3178789
Remove last references to debug logger (#814)
Code has been unused for a long time.
Widgets weren't even logging to it.
2025-01-13 10:48:37 +00:00
Olivier FAURE c1e0c83b0b
Have AppDriver take a reference to RenderRoot for more flexibility (#808) 2025-01-10 14:16:37 +00:00
Bruce Mitchener c1ef637309
Use `palette` and `Color` from top level Xilem and Masonry (#800) 2024-12-20 16:34:11 +00:00
Bruce Mitchener ee4411467c
Fix and un-allow `clippy::use_self` lints (#799) 2024-12-19 13:45:57 +00:00
Bruce Mitchener 653e424a8e
Consistently use `FontWeight` as the name (#778)
Right now, there are uses of `Weight` from Fontique, `TextWeight` from
Masonry, and `FontWeight` from Parley.

We should just use a single name.
2024-12-09 10:10:11 +00:00
Kirpal Grewal 363e4222c2
heading level and doc for masonry readme (#770)
Update the Masonry readme with documentation on how it is generated and
change the heading level to be consistent with Color
2024-12-06 11:43:12 +00:00
Kirpal Grewal a1d47a06bb
Tree arena (#752)
I've had a try at implementing the unsafe `tree_arena` in a separate lib
(but in the same workspace for now) - haven't thought of a good way to
make non root access not O(depth), without slowing down insertion or
using more memory, though have improved accessing nodes from the root to
O(1) from O(depth) and accessing direct children to O(1) from
O(children)
2024-12-05 10:18:52 +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 10dc9d171c
Update to Vello 0.3.0, Parley main, AccessKit 0.17 (#616)
The biggest remaining issue in this PR is that IME support is not
present.

However, I think landing this is *better* than not landing it, because:
1) If we don't land it, it's going to languish again
2) Getting IME support back can be parallelised (cc @tomcur)
3) Getting Vello 0.3.0 and Parley 0.2.0 unlocks real advantages,
including full emoji support (#420).

To be clear, my first follow-up priority will be connecting the IME back
up. I do not however think this should block on Parley 0.3.0.

Discussion in
https://xi.zulipchat.com/#narrow/channel/317477-masonry/topic/Updating.20Parley.20dependency
2024-11-18 17:25:02 +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
Bruce Mitchener 1b804fbcd2
masonry: Export `UnitPoint` (#720)
This is needed for `Align::horizontal`, `Align::vertical`, etc.
2024-10-29 16:43:33 +00:00
Bruce Mitchener 0edce4f20f
masonry: Export `WindowSizePolicy` (#718)
This is a pub enum within `render_root` and is required for creating a
`RenderRootOptions` which is already exported. This is needed for people
embedding masonry in a non-Xilem way.
2024-10-29 13:56:40 +00:00
Olivier FAURE e03dfdd82b
Create skeleton of documentation (#632)
This is a very messy, very basic skeleton of what Masonry documentation
will eventually look like.

Main points are:

- Dedicated documentation modules.
- Re-using most of the language from the RFCs.

Next steps are:

- Flesh out the Widget documentation.
- Rewrite all those docs in a less placeholder-y way.
- Add chapter about the widget arena.
- Spread out that pass documentation to the respective pass files.
- Rewrite ARCHITECTURE.md.
- Add screenshots.

Fixes #376 and #389.

---------

Co-authored-by: Daniel McNab <36049421+DJMcNab@users.noreply.github.com>
2024-10-22 13:49:43 +00:00
Olivier FAURE f322894e50
Replace WidgetMut methods with free functions. (#705)
See discussion here https://github.com/linebender/xilem/pull/663 and [on
zulip](https://xi.zulipchat.com/#narrow/channel/317477-masonry/topic/Improving.20docs.20for.20WidgetMut).

Basically, previous code was using `WidgetMut<MyWidget>` as a receiver.
This can be done when WidgetMut is a local type, but external users
wouldn't be able to do it. The result would be that users importing
Masonry as a dependency but copy-pasting code from one of our widgets
would get compile errors.

This PR switches to a syntax that external crates will be able to use
when declaring widgets. It's a more verbose, less readable syntax, but
it's unambiguous and doesn't require clever tricks.

We can consider switching back to WidgetMut-as-a-receiver when
`#![feature(arbitrary_self_types)]` or some equivalent gets stabilized.
See
https://github.com/rust-lang/rust/issues/44874#issuecomment-2122179688
for current progress.
2024-10-22 13:36:48 +00:00
Olivier FAURE ed5c141701
Reorganize top-level Masonry modules (#703) 2024-10-21 12:18:30 +00:00
Olivier FAURE 4d20e0dd19
Merge StatusChange with Update (#697) 2024-10-20 17:15:18 +00:00
Olivier FAURE 3d8c7950e4
Reorder imports across project (#690)
Split off from #637.
2024-10-20 14:54:13 +00:00
Olivier FAURE dc9a2e2a97
Rename lifecycle to update (#677) 2024-10-17 12:09:14 +00:00
Marco Melorio 634afd7010
Expose font weight parameter in label widget (#669) 2024-10-14 17:01:53 +00:00
Olivier FAURE 337f7c774e
Make WidgetState private (#655)
This enforces a pattern in the codebase where that WidgetState can only
be accessed through pass contexts, which prevents invalidation bugs.
2024-10-09 09:53:59 +00:00
Olivier FAURE f195c318e3
Rename RootWidget::get_element to RootWidget::child_mut (#645) 2024-10-07 20:10:25 +00:00
Olivier FAURE a04649dbc9
Rearrange text-handling code (#624)
Remove obsolete types.
Remove text_helpers module.
2024-10-03 15:05:35 +00:00
Daniel McNab 1fe790ab18
Connect to tracy if the `tracy` feature is enabled (#612)
This is very useful for debugging performance issues. I've already used
it to debug [#masonry>`to_do_list`: Horrendous
performance](https://xi.zulipchat.com/#narrow/stream/317477-masonry/topic/to_do_list.3A.20Horrendous.20performance).

Setting a feature works on a workspace-wide basis. I.e `cargo run
--example mason --features tracy` works.

Some weirdness:
- Tracy seems to assume we know when a frame will "start", but we only
know if we'll repaint once processing for an event has finished.
- Something seems to be starting a default "Frame", which isn't really
right. We don't have any continuous frames. Maybe we should always
request a redraw if tracy is enabled.

Either way, I think this feature is useful to land *now*, so am not
planning on resolving these in this PR unless someone provides a
solution.
2024-10-02 12:50:51 +00:00
Tom Churchman 653874e103
masonry: reimplement `Widget::get_child_at_pos` (#565)
The `Widget::get_child_at_pos` has a default linear search
implementation, upholding some conditions (e.g., picking the last child
in "z-order" in case of overlap). Widgets can override this with a
custom implementation (e.g., a widget with many children that maintains
a quadtree to search through). Custom implementations should uphold the
same conditions, we can add some debug assertions to check this in a
later PR.

This introduces a `QueryCtx`, allowing widget methods access to the
global state, widget state, and widget subtree. `QueryCtx` is similar to
the other (mutable) context types, but can be shared.

This also changes `WidgetRef` to consist of a `Widget` and a `QueryCtx`,
similar to `WidgetMut` consisting of a `Widget` and `MutateCtx`. This
required changing where `WidgetRef` can be constructed.

This resolves code comment
ac95f2524a/masonry/src/widget/widget_ref.rs (L192-L199)
2024-09-26 14:37:05 +00:00
Olivier FAURE 2642a9e146
Replace RouteWidgetAdded event with new register_children method (#602)
Make lifecycle method optional.
Remove InternalLifecycle.
2024-09-23 08:25:32 +00:00
Muhammad Ragib Hasin 92fc669493
Enable BackgroundBrush in SizedBox view (#541)
The `SizedBox` widget in Masonry had the option to set a background
brush that was not exposed in its corresponding view in Xilem. The
`SizedBox` view now exposes the option.

Incidentally, `BackgroundBrush::PainterFn` variant had the wrong type,
as such it was not usable. A `scene` parameter is added and the closure
now requires to be `Send + Sync`.

---------

Co-authored-by: Daniel McNab <36049421+DJMcNab@users.noreply.github.com>
2024-08-27 10:57:16 +00:00
Bruce Mitchener 991a485bd1
masonry: Re-enable `clippy::doc_markdown` (#549)
This is work towards #449.
2024-08-25 11:56:34 +00:00
Olivier FAURE 3cceb60f72
Improve lints for debug prints (#551) 2024-08-25 11:10:50 +00:00
Olivier FAURE 07c908a426
Remove bloom filter (#536)
The filter was only used for RouteFocusChanged which is about to be
removed. Since it was a performance feature, we can remove it early.
2024-08-25 08:51:02 +00:00
Olivier FAURE 652ee68ae5
Implement compose pass (#512)
Add `Widget::compose` method.
Add `ComposeCtx` type.
Add `needs_compose`, `request_compose`, `translation_changed` flags to
WidgetState.
Add `window_origin` attribute to WidgetState.
Add convenience methods to TreeArena.
Remove `needs_window_origin` flag and `parent_window_origin` attribute.
2024-08-16 17:06:00 +00:00
Bruce Mitchener 052ac39667
masonry: Use Kurbo via Vello. (#223)
Rather than have to keep a dependency on `kurbo` at the correct version,
always use it via `vello`.

This makes this match how `peniko` is already used within `masonry`.
2024-08-16 13:53:09 +00:00
Olivier FAURE e0d6a309d1
Implement mutate pass from pass spec RFC (#510)
This is part of the "Pass Specification" RFC:
https://github.com/linebender/rfcs/pull/7

Rename WidgetCtx to MutateCtx.
Add a mutate pass.
Add a `mutate_later` context method to trigger that pass.
Refactor `edit_root_widget` to use a version of that pass.
Add a separate constructor for the synthetic WidgetState created in
RenderRoot.

---------

Co-authored-by: Philipp Mildenberger <philipp@mildenberger.me>
Co-authored-by: Daniel McNab <36049421+DJMcNab@users.noreply.github.com>
2024-08-14 20:06:01 +00:00
Olivier FAURE 59ee615651
Implement event and update_pointer passes from pass spec RFC (#488)
This is a first step in implementing the "Pass Specification" RFC:
https://github.com/linebender/rfcs/pull/7

Create a `passes` module.
Create event passes.
Create the update_pointer pass.

Remove `WidgetPod::update_hot_state` method.
Move mouse-cursor-handling code to update_pointer pass.
Implement pointer capture.
Refactor the TreeArena code.

---------

Co-authored-by: Daniel McNab <36049421+DJMcNab@users.noreply.github.com>
2024-08-13 08:52:27 +00:00
Bruce Mitchener 10c064f2a1
masonry: Remove ExtEvent, Promise, WorkerCtx, WorkerFn, SpawnWorker. (#503)
These either aren't used, aren't implemented, or are just stubs. A new
implementation may or may not take the same approach given changes
within the ecosystem, and if we want these back, they're in the history.
2024-08-12 12:01:57 +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
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
Olivier FAURE fc6a52265f
Use `cargo-rdme` to sync README and documentation root (#435)
This was remarkably painless.

I especially appreciate @taiki-e providing an install-action which does
90% of the CI work for us.

---------

Co-authored-by: Daniel McNab <36049421+DJMcNab@users.noreply.github.com>
2024-07-22 12:44: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 732cfa8376
Move `text` into `reference` folder (#433)
This was imported in #241

See also [#masonry > text vs
text2](https://xi.zulipchat.com/#narrow/stream/317477-masonry/topic/text.20vs.20text2)

We do want to sort out text properly, see #337, so I'm keeping the
reference code around.
2024-07-18 07:05:11 +00:00
Olivier FAURE be4a5bf5e8
Implement widgets-in-arenas RFC (#396)
See https://github.com/linebender/rfcs/pull/6 and [zulip
thread](https://xi.zulipchat.com/#narrow/stream/317477-masonry/topic/New.20RFC.3A.20.22widgets-in-arena.22).
2024-07-15 11:45:19 +00:00
Daniel McNab e76cf31258
Deny unsafe code globally (#406)
Related to #44

We don't have any necessary unsafe code, and I don't think any of us
want to lose that.

(Vello is also no longer laundering the unsafety wrt surface creation
thanks to a recent wgpu release)
2024-07-02 13:19:39 +00:00
Daniel McNab d6af6a6ef7
Differentiate pointer buttons in `Button` Widget and View (#397)
In most cases, you want a button which only actuates when the primary
mouse button is pressed, so the easy case is still that. This is a short
term hack, because e.g. the active state is still based on any button
being pressed, not just those we are interested in.

That is, we probably need to represent a set of buttons we are
interested in. However, this change minimally unblocks additional work
with Xilem. In particular, see [#xilem > Minesweeper converted from Iced
to
Xilem](https://xi.zulipchat.com/#narrow/stream/354396-xilem/topic/Minesweeper.20converted.20from.20Iced.20to.20Xilem).
2024-06-14 16:40:26 +00:00
Olivier FAURE 36d894cfde
Small improvements to tracing code (#384) 2024-06-10 11:15:36 +00:00
Olivier FAURE a2045f1356
Document masonry (#329)
This was initially a supposed to be a small documentation pass, which
grew into a few changes:

- Adding back a to-do-list example.
- Fixing the bugs revealed by that example (infinite bounding boxes,
wrong accessibility handling in Portal, etc).
- Making sure all widgets return the correct spans instead of the
less-useful default one.
- Adding a trace to the layout pass for easier debugging.

Overall I'm pretty happy with this!
2024-06-03 14:21:41 +00:00
Bruce Mitchener 94d8f50947
Allow feeding masonry from an externally event loop. (#325)
This allows for running `masonry` with an externally managed event loop
for integrating with an application that is already running an event
loop.

* Expose `PointerState` to allow creating `PointerEvent`
* Expose `WindowEvent` to allow managing window size and scale factor.
* Make `DriverCtx` usable from outside the crate. While this struct was
already `pub`, the sole member of it was not.
2024-06-01 16:52:01 +00:00
Bruce Mitchener 2ab7c824cc
xilem,masonry: Use `dpi` crate directly (#320)
This removes a class of dependencies from within both `masonry` and
`xilem` on the `winit` crate where we can just use `dpi` directly
instead.

The `dpi` crate is meant (like `cursor_icon`) to be a shared ecosystem
crate rather than only for usage with `winit`.
2024-05-29 07:52:04 +00:00