Commit Graph

372 Commits

Author SHA1 Message Date
Daniel McNab 86d9592a3e
Move `xilem` onto a new `xilem_core`, which uses a generic View trait (#310)
This:
1) Renames the current/old `xilem_core` to `xilem_web_core` and moves it
to the `xilem_web/xilem_web_core` folder
2) Creates a new `xilem_core`, which does not use (non-tuple) macros and
instead contains a `View` trait which is generic over the `Context` type
3) Ports `xilem` to this `xilem_core`, but with some functionality
missing (namely a few of the extra views; I expect these to
straightforward to port)
4) Ports the `mason` and `mason_android` examples to this new `xilem`,
with less functionality.

This continues ideas first explored in #235 

The advantages of this new View trait are:
1) Improved support for ad-hoc views, such as views with additional
attributes.
This will be very useful for layout algorithms, and will also enable
native *good* multi-window (and potentially menus?)
2) A lack of macros, to better enable using go-to-definition and other
IDE features on the traits

Possible disadvantages:
1) There are a few more traits to enable the flexibility
2) It can be less clear what `Self::Element::Mut` is in the `rebuild`
function, because of how the resolution works
3) When implementing `View`, you need to specify the context (i.e.
`impl<State, Action> View<State, Action, [new] ViewCtx> for
Button<State, Action>`.

---------

Co-authored-by: Philipp Mildenberger <philipp@mildenberger.me>
2024-06-06 15:16:36 +00:00
Bruce Mitchener 3726c24c6a
masonry: Pass in winit `CursorEntered` events (#324) 2024-06-04 16:22:53 +00:00
Bruce Mitchener 36bbe77352
masonry: Use own `PointerButton` enum (#333)
This brings the `PointerButton` enum from glazier and has all code
outside of the winit event loop integration using it.

For now, it has a `todo!()` for the `MouseButton::Other` as it isn't
clear what that is for.
2024-06-04 08:53:14 +00:00
Bruce Mitchener 5a2db6dce8
masonry: Use `dpi` via `crate::dpi` (#332) 2024-06-04 07:06:21 +00:00
Aaron Muir Hamilton d2336d8b66
Signal TextFieldFocused and ImeMoved to enable and position the IME. (#314) 2024-06-03 16:29:23 +00:00
Olivier FAURE 49d22aaeea
Add diagram to document xilem layers (#322)
Note that this adds a link to a section added in
https://github.com/linebender/parley/pull/69

I removed Taffy from the diagram for simplicity, and because Taffy's
current integration is in flux.

Overall I think the Xilem README is in desperate need of a rewrite, and
this PR should be considered a stopgap. Further PRs should better
integrate the ecosystem descriptions into the README, move some sections
around, etc.
2024-06-03 15:36:18 +00:00
Kaur Kuut 5b200876c3
Disable `clippy::assigning_clones` lint. (#331)
Enabling
[`assigning_clones`](https://rust-lang.github.io/rust-clippy/master/index.html#/assigning_clones)
by default in Rust 1.78 was a mistake which was reversed in a week in
[rust-clippy#12779](https://github.com/rust-lang/rust-clippy/pull/12779).

We can disable it locally until the upstream fix arrives to stable Rust.
2024-06-03 14:35:03 +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
Olivier FAURE a1ed84ea6a
Bump accesskit sub-dependency version (#330)
This bumps the `accesskit_consumer` version in `Cargo.lock` to the next
minor version (`0.19.1`).

That version includes better error messages when AccessKit panics.
2024-06-03 14:17:03 +00:00
Bruce Mitchener 9a28599f57
masonry: Rename a scale factor variable (#328)
This helps make it more clear when skimming through this code that this
is the scale factor being used to transform the scene.
2024-06-03 11:39:02 +00:00
Bruce Mitchener 6adcf746f4
masonry: Use `web-time` instead of `instant` (#323)
Recently, `instant` has been marked as unmaintained by the maintainer. A
suggested replacement is `web-time`, which is used by `winit` and is
already in our dependency tree.
2024-06-03 11:30:55 +00:00
Bruce Mitchener 8c06d3a9bc
masonry: Update more docs to use non-HTML links. (#327) 2024-06-03 11:29:51 +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 a76995f2b4
masonry: Avoid reconstructing LogicalPosition. (#326)
In the call to updating the hot state from the widget pod, the
`mouse_pos` is already of the right type, so it doesn't need to try to
reconstruct itself as the right type.

This is different from another call site (in `contexts.rs`) where the
`mouse_pos` is an `Option<Point>` and so it does need reconstructing.
2024-05-31 18:02:52 +00:00
Olivier FAURE 5575c9248b
Add VS Code marker comments to code (#261)
[VS Code marker
comments](https://code.visualstudio.com/docs/editor/custom-layout#_minimap-and-breadcrumbs)
are a [new
feature](https://code.visualstudio.com/updates/v1_88#_minimap-section-headers)
that supposedly help with browsing the code with a minimap. I don't know
if other editors have equivalents.

I haven't tested them before, and I don't know whether they actually
improve DX, but they're pretty simple and unobstrusive, so I think it'd
be worth adding them experimentally and seeing how it goes.
2024-05-31 11:54:19 +00:00
Bruce Mitchener f8cbf81ca5
lints: Suppress some check-cfg warnings (#321)
The current nightly issues warnings for unknown cfgs, so we need to
suppress some of these for now.

Even though these are only needed for `masonry`, we put them in the
workspace configuration due to limitations in how the lints table is
configured and overridden in current versions of Cargo.
2024-05-30 04:42:48 +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
Bruce Mitchener 66e141ab8f
ci: Update stable Rust. (#317) 2024-05-26 15:22:32 +00:00
Bruce Mitchener b85a511140
clippy: Fix `doc_lazy_continuation` lint (#316) 2024-05-26 15:22:19 +00:00
Aaron Muir Hamilton 73fe4e6c2e
Add basic translation of Touch to PointerEvent. (#313)
https://github.com/linebender/xilem/assets/1272018/6e9aeefb-f324-4738-9aa2-f54d643631e2
2024-05-24 13:33:25 +00:00
Daniel McNab 866d416cef
Make execution on Android work properly (#309)
```
cargo apk run --example mason_android -p xilem
```


![image](https://github.com/linebender/xilem/assets/36049421/40cec14e-ce27-4bb8-ba46-8e6bd902852d)

There will some followup needed here, of course. But some of that will
want to come after xilem#235, when the way to do multiple windows has
become clearer
2024-05-23 08:13:30 +00:00
Philipp Mildenberger c6f6c78f52
xilem: Add Memoization views (`Memoize` and `Arc<impl View>`) (#267)
This ports the `Memoize` view from old xilem, slightly enhances it, by
checking whether the given view callback is a non-capturing closure and
not a function pointer (by asserting `std::mem::size_of::<F>() == 0`)

It also ports the `Arc<impl View>` and `Arc<dyn AnyMasonryView>` from
#164 including the example there to show how these two forms of
memoization can be used.
2024-05-20 15:51:58 +00:00
Jonas Platte 9c1eb3b2fe
Check for typos in CI (#306)
Currently, the only legit typo being found is `seeked` but I'm not sure
what to do about that.

Would be nice to check for new typos in CI anyways, right?

---------

Co-authored-by: Kaur Kuut <strom@nevermore.ee>
2024-05-17 06:39:32 +00:00
Bram Hoendervangers 380d39dea4
Update xilem-architecture.svg to have a white background (#308)
The architecture diagram is very hard to read on the dark theme of
github

<img width="1312" alt="image"
src="https://github.com/linebender/xilem/assets/9047770/90b5d68e-a14e-43ac-a625-c9696540df0c">
2024-05-16 16:44:25 +00:00
Aaron Muir Hamilton 0ef12a7fb6
Ignore synthetic keyinput events for now (#307)
They are unused (and rarely useful), and they cause unwanted behavior.
2024-05-16 14:18:16 +00:00
Olivier FAURE a8cf86772c
Add rustfmt config (#305)
These standardized options can make code a little nicer. Right now they
don't change anything, though they include an implicit commitment to
adopt the # `imports_granularity = "Module"` and `group_imports =
"StdExternalCrate"` settings.

While these settings are unstable, we can apply them with rustfmt
nightly without actually committing to using nightly in CI. We should
progressively move parts of the codebase towards that format in future
PRs.

---------

Co-authored-by: Kaur Kuut <strom@nevermore.ee>
2024-05-14 09:46:59 +00:00
Daniel McNab eef5a23905
Actually use the druid backspace logic (#303)
This is followup to #273.

This code originally came from
https://github.com/xi-editor/xi-editor/pull/837

I've also brought the tests back

---------

Co-authored-by: Yang Keao <keao.yang@yahoo.com>
2024-05-12 07:49:26 +00:00
Alex Pyattaev c12aa851bf
fix invalid HTML in examples (#304)
For some reason the recent version of Trunk refused to serve some of the
examples due to them missing the <html> tags. Adding the tags calms it
down and allows it to work again. Trivial change, but would save someone
the pain of having to fix examples before running them with trunk serve.

Co-authored-by: Alex Pyattaev <me@example.com>
2024-05-12 06:03:24 +00:00
Bruce Mitchener 99688a6eef
`masonry`: Use `cursor_icon` crate directly. (#300)
`cursor_icon` is a crate that is used by `winit` to provide its
`CursorIcon` type separately from the `winit` crate.

This re-exports the `CursorIcon` from `masonry` and then uses that
rather than via `winit:🪟:CursorIcon`, allowing the use of the
`CursorIcon` without having to independently discover its provenance.

This is also one step towards not requiring `winit` within the `masonry`
internals apart from the actual window / event loop management.
2024-05-12 05:53:53 +00:00
Olivier FAURE ef5d36e8fc
Move crates to the repository root (#302)
Follows the convention proposed in this discussion:

https://xi.zulipchat.com/#narrow/stream/419691-linebender/topic/Standardizing.20multi-package.20repos
2024-05-11 21:59:03 +00:00
Daniel McNab 9e697cc06f
Handle IME in a way which winit expects (#298)
Doing some investigation, the issues I'm seeing is that ibus is a bit/a
lot broken around compose keys

But this has correct behaviour for me. This matches the documentation of
the `winit`
[`Ime`](https://docs.rs/winit/latest/winit/event/enum.Ime.html) event.
2024-05-11 14:01:06 +00:00
Pearce Keesling aaeeadbbd7
Additional flex view options (#285)
Wired up some more existing masonry flex properties so they can be set
on the flex view.

I was messing around with a dummy example to try out the v0.1 and
noticed I couldn't easily center something because flex was only
exposing direction not alignment/cross-alignment. It looked like all the
logic already exists in masonry so it was just a matter of wiring it up.
This is my first contribution so sorry if I missed some steps.

Sidenote: I didn't see any examples of testing that a view updates the
underlying element so I am guessing that is still tbd. If someone has a
suggestion for a good way to do that I am happy to try it out.

I'm also not sure what the etiquette is on adding/editing examples so I
just included the example I was using to verify it worked but no stress
if you want to remove it.
2024-05-09 05:07:49 +00:00
Philipp Mildenberger 43bd4ef090
xilem_web: Fix mathml example (use `style` method instead of untyped `attr`) (#296)
Fixes #295

Also implements `IntoStyles` for `[impl IntoStyles; N]`
2024-05-09 00:03:27 +00:00
Bruce Mitchener 300b22ce74
xilem_web: Remove unused direct dep on `kurbo`. (#293)
This is always used via `peniko`.
2024-05-08 14:45:26 +00:00
Bruce Mitchener 139395bb67
Remove `xilem_classic` (#290)
This can be accessed in the git history and has been replaced by the
version using `masonry`.
2024-05-08 09:09:49 +00:00
John Skottis 3ef6efa8ce
First draft of ARCHITECTURE.md (#277) 2024-05-08 09:04:45 +00:00
Bruce Mitchener 1c17e9c38a
xilem_classic: deps: Require current `futures-task` (#289)
Previously, this depended only on version `0.3`, which had a advisory
issued for it.
2024-05-08 07:11:07 +00:00
Bruce Mitchener a9dc625472
masonry: Fix typos (#288) 2024-05-08 07:10:41 +00:00
Bruce Mitchener 620b4041f8
masonry: docs: Don't `deny(rustdoc::broken_intra_doc_links)`. (#287)
Having this denied means we can't generate docs locally. We can
re-enable this once the issues are fixed.
2024-05-08 05:57:32 +00:00
Matt Hunzinger e8d88c6610
Add crates.io and docs.rs links to README.md (#286)
Congrats everyone on v0.1!

Not sure if this is the best styling to go for, but I think it'd be
great to link to the new releases
2024-05-08 05:41:48 +00:00
Daniel McNab a0b0842093
Implement underlining for IME areas (#284)
![image](https://github.com/linebender/xilem/assets/36049421/5378dc8c-bb2a-4dba-bbb1-352d827a617b)
2024-05-07 20:56:58 +00:00
Kaur Kuut 392c3c1fc9
Update dependencies. (#283)
These are the results of running

```sh
cargo upgrade --ignore-rust-version
cargo update
```

in preparation for the upcoming release.

These are semver compatible updates.
2024-05-07 19:38:40 +00:00
Daniel McNab 738e4b213b
Make the default label colour white (#282)
We should be following the system theme here, probably.

And doing a lot of other things. But this is a saner default with a
black default "background"
2024-05-07 19:01:15 +00:00
Daniel McNab 72164fcf33
Fix incorrect handling of the margin in textbox selection (#281)
Previously, click-and-drag selection in the textbox would select the
wrong characters (among other issues with clicking)
2024-05-07 13:55:01 +00:00
Aaron Muir Hamilton 786963e302
Implement basic IME interaction, backspace, and delete. (#273) 2024-05-07 13:30:52 +00:00
Bruce Mitchener 8829daa39f
deps: Update `image`, make workspace, turn off default features. (#279)
The `image` crate has a number of dependencies which aren't needed in
the core masonry crate, so we can turn off the default image format
support and only enable "png" when used as a dev dependency.

Also, make it a workspace dependency at the same time so that the
version is only stated in a single location.
2024-05-07 12:57:55 +00:00
Bruce Mitchener f6930242b8
deps: Update `float-cmp` (#280) 2024-05-07 11:37:41 +00:00
Daniel McNab 47804206b4
Fix the handling of textbox width (#275)
Previously, filling up the line would overflow the right border of the
box, because the `max_advance` was too big.

This improves the margin hack, and also fixes the resultant issue.

---------

Co-authored-by: Bruce Mitchener <bruce.mitchener@gmail.com>
2024-05-07 05:08:50 +00:00
Philipp Mildenberger c3783ae693
masonry: Require `ParentWindowOrigin` lifecycle when origin of child has changed (#278)
Fixes the issue described in #265.

I *think* this is the proper fix, it seems to be similar as in previous
xilem (where I think that pass is called `ViewContextChanged`).
2024-05-06 19:53:14 +00:00
Daniel McNab 44f45fe171
Implement underlining and strikethrough for Masonry (#276)
This will be needed to follow on from #273 (showing the pre-edit region
visually)

![underline on Lorem
Ipsum.](https://github.com/linebender/xilem/assets/36049421/eee27c4f-4029-45a1-8a4b-a853a61f5d6b)

and

![stikethrough on Lorem
Ipsum](https://github.com/linebender/xilem/assets/36049421/c7a0efdb-3ddf-4bd1-b837-64a0ee538914)

cc @dfrg for awareness, I'm not certain on the maths (but that doesn't
need to block merging)
2024-05-06 17:25:15 +00:00