Commit Graph

213 Commits

Author SHA1 Message Date
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
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
Muhammad Ragib Hasin 43ffdbf824
Fix non-standard textbox behavior in Windows (#489) 2024-08-06 16:52:54 +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
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—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
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
Werick da Silva Santana 67afe67816
masonry: add pressure sensitivity to the pen's touch on the screen (#453)
device test
* huion kamvas 13 tablet windows 10 platform
2024-07-29 09:12:01 +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
Andrii Zymohliad 4ddad5129e
Expose control over window background color (#439)
Adds `Xilem::background_color` builder method and the relevant changes
to Masonry. I've also modified `mason` example to demonstrate the usage
of the new API.

[Zulip
discussion](https://xi.zulipchat.com/#narrow/stream/354396-xilem/topic/Window.20background.20color)
2024-07-23 09:37:14 +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 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 2dc1c08b80
Add a CSS `gap` inspired Flex property. (#437)
See https://developer.mozilla.org/en-US/docs/Web/CSS/gap

Since #428, we no longer have default spacing between flex elements in
Masonry. This makes the examples quite ugly.

Choices made based on [#xilem > Porting Taffy Integration to New
Xilem](https://xi.zulipchat.com/#narrow/stream/354396-xilem/topic/Porting.20Taffy.20Integration.20to.20New.20Xilem).
Of particular note is the choice to not have this be overwritten by
spacers, due to:

> My first thought is that users are going to be very confused when they
add a space between two items and the result is the items are closer
together.

There is no such concept of a spacer in CSS parlance
2024-07-19 14:14:38 +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
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
Daniel McNab 7a28babdd6
Allow Masonry to compile in release mode (#431)
Cc @xStrom for the CI change

Cc @PoignardAzur for the Masonry changes
2024-07-17 09:52:37 +00:00
Bruce Mitchener b83a7ef41f
[masonry] Update to accesskit 0.16 (#426)
There was a breaking change in this release that renamed
`role::StaticText` to `role::Label`.
2024-07-16 08:18:51 +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
cfagot cf3530097b
Allow external event loop to drive masonry and xilem (#417)
These changes allow you to create a masonry or xilem app that is driven
by an external event loop.

## Masonry

Existing method for creating masonry app:
```
    masonry::event_loop_runner::run(
        masonry::event_loop_runner::EventLoop::with_user_event(),
        window_attributes,
        root_widget,
        app_driver,
    )
    .unwrap();
```

Instead you can now do this:

```
    let masonry_state = MasonryState::new(window_attributes, &event_loop, root_widget);

    let mut app = AppInterface {
        masonry_state,
        app_driver: Box::new(driver),
    };
    event_loop.run_app(&mut app)
```

Where AppInterface implements the winit
ApplicationHandler<accesskit_winit::Event> trait.

## Xilem

Existing method:
```
    let app = Xilem::new(state, app_logic);
    app.run_windowed(EventLoop::with_user_event(), title)?;
```

Now:
```
    let xilem = Xilem::new(0, app_logic);
    let (root_widget, app_driver) = xilem.split();
    let parts = xilem.split();
    let (root_widget, app_driver) = (parts.root_widget, parts.driver)

   // and then create masonry app just like above using root_widget and app_driver
```

Also adds example/external_event_loop.rs which duplicates
example/flex.rs but with an external event loop.

---------

Co-authored-by: Daniel McNab <36049421+DJMcNab@users.noreply.github.com>
2024-07-05 08:28:11 +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
Johan Holmerin ca5515125a
Use window.outer_size on iOS (#421)
As I understand it, on iOS the outer_size corresponds to the size of the
window, meaning when the surface is rendered using inner_size(the
safe/non-obscured size) the elements get stretched.

There's an open issue in winit about clarifying/standardizing the
different sizes, but until that's done switching to outer_size fixes the
issue.

The touch positions now also match the rendering

Winit issue: https://github.com/rust-windowing/winit/issues/2308

Fixes #419


<details>
  <summary>Before</summary>

![xilem
ios](https://github.com/linebender/xilem/assets/7433263/8bde0880-90e7-498b-b45c-c9964a0ae153)

</details>


<details>
  <summary>After</summary>

![ios
after](https://github.com/linebender/xilem/assets/7433263/8f6703d3-bb99-4f42-a941-d936ca5da6cf)


</details>
2024-07-01 23:18:25 +00:00
Johan Holmerin 1daf711d7f
Remove key_without_modifiers call on iOS (#418)
I had trouble getting masonry to compile for iOS due to a winit platform
method call that's not supported. There's already a cfg for android so I
just added iOS to it.

Reproduction:

```
cargo check --target aarch64-apple-ios
```

---------

Co-authored-by: Daniel McNab <36049421+DJMcNab@users.noreply.github.com>
2024-06-30 18:50:52 +00:00
Daniel McNab 032e86216a
Update to our latest CI standard (#414)
This was most recently updated in
https://github.com/linebender/vello/pull/505

The main differences are:
1) Greater concurrency between clippy and testing
2) More explanations
3) MSRV checking
4) Use of `cargo hack`
5) WASM checked in CI

I've also added the current values of our MSRVs to the main three
crates.
2024-06-28 13:02:54 +00:00
Bruce Mitchener 26f32020aa
masonry: Fix `unused_qualifications` lints (#416) 2024-06-28 12:48:24 +00:00
Daniel McNab 45c7500f7a
Support `text_size` in `Label`/`Prose` views (#413)
Format:
```rust
label("everything").text_size(42.)
```
and the same with `prose`.

I've also added `font_size` aliases for these, because people will
expect it to have these names.
2024-06-27 09:50:50 +00:00
Daniel McNab d99e7af31f
Fix the mentions of Masonry issues to use issue links (#412)
Since we merged https://github.com/linebender/masonry into this
repository, these issue numbers were out-of-date.

I found these by search for `#[0-9]`, and got the updated links using
`https://github.com/linebender/masonry/issues/{x}`
2024-06-26 13:06:18 +00:00
Daniel McNab 2d88a63645
Handle an empty preedit (#387)
Since #314, we request the IME to be positioned every paint cycle. This
triggers a new event from the IME, which is a preedit clear. This IME
event also breaks text selection, which is why we handle it here.

This is still not the fully correct behaviour, but it does at least make
text selection in textboxes work again. We really need to improve our
testing story here.

Also give more detail in the short form of IME events; these events all
have quite different properties.
2024-06-24 17:28:33 +00:00
Daniel McNab d5bbb4cc35
Don't create a log file and print its name unless it will be used (#410)
Previously, this had the potential to be quite confusing.
2024-06-24 13:45:52 +00:00
Olivier FAURE 9d7b9a6b04
Move another log line to reduce noise (#409) 2024-06-22 13:29:45 +00:00
Olivier FAURE 27a6b6285d
Move a log line to avoid false positives and reduce noise (#407) 2024-06-21 10:23:24 +00:00
Daniel McNab 9299b67986
Move to a single global `parley::LayoutContext` (#405)
Based on a suggestion from @dfrg.

This appears to have improved performance with the 30_000 hello's
example from ~$\frac{1}{20}$ms to $\frac{1}{160}$ms
So an approx 8x increase in throughput for that scene.
2024-06-18 19:04:17 +00:00
Olivier FAURE dd196c7134
Tweak code in post_event_processing (#270)
Inline `wants_animation_frame`.
Request new frame for both visual and accessibility updates.
2024-06-17 10:16:42 +00:00
Daniel McNab 7d62b16a19
Create a `View` for `SizedBox` (#398)
![image](https://github.com/linebender/xilem/assets/36049421/9b1cccc2-15d9-48dc-aca8-eddeb32dfac5)

I have chosen not to set the background and border properties, as those
are moreso styling properties - in our current state, we seem to be much
preferring only specifying layout values
2024-06-14 17:04: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
Daniel McNab a63c708ff2
Fix textboxes with an infinite available width (#386)
Also fix clipping behaviour - previously the textbox outline would be
clipped.
2024-06-11 17:49:08 +00:00
Olivier FAURE 921912b10c
Fix typos in tracing code (#385) 2024-06-10 12:56:45 +00:00
Olivier FAURE 36d894cfde
Small improvements to tracing code (#384) 2024-06-10 11:15:36 +00:00
Daniel McNab 8386ad2399
Add milliseconds in the tracing formatting (#383)
In #254, we had an initial log format added.

However, that doesn't include support for milliseconds, which are useful
in a GUI system because it allows getting a first approximation of
latency. I'm adding this now because of the startup latency issues first
observed in #381 ([#masonry > Slight Startup Time
Regression](https://xi.zulipchat.com/#narrow/stream/317477-masonry/topic/Slight.20Startup.20Time.20Regression))
2024-06-10 10:14:12 +00:00
Bruce Mitchener 1ddff7be92
deps: Update `wgpu`, `vello`, `peniko` (#381)
This brings us to the 0.2 release of Vello, which brings the 0.20
release of wgpu.
2024-06-10 08:29:53 +00:00
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 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 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 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 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
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
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
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