egui/crates
mitchmindtree 4445497546
`Scene`: Set transform layer before calling user content (#5884)
This changes the `Scene` behaviour to call `set_transform_layer` prior
to calling the user content fn, rather than after.

### Motivation

This provides a simple way for the user to access the `TSTransform` that
will be applied to the `Scene` within the user content function, e.g.

```rust
ui.ctx().layer_transform_to_global(ui.layer_id())
```

Previously getting the transform like this still kind of worked, but
resulted in the user content lagging behind the actual scene position by
a single frame, which looks a bit strange.

With this PR, the user content using the transform no longer lags by a
frame, and matches the scene's transform perfectly.

Accessing the `TSTransform` of the `Scene` within the user content
function is useful for the case where the user may want to instantiate
new `Ui` sublayers that also track the scene (by default, sublayers do
*not* apply the same transform as the scene, likely the cause of #5682).
With these changes, the user can have sublayers track the scene like so:

```rust
let scene_layer = ui.layer_id();
let sub_layer = egui::LayerId::new(scene_layer.order, self.id);
ui.ctx().set_sublayer(scene_layer, sub_layer);
let scene_transform = ui.ctx().layer_transform_to_global(scene_layer).unwrap();
ui.ctx().set_transform_layer(sub_layer, scene_transform);
```

### Tested with

- `egui_demo_app` scene example.
- Local `egui_graph` demo example.

---

<!--
Please read the "Making a PR" section of
[`CONTRIBUTING.md`](https://github.com/emilk/egui/blob/master/CONTRIBUTING.md)
before opening a Pull Request!

* Keep your PR:s small and focused.
* The PR title is what ends up in the changelog, so make it descriptive!
* If applicable, add a screenshot or gif.
* If it is a non-trivial addition, consider adding a demo for it to
`egui_demo_lib`, or a new example.
* Do NOT open PR:s from your `master` branch, as that makes it hard for
maintainers to test and add commits to your PR.
* Remember to run `cargo fmt` and `cargo clippy`.
* Open the PR as a draft until you have self-reviewed it and run
`./scripts/check.sh`.
* When you have addressed a PR comment, mark it as resolved.

Please be patient! I will review your PR, but my time is limited!
-->

* Closes <https://github.com/emilk/egui/issues/THE_RELEVANT_ISSUE>
* [x] I have followed the instructions in the PR template
2025-04-08 11:16:29 +02:00
..
ecolor Add assert messages and print bad argument values in asserts (#5216) 2025-03-25 09:20:29 +01:00
eframe Use lychee link checker instead of linkinator (#5868) 2025-04-03 09:26:49 +02:00
egui `Scene`: Set transform layer before calling user content (#5884) 2025-04-08 11:16:29 +02:00
egui-wgpu Release 0.31.1 - text_edit and kittest fixes 2025-03-05 08:37:34 +01:00
egui-winit Fix text input on Android (#5759) 2025-03-21 14:35:46 +01:00
egui_demo_app Make text underline and strikethrough pixel perfect crisp (#5857) 2025-03-28 20:37:38 +01:00
egui_demo_lib Use `TextBuffer` for `layouter` in `TextEdit` instead of `&str` (#5712) 2025-04-06 18:45:20 +02:00
egui_extras Make text background rects pixel-sharp (#5864) 2025-03-30 16:21:00 +02:00
egui_glow Add assert messages and print bad argument values in asserts (#5216) 2025-03-25 09:20:29 +01:00
egui_kittest Improve text sharpness (#5838) 2025-03-21 12:56:47 +01:00
egui_plot Move `egui_plot` to its own repo (#4828) 2024-07-15 18:45:19 +02:00
egui_web Fix typos (#2866) 2023-04-18 15:52:45 +02:00
emath Optimize editing long text by caching each paragraph (#5411) 2025-04-01 18:55:39 +02:00
epaint Optimize editing long text by caching each paragraph (#5411) 2025-04-01 18:55:39 +02:00
epaint_default_fonts Release 0.31.1 - text_edit and kittest fixes 2025-03-05 08:37:34 +01:00