Commit Graph

36 Commits

Author SHA1 Message Date
Bruce Mitchener 231e304249
masonry example: Fix reference to `on_status_changed` (#719)
This is now just `update`.
2024-10-29 16:40:35 +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 dc9a2e2a97
Rename lifecycle to update (#677) 2024-10-17 12:09:14 +00:00
Olivier FAURE f4a8b47587
Refactor safety rails for layout pass (#644)
Merge call_widget_method_with_checks, run_layout_inner and
run_layout_on.
Remove needs_visit flag.
Add checks for invalid values in place_child, set_child_translation and
run_layout.

---------

Co-authored-by: jaredoconnell <jared.oc321@gmail.com>
2024-10-15 16:25:46 +00:00
Olivier FAURE 9a6178b3d4
Add request_render context method (#660)
Remove some redundant request_paint calls

Fixes #585.
2024-10-15 16:18:47 +00:00
Marco Melorio 634afd7010
Expose font weight parameter in label widget (#669) 2024-10-14 17:01:53 +00:00
Olivier FAURE a26bf11119
Add target field to EventCtx (#657)
Remove target field from AccessEvent
2024-10-13 01:21:52 +00:00
Olivier FAURE f6ad804ae6
Remove last mentions of hot state from code (#654) 2024-10-08 17:12:13 +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
failingprovince fe140afc9a
feat(#574): reimplementation of `Image` widget `layout` function (#605)
Reimplement calculation of image size in `Image` widget `layout`
function.
Makes it match against `self.fill` before setting size.

Tests still missing.

Fixes #574
2024-10-02 10:08:00 +00:00
Matt Campbell 997da0314b
Remove `current_node` from `AccessCtx` (#614)
It makes more sense to pass the `NodeBuilder` reference separately to
the `accessibility` method. In particular, this avoids the need to keep
calling a method on `AccessCtx` to get that mutable reference.
2024-09-26 18:13:56 +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
Olivier FAURE 09d9ad555d
Make `Textbox` focusable and trigger redraw in response to `request_layout` (#537)
Fixes #301.
2024-09-16 15:31:37 +00:00
Jared O'Connell 3726e91a48
Grid layout (#570)
This PR adds a basic grid layout to Masonry and Xilem.

The way this layout works is it has a fixed grid based on the initial
size passed in, and grid items are placed based on the position
requested. Grid items are allowed to span more than one cell, if
requested.

There are potential improvements that could be done, like the use of
intrinsic sizing for varied column width based on content size. Though
that could be done in the future taffy layout if we want to keep this
one simple.


~~This PR is still a draft because of one remaining concern. I was not
able to successfully optimize with conditional calls to child widgets
for layout. It led to crashes about the paint rects not being within the
widget's paint rect. `Error in 'Grid' #16: paint_rect Rect { x0: 0.0,
y0: 0.0, x1: 800.0, y1: 610.0 } doesn't contain paint_rect Rect { x0:
400.5, y0: 0.0, x1: 800.5, y1: 150.0 } of child widget 'Button' #5`. My
failed attempt at fixing it is commented out.~~

Since I am rusty on View Sequences, a lot of that code is based on the
Flex implementation. Let me know if I did anything incorrectly or if any
of it is unnecessary, or if anything is missing.

---------

Co-authored-by: Daniel McNab <36049421+DJMcNab@users.noreply.github.com>
2024-09-11 14:55:19 +00:00
Tom Churchman 9a3c8e308c
masonry: replace `set_active` and `is_active` with pointer capture (#564)
Also improve documentation of pointer capture.

Continuation of 59ee615651
(https://github.com/linebender/xilem/pull/488).

Makes `has_pointer_capture` available on all context types except
`LayoutCtx`, like `is_active` used to be.
2024-09-10 11:55:51 +00:00
Olivier FAURE dcea01a4a9
Migrate layout pass (#529) 2024-09-09 12:35:36 +00:00
Tom Churchman 923c0fb8ca
Remove manual recursion to child `paint` and `accessibility` (#557)
Recursing is done inside the paint and accessibility passes since
ff7635e4c2. I believe this is the correct
continuation of #522, with the removal of these methods "left for later"
as mentioned in
https://github.com/linebender/xilem/pull/522#issuecomment-2298610203.

One note is that Flex now debug-paints its baseline under its children,
rather than over them.
2024-08-28 13:41:36 +00:00
Bruce Mitchener 7bd572b9a3
Fix typos. (#556) 2024-08-26 13:55:55 +00:00
Olivier FAURE 42a6a320da
Fix visual bug in masonry_calc example (#526) 2024-08-19 15:13:26 +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
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 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
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
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 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
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 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 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
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
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