Commit Graph

480 Commits

Author SHA1 Message Date
Crockeo 522d42cf0c
masonry: add Pinch to PointerEvent (#476)
I opened https://github.com/linebender/xilem/issues/473 earlier today,
but I realized after looking at the code that it would be super simple
to implement!

Copying over some context from that issue:

- I'm working on a graph renderer using Vello.
- I'm porting it over to a Masonry widget, so that I can build a UI
around it.
- In doing so I noticed there wasn't support for winit's `PinchGesture`,
which I had been using before when messing around with this on my macOS
device.

Please let me know if y'all feel like this is appropriate to include
inside of `PointerEvent`!
2024-08-18 11:52:49 +00:00
Olivier FAURE 7842fd98df
Add per-widget trace spans to compose pass (#523) 2024-08-17 12:10:30 +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
Daniel McNab 3fd3903eae
Label with animated variable font parameters (#507)
This adds a new `VariableLabel` widget, which animates its weight to a
target value in a linear fashion (over a fixed time period). Also adds
support for this in Xilem, and a new `variable_clock` example. This
example also runs on Android.


[Screencast_20240812_171138.webm](https://github.com/user-attachments/assets/5df623f9-f4ca-4b55-b6a9-2047d2581b56)

Current status: The code in Xilem and Masonry library crates is final.
I'm planning on significantly updating the actual example.

Outstanding issues:

- [X] Hacks in support for "Roboto Flex", by always loading it from the
local file - resolved
- [X] It's not clear what subset of Roboto Flex we should use - still
open to bikeshedding
- [ ] The variable font animation support is not really as generic as it
should be. This starts to drift quite close to a styling question,
however.
- [ ] The only supported variable axis is `wgth`
2024-08-16 14:06:42 +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
Bruce Mitchener c6c1b71640
masonry: More efficient set of PointerButtons. (#334)
This brings code over from glazier for a set of PointerButtons that just
uses a single value and bit flags rather than a `HashSet`.
2024-08-16 13:28:34 +00:00
Bruce Mitchener c380d8a2b6
masonry: Fix a couple of broken doc links. (#520) 2024-08-16 11:20:15 +00:00
Philipp Mildenberger 88cc3eed3d
xilem_web: Apply props when the element type changes in `replace_inner` (#519)
Fixes #518
2024-08-16 10:42:33 +00:00
Philipp Mildenberger 5ae36200b3
xilem_web: Document a lot and remove `start_<modifier>` as it doesn't do anything in `View::build` and may be misleading (#517)
I think I've covered every pub item at the top level.

It also renames (taking `Attributes` as example)
`start_attribute_modifier` -> `rebuild_attribute_modifier`,
and `end_attribute_modifier` -> `mark_end_of_attribute_modifier`, as I
think that makes it more clear what these methods do.
`start_attribute_modifier` was a noop in `View::build` and may lead to
buggy behavior when `DomNode::apply_props` is called before every parent
`View::build` has done modifying the props. This should make
`DomNode::apply_props` robust. And `AfterBuild` is fixed now with that.
2024-08-16 09:51:33 +00:00
Olivier FAURE cb7e9e605c
Reduce logs in tests (#511)
Stop debug log lines from showing up between test indicators when
running `cargo test`.
2024-08-15 16:41:28 +00:00
Philipp Mildenberger 411acc12aa
xilem_web: Add hydration support, and a new view using it `Templated` (#495)
This is mostly a first step towards SSR.
But we can use hydration to speed up creation of long (non-virtualized)
lists with the `Templated` view.
`Templated` stores a deep copy of the DOM node of the first occurence of
its `impl DomView` based on the `TypeId` in the `ViewCtx`,
and reuses it on every further invocation, where it will be hydrated and
updated based on the new attributes.
As it uses an `Rc` to achieve this, it also supports memoization,
similar to an `Arc<impl View>`.

Hydration is currently feature-gated, as it produces a little bit more
binary bloat. Though it's little enough to this being justified as
default.

---------

Co-authored-by: Markus Kohlhase <markus.kohlhase@slowtec.de>
2024-08-15 15:37:57 +00:00
Bruce Mitchener 7607ffd13f
masonry: tweak docs: typos and linking. (#516) 2024-08-15 15:26:34 +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
Philipp Mildenberger 0c80c0fb62
masonry: reuse redundant `ArenaRef/Mut` creation code (#509)
@PoignardAzur this is what I meant with the redundancy.
2024-08-13 12:13:11 +00:00
rustui 574ac7dc8f
Fix view overflow in the calc example on mobile (#508)
On mobile platforms, setting the logical width of the window to 400 can
cause the view to overflow on phones with smaller screen widths (such as
the iPhone SE 2nd generation).
<details>
  <summary>screenshot of the view overflow</summary>
<img
src="https://github.com/user-attachments/assets/d47c1c88-ace6-4059-a0ed-b5384dcfa207"
alt="screenshot of the view overflow" width="400" />
</details>

It is more intuitive not to manually set the window size. Additionally,
winit does not support set_title and set_resizable on iOS and Android
(calling them does not have any effect).
2024-08-13 10:21:45 +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
Markus Kohlhase 7d137a765d
xilem_web: Add event_target_value helper function (#506) 2024-08-12 11:27:30 +00:00
Philipp Mildenberger c9dbb211a8
xilem_web: Fix issue with downcasting to a wrong type transitively from `AnyView` (#505)
This should fix the issue described in #440 by adding the type of the
`Children` `ViewSequence` to the type of element, which results in
unique types, so `AnyView` should not cause issues anymore. Fortunately
there's no regression with the compilation times here, so an
`AnyViewSequence` doesn't seem to be necessary in that case.
2024-08-12 08:38:11 +00:00
Markus Kohlhase b7f98babd6
xilem_web: Make MessageThunk public (#504) 2024-08-11 00:09:47 +00:00
Jared O'Connell 16325dbafe
Xilem stopwatch example (#492)
This pull request adds a stopwatch example with start, stop, lap, and
reset buttons.
When the stopwatch is active, the stop and lap buttons are visible. When
the stopwatch is not active, the reset and start buttons are example.
To reduce resource usage, I set the timer period to 50ms, and only show
1 decimal place.

<img width="564" alt="Screenshot 2024-08-08 at 10 55 49 AM"
src="https://github.com/user-attachments/assets/4c044653-230b-4f36-b421-1a9aa6bd4486">

This is an older screenshot of what it looks like when it exceeds a day:

<img width="447" alt="Screenshot 2024-08-07 at 10 21 43 PM"
src="https://github.com/user-attachments/assets/57f8887c-83bd-4361-817c-37c76ff4892b">

Also tested on Windows:

![image](https://github.com/user-attachments/assets/71537ccc-11d9-4491-b2f3-5c62bb419896)


Let me know if there are any improvements you see that I can make.

I included the android boilerplate, but I haven't tested it.
2024-08-10 12:44:27 +00:00
Philipp Mildenberger 407c3788f0
Cleanup of unnecessary tracing and "external" `.flex()` of `num_row` in the `calc` example (#502) 2024-08-09 18:06:37 +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
Daniel McNab cfb0ef231e
Restore animation support - add `spinner` view (#497)
This is the smallest change possible to make animations work in Masonry.

Essentially, we treat every redraw as a potential animation frame, so
that animations do work.

I've also added the `spinner` view in Xilem to test this out. The
`state_machine` examples uses this.

This is work done for the variable fonts demo.
2024-08-09 15:41:36 +00:00
Philipp Mildenberger a52c3c7b3c
xilem_web: Add support for opacity in `svg::Fill` and dashes, opacity in `svg::Stroke` (#493)
Uses `ViewState` for a little bit of optimization (of allocations
mostly).
2024-08-09 09:28:52 +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
Markus Kohlhase 5b6ebc324f
xilem_web: Add an `AfterBuild`, `AfterRebuild` and `BeforeTeardown` view, which reflects `Ref` in React (#481)
Co-authored-by: Philipp Mildenberger <philipp@mildenberger.me>
2024-08-08 22:44:49 +00:00
Markus Kohlhase 2eda5a2a50
xilem_web: Add async_repeat (#485)
Co-authored-by: Philipp Mildenberger <philipp@mildenberger.me>
2024-08-08 17:51:04 +00:00
Muhammad Ragib Hasin 43ffdbf824
Fix non-standard textbox behavior in Windows (#489) 2024-08-06 16:52:54 +00:00
Philipp Mildenberger 10387e90ab
xilem: Fix calc example (missing `flex` property) (#491)
Fixes #490
2024-08-06 12:32:21 +00:00
Philipp Mildenberger 99d61603d2
xilem_web: Add `interval` `View`, which somewhat reflects `setInterval` (#486)
Simple but convenient `View`, e.g. for some kind of ticker. (Maybe needs
an additional example)
2024-08-05 13:36:18 +00:00
Philipp Mildenberger bb13f1a760
xilem_web: Allow `DomFragment` instead of `DomView` as `app_logic` (#482)
Should fix #461. This allows a `ViewSequence` (called `DomFragment`) of
`DomView`s as root component.

The `counter` example is updated to show this new behavior.
2024-08-05 13:03:19 +00:00
Daniel McNab e27b3ce0c2
Run tests in CI, and fix fonts for snapshot testing (#233)
See also linebender/vello#439

This should open the door to doing much more comprehensive testing at
higher level in the nearish future (including e.g. in `xilem_masonry`)
2024-08-05 13:01:47 +00:00
Philipp Mildenberger 19454e3dc8
Improve `calc` and xilem_web's `mathml_svg` example (#487)
Reduces a little bit of the boilerplate in `calc`
2024-08-05 12:54:22 +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
Philipp Mildenberger 544a4a1ca9
xilem_web: Fix `DomChildrenSplice::with_scratch` (#484)
I'm surprised that this was not noticed yet,
`DomChildrenSplice::with_scratch` previously only appended new elements
to the end of the children of an element in the DOM tree, whereas it
should've inserted it at the current index of the `ElementSplice`. This
should fix this, using a `DocumentFragment` which is shared on the
`ViewCtx` to avoid unnecessary allocations.
2024-08-05 09:08:34 +00:00
edgy-sphere 0bca54ae52
masonry: `TextEditor` add `Action::TextChanged` for backspace & delete (#483)
`masonry::text::edit::TextEditor` should emit an
`Action::TextChanged(...)` also on `Backspace` and `Delete` if anything
was deleted, so that e.g. `xilem::view::textbox::Textbox` receives this
action. This is already implemented for `Ctrl+Backspace` and
`Ctrl+Delete`.

The code changes are not elegant, but intended to be minimally invasive.

Local `cargo test` failed for the modified and an unmodified code, but
sometimes with different errors&mdash;which I do not quite understand.

I apologize in advance for any mistakes on my part, I've never before
worked on open source repos and did not find any guideline for your
project.
2024-08-05 08:25:36 +00:00
Bruce Mitchener 101fa9bb7d
Fix some `clippy::doc_markdown` lints in masonry. (#479)
This is a start on #449.
2024-08-02 08:04:27 +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
Casey Rodarmor 4c991dd3e9
xilem_web: Add HtmlLiElement `value` attribute setter (#471)
From manually testing in Chrome, values between `2**31` and `2**31 - 1`
work, so this takes an `i32`.

It's pretty trivial code, but I think it would be really nice to add
some kind of test, or even just an example which uses it.

What do you think about adding a "misc" example for `xilem_web`, which
exercises a bunch of small features? I was thinking a layout with a
column on the left with a list of items with a larger area on the right.
When an item on the left is clicked, the right side is populated with
whatever that item is.

In this case, the item name would be `ol-li-value`, which when clicked
would show something like this on the right:

```rust
ol((
  li("foo"),
  li("bar"),
  li("baz").value(10),
  li("qux"),
));
```

Ideally, this would be compiled as part of CI, to make sure that no
compilation errors are introduced. Any time a small feature is added, a
new item in the "misc" example could be added which uses it.

It would also be nice for development, to have a place where new, small
features like this can be exercised during development. An actual test
would be great, but from quick googling, I couldn't find an obvious way
to test WASM code which runs in the browser. There's
`wasm_bindgen_test`, but that only runs tests in WASM outside of a
browser environment.
2024-08-01 21:05:09 +00:00
Daniel McNab 3405f6ee69
Support running `calc` on Android (#474)
This works without any other code modifications.

![Xilem Calc on
Android.](https://github.com/user-attachments/assets/b6648c04-bc9e-464c-9a19-0f03e958ade9)
2024-08-01 13:48:58 +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
Jared O'Connell 759d746653
Xilem Calculator Example (#467)
This pull request adds a simple calculator that can display binomial
math (ex: 2 + 2 = 4). Math operations with more than two operands are
done by moving the prior binomial results into the left operands.

This pull request also follows the existing convention by masonry's
calculator example to calc_masonry to differentiate them.

Let me know if there are any changes that I should make to improve code
quality.

<img width="404" alt="image"
src="https://github.com/user-attachments/assets/3498913b-dd4d-451c-8fa2-fcd2f7fd26af">

---------

Co-authored-by: Daniel McNab <36049421+DJMcNab@users.noreply.github.com>
2024-07-31 15:07:55 +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
Casey Rodarmor 741c36b13a
xilem_web: Add function to set HtmlIFrameElement src attribute (#466)
Apropos of #462. Let me know if this should have a test or an example!
2024-07-31 08:01:56 +00:00
Philipp Mildenberger b71f533571
xilem_web: Fix #465, by actually replacing the old element in the DOM-tree (#468)
Fixes #465
2024-07-29 12:50:10 +00:00
Philipp Mildenberger 1b1a1d3238
xilem_web: Fix message type of `AnyDomView` and add `.boxed()` combinator (#460)
I guess I missed this when adding #408, the doc-test should ensure that
`Box<AnyDomView>` is now really a `DomView`.

---------

Co-authored-by: Daniel McNab <36049421+DJMcNab@users.noreply.github.com>
2024-07-29 09:23:31 +00:00
Philipp Mildenberger a2f136079c
xilem_web: Remove hardcoded `prevent_default`/`stop_propagation` as the user should decide that behavior (#458)
I think we could also create some additional sugar around that, but
since the event is given to the user, they can handle that behavior
anyway.

Fixes #457
2024-07-29 09:15:21 +00:00