Commit Graph

795 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
Aaron Muir Hamilton 3f92904fc4
masonry: Scroll by 120 logical pixels per line scroll increment. (#925)
This is the default behavior in Chromium (when no configuration is
provided) and is a better default than individual logical pixels.
2025-04-15 15:16:17 +00:00
Matt Campbell 374694a2da
Fix bounding rectangles in accessibility nodes for text runs (#923)
It's no longer correct to add the window-relative origin of the widget
to the bounding rectangles of the text runs, since we now apply a
transform on each widget's AccessKit node.
2025-04-14 21:04:24 +00:00
Olivier FAURE da468aedfd
Fix text of screenshot testing documentation (#919) 2025-04-12 10:09:54 +00:00
alexjg 4778ad22a6
Add multiline text input support to TextArea (#922)
The textarea widget currently doesn't support multiline input because
the Enter key is used to trigger the TextEntered action. This commit
makes this behavior configurable by adding
masonry_core::widgets::InsertNewline.
2025-04-11 16:16:17 +00:00
Daniel McNab 21b8827005
Virtual Scrolling: allow setting a valid range (#906)
This is the first follow-up from the MVP of virtual scrolling. The valid
range is used to limit where in the id space can be scrolled to. This
will be widely useful for many (most?) virtual scrolling use cases.
Consider for example http_cats; the valid range would be 0..the number
of status codes.
2025-04-10 14:43:50 +00:00
Bruce Mitchener 324ff2444b
ci: Update stable Rust to 1.86, typos to 1.31.1 (#916) 2025-04-03 11:32:25 +00:00
Olivier FAURE fad997afa5
Add Properties to Button (#892)
Depends on #904.

Add BackgroundColor, BorderColor, BorderWidth, CornerRadius and Padding
properties.
Modularize button painting code.
Paint border after background to get slightly better border appearance.
Update screenshots.
Add screenshot test using properties.
2025-03-29 09:43:22 +00:00
Olivier FAURE 5c32f5c44b
Split winit dependency from masonry_core (#915)
Builds on top of #914.

This is the final step to splitting masonry_core from masonry.
2025-03-28 16:13:17 +00:00
Daniel McNab d4ad901fc6
Virtual Scrolling Widget (#882)
This is a minimum viable virtual scrolling widget, making the following
assumptions:
-  It does not *care* about scrollbars. This has several big advantages:
    - It allows for "infinite" virtual up and down-scrolling
- It allows for much more control by users of how the scrolling happens
(e.g. a date based scrollbar)

It does *not* assume that each item has a fixed height, and instead uses
some best-effort heuristics to work out which items should be loaded.

We've done some thinking about how to handle arbitrary transforms of
child widgets. Essentially, the only way we can reasonably handle this
is for each child widget to be automatically clipped to their layout
rectangle (...maybe e.g. 20% larger than it; that's hard because if we
don't use fixed margins then the variable scroll controller needs to
know about it).

This also does not handle focus and other details around (e.g.)
textboxes properly; it's not actually possible for the VirtualScroll
widget to know which child has the focus, so it can't keep that widget
around. Saving the textbox state would be nice, but requires a redesign
of a lot of things, essentially.

![A screenshot of fizzbuzz starting at 'FizzBuzz' at the top of the
screen, followed by 42031, going to
42106.](https://github.com/user-attachments/assets/fe55be05-ad07-4dc7-b7c2-c9209f5a114b)

Fixes #51

---------

Co-authored-by: Bruce Mitchener <bruce.mitchener@gmail.com>
2025-03-28 09:48:00 +00:00
Olivier FAURE c8b3985226
Rename `masonry` crate to `masonry_core` and `masonry_winit` crate to `masonry` (#914)
The main change is to change the names of the crates as registered in
the `Cargo.toml` files. The folders these projects are in aren't
renamed, but since most snapshot test files include their crate name, a
lot of files end up being renamed as well.
2025-03-27 11:10:26 +00:00
Olivier FAURE 6fe84201b0
Split most of the masonry crate into masonry_core sub-crate. (#910)
This change is done very carefully to minimize the number of changed
files, and use almost only file renames.
This is both for avoiding merge conflicts, keeping file history
unbroken, and keeping the PR easy to review.

A future PR will rename masonry to masonry_core, masonry_winit to
masonry change all the doc tests and snapshots that depend on those
names, etc.

After *that*, future PRs will have actual code changes splitting winit
away from masonry_core.
2025-03-26 12:00:46 +00:00
Olivier FAURE fadea88afa
Fix pointer capture (#912)
Create new PointerLost event.
No longer remove pointer capture on PointerLeave.
Fix small bugs and implementation errors.

Fixes #857.
Supersedes #858.
2025-03-25 15:36:36 +00:00
Olivier FAURE 3a21b21bbf
Mark `masonry/screenshots/*.png` as LFS files (#911)
These files we previously stored as blobs as-is. This stores them using
the same LFS method as other screenshots.
2025-03-25 13:32:17 +00:00
Olivier FAURE 8002eecbcd
Tighten screenshot testing (#904)
Remove nv-flip dependency and use pixel-by-pixel comparison instead.
Reduce error tolerance in tests.
Update a few outdated screenshots.

Create `assert_failing_render_snapshot` macro to make sure our diffing
infrastructure catches regressions.

Fixes #893.
2025-03-23 19:19:25 +00:00
Olivier FAURE 25a446029f
Isolate winit imports to `app` module (#908)
This is the first step towards #907.

This doesn't split the crate yet, but adds a translation layer between
winit and Masonry to facilitate that split.
2025-03-23 10:21:35 +00:00
Olivier FAURE 125dab7949
Document more items (#899)
Make missing_docs annotations more granular.
2025-03-21 14:50:16 +00:00
Olivier FAURE ab341367b0
Remove tempfile direct dependency (#905)
`tempfile` on Unix pulls `rustix`, which has a 9.19s single-core build
time on my machine, and was unused in our code.

`tempfile` is still a indirect dependency through `uds_windows`, which
is fine because in that dependency path (windows-only) doesn't pull
`rustix`.
2025-03-21 14:49:53 +00:00
Bruce Mitchener b97ae5dfd0
masonry: Remove `focus` from `PointerState` (#903)
This is unused. It was added to Druid in
<https://github.com/linebender/druid/pull/842>.

In the `winit` world, this would be done instead by customizing the
window creation with `WindowAttributesExtMacOS` and the
`with_accepts_first_mouse` function. (So it would no longer be something
that you have to check on every mouse click event as it is part of the
`WinitView` within `winit`.
2025-03-21 10:29:32 +00:00
Daniel McNab d4e46357b3
Handle renaming of `#gpu` to `#vello` (#902)
See [#linebender > Create a channel for
Vello?](https://xi.zulipchat.com/#narrow/channel/419691-linebender/topic/Create.20a.20channel.20for.20Vello.3F)
2025-03-20 17:18:57 +00:00
Bruce Mitchener f72f556e9e
docs: Missing backticks (#900) 2025-03-19 18:34:29 +00:00
Daniel McNab 88f453cbfe
Make `allow(missing_docs)` for widgets much more tightly scoped (#898)
Any new widget code needs to have full docs.
Not having `missing_docs` trigger by default for new widgets is quite
bad.

See #875 and #882 for cases where this over-broad allow has bitten us.

The comment about not using `expect(missing_docs)` because of
rust-analyzer is confusing to me; I don't run into an issue. It might
have been https://github.com/rust-lang/rust/issues/130021, which is now
fixed. That comment should have had a link to an upstream issue for more
context.
2025-03-19 13:14:15 +00:00
Olivier FAURE 3ef84e5605
Change sizes of various screenshots (#897) 2025-03-19 12:09:15 +00:00
platlas e1907a242a
Pair image with copyright notice in http_cats example. (#895)
While on slow internet connection I noticed that copyright notice is
conflicting with the spinner:

![http_cat-screenshot](https://github.com/user-attachments/assets/e8f418d5-9a03-4497-a830-9a268e5c8455)

So I paired the image with the copyright notice to display it only when
image is loaded. I hope this is not complicating the example code.

---------

Co-authored-by: Daniel McNab <36049421+DJMcNab@users.noreply.github.com>
2025-03-18 15:40:27 +00:00
Viktor Strate Kløvedal 6d1d6b9217
Add Xilem view for the Split widget (#887)
### Highlights

- Make the Masonry Split widget generic over its children (fixes a todo)
- Adds a new Xilem view for the widget
- Updated the `http_cats` example to use it for the main divider.

---

I'm unsure how exactly the `message` function works on a Xilem view as
it was hard to find documentation on that, so I've tried my best to
implement it, by looking at other views. Please double check that I did
it right.

I also changed some defaults on the split widget. First, I changed
`draggable` to default to true, since I believe this is the intended
behaviour for the view, similar to how a button is not disabled by
default.

I changed the constructors of the widget to not include the `split_axis`
but rather let it be optional with vertical (row) being the default
axis. I feel this made it more ergonomic to integrate with Xilem.
2025-03-18 09:48:29 +00:00
platlas fcc1c4a6f2
Resolving remaining `Label::message` artifacts. (#894)
Sorry, I should have done this already in #889.
2025-03-17 16:07:44 +00:00
Olivier FAURE 8d322b63a8
Change how some widgets are rendered (#886)
Update the code for Button, Textbox and ProgressBar.

Make the border and background disjoint.
Correctly interpret the border width.
2025-03-17 14:22:46 +00:00
Olivier FAURE aa56ea7633
Fix accessibility documentation (#859) 2025-03-17 14:10:36 +00:00
Olivier FAURE d9e2efffc0
Add note about `split-debuginfo="unpacked"` in README (#890)
(Co-authored by Daniel McNab)
2025-03-17 13:52:44 +00:00
platlas aaa84034ef
Fixing minor artifact. (#889)
edit(jplatte): Closes #888
2025-03-15 19:29:16 +00:00
Daniel McNab f98987f34c
Free properties as well (#885)
I found in #882 that properties (as introduced in #873) are never freed.
2025-03-14 14:52:53 +00:00
Matt Campbell 711135027f
Update to parley 0.3 (#883)
This update requires us to handle one breaking API change in parley.
2025-03-10 17:43:42 +00:00
Olivier FAURE 93e000d9c1
Improve bounding rect code (#874)
Document concepts of "layout rect" and "bounding rect".
Deprecate `local_layout_rect()` method.
Add `global_layout_rect()` method.
Remove `transform_changed()` method.
Improve bounding rect merging code.
Tweak `TestHarness::mouse_move_to`.
Tweak WidgetState doc.
2025-03-06 12:58:51 +00:00
Olivier FAURE 60c037dc1f
Add arbitrary properties to widgets (#873)
Add `Properties[Mut]` argument to widget methods.
Add a third TreeArena to sort per-widget arbitrary property values.

For the type-to-value map, I considered the following crates:
- https://docs.rs/typemap/latest/typemap/
- https://crates.io/crates/typemap_rev
- https://crates.io/crates/typemap-ors
- https://github.com/chris-morgan/anymap
- https://github.com/reivilibre/anymap3

Of these, anymap3 is the only one actively maintained (last commit less
than 12 months ago). The code source itself is extremely light and
simple; we may or may not decide to roll out our own implementation down
the line.

Add a BackgroundBrush property used by SizedBox as a proof of concept.

Note that SizedBox still has its `background` field, but we should
expect future widgets to use almost *exclusively* properties; properties
usually shouldn't be redundant with local fields.

To get there, we'll first need to better integrate properties in Xilem.
2025-03-06 11:32:06 +00:00
Daniel McNab 4e23dc5425
Refactor LFS handling (#881)
See https://github.com/linebender/vello/pull/833
2025-03-05 14:56:28 +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
Matt Campbell 642818dcee
Add missing `request_render` call when setting text selection from AccessKit (#803)
Without this, the updated text selection is neither painted nor
reflected in an updated accessibility tree until the user presses a key.
2025-02-21 16:34:16 +00:00
Evgeny 5e854382b2
Add DPI scale factor to the render root state (#872)
so that it's available to widgets that can fix blurry lines due to bad
overlapping positioning of its internal elements

partially addresses https://github.com/linebender/xilem/issues/869

---------

Co-authored-by: Daniel McNab <36049421+DJMcNab@users.noreply.github.com>
2025-02-20 15:12:43 +00:00
Bruce Mitchener f63e7096dd
Update to current `parley` `main` (#870)
This updates to the version using the updated objc2 and binding crates
for Fontique.

It also has a minor API change.
2025-02-19 02:50:26 +00:00
Olivier FAURE f8a7690d54
Update ARCHITECTURE.md file (#849) 2025-02-17 21:07:18 +00:00
Bruce Mitchener 2f580a1f3d
Update `float-cmp` and `pollster` (#871)
These are the direct dependencies that have non-semver compatible
updates (apart from wgpu).
2025-02-17 17:44:36 +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
Richard Dodd b89d9b16fe
expose winit (#860)
I don't think there is a reason not to, and you need winit for some
types so currently you must define the crate yourself, which risks
version errors etc.
2025-02-12 22:28:22 +00:00
Evgeny 25b12ad385
masonry: make util pub to allow customizing buttons in an app (#862)
Similar to https://github.com/linebender/xilem/pull/861 this would help
creating custom elements while relying on the already used/tested
library utilities
2025-02-10 11:28:18 +00:00
Evgeny de1d88c1a6
xilem: make a Pod method pub to allow creating custom buttons in an app (#861)
I wanted to create a custom button view, but when needing to pass to the
masonry type could not convert the pod to a widgetpod.
So I'd like to make this method pub to allow that

---------

Co-authored-by: Daniel McNab <36049421+DJMcNab@users.noreply.github.com>
2025-02-10 11:02:52 +00:00
Bruce Mitchener 8d59974f2f
Remove extraneous `#[warn(...)]` (#855)
These are no longer suppressed above it in the crate, so this isn't
needed now.

Related to #449.
2025-01-30 10:20:50 +00:00
Olivier FAURE d77b31b892
Reorganize Masonry modules (#848) 2025-01-24 11:24:31 +00:00