Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce UiStack #4588

Merged
merged 13 commits into from
Jun 4, 2024
Merged

Introduce UiStack #4588

merged 13 commits into from
Jun 4, 2024

Conversation

abey79
Copy link
Collaborator

@abey79 abey79 commented May 30, 2024

This PR:

  • Introduces Ui::stack(), which returns the UiStack structure providing information on the current Ui hierarchy.
  • BREAKING: Ui::new() now takes a UiStackInfo argument, which is used to populate some of this Ui's UiStack's fields.
  • BREAKING: Ui::child_ui() and Ui::child_ui_with_id_source() now take an Option<UiStackInfo> argument, which is used to populate some of the children Ui's UiStack's fields.
  • New Area::kind() builder function, to set the UiStackKind value of the Area's Ui.
  • Adds a (minimalistic) demo to egui demo (in the "Misc Demos" window).
  • Adds a more thorough test_ui_stack test/playground demo.

TODO:

  •  benchmarks
  • add example to demo

Future work:

  • Add UiStackKind and related support for more container (e.g. CollapsingHeader, etc.)
  • Add a tag/property system that would allow adding arbitrary data to a stack node. This data could then be queried by nested Uis. Probably needed for CSS-like styling #3284.
  • Add support to track columnar layouts.

@abey79 abey79 added feature New feature or request egui labels May 30, 2024
@abey79
Copy link
Collaborator Author

abey79 commented May 30, 2024

benchmark for main, "change" are w.r.t this PR. TL;DR: nothing significant.

demo_with_tessellate__realistic
                        time:   [162.71 µs 163.43 µs 164.22 µs]
                        change: [-0.5310% -0.0758% +0.3821%] (p = 0.75 > 0.05)
                        No change in performance detected.
Found 1 outliers among 100 measurements (1.00%)
  1 (1.00%) high mild

demo_no_tessellate      time:   [100.03 µs 100.27 µs 100.55 µs]
                        change: [-0.9036% -0.4831% +0.0081%] (p = 0.04 < 0.05)
                        Change within noise threshold.
Found 1 outliers among 100 measurements (1.00%)
  1 (1.00%) high severe

demo_only_tessellate    time:   [63.612 µs 63.759 µs 63.910 µs]
                        change: [+0.0594% +0.6954% +1.3806%] (p = 0.04 < 0.05)
                        Change within noise threshold.
Found 4 outliers among 100 measurements (4.00%)
  3 (3.00%) high mild
  1 (1.00%) high severe

label &str              time:   [553.38 ns 618.15 ns 757.60 ns]
                        change: [-18.927% -3.9587% +12.659%] (p = 0.71 > 0.05)
                        No change in performance detected.
Found 1 outliers among 100 measurements (1.00%)
  1 (1.00%) high severe

label format!           time:   [607.36 ns 723.32 ns 973.61 ns]
                        change: [-34.326% -6.3731% +32.513%] (p = 0.78 > 0.05)
                        No change in performance detected.
Found 10 outliers among 100 measurements (10.00%)
  6 (6.00%) high mild
  4 (4.00%) high severe

Painter::rect           time:   [31.272 ns 31.625 ns 31.942 ns]
                        change: [-4.8340% -3.4710% -2.1191%] (p = 0.00 < 0.05)
                        Performance has improved.

text_layout_uncached    time:   [62.191 µs 62.366 µs 62.584 µs]
                        change: [+0.1487% +0.3898% +0.6197%] (p = 0.00 < 0.05)
                        Change within noise threshold.
Found 7 outliers among 100 measurements (7.00%)
  1 (1.00%) low mild
  2 (2.00%) high mild
  4 (4.00%) high severe

text_layout_cached      time:   [209.13 ns 209.47 ns 209.86 ns]
                        change: [-0.0661% +0.1518% +0.3733%] (p = 0.17 > 0.05)
                        No change in performance detected.
Found 3 outliers among 100 measurements (3.00%)
  3 (3.00%) high mild

tessellate_text         time:   [8.3576 µs 8.4386 µs 8.5532 µs]
                        change: [+0.0148% +0.6121% +1.5481%] (p = 0.10 > 0.05)
                        No change in performance detected.
Found 16 outliers among 100 measurements (16.00%)
  1 (1.00%) low mild
  8 (8.00%) high mild
  7 (7.00%) high severe

@abey79 abey79 marked this pull request as ready for review May 31, 2024 08:26
Copy link
Owner

@emilk emilk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

crates/egui/src/ui.rs Outdated Show resolved Hide resolved
crates/egui/src/ui_stack.rs Outdated Show resolved Hide resolved
crates/egui/src/ui_stack.rs Outdated Show resolved Hide resolved
type Item = Arc<UiStack>;

fn next(&mut self) -> Option<Self::Item> {
let current = self.next.clone();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you use references (and lifetimes) we can avoid this .clone(). I think this is likely to be on the hot path of quite a few layout thing in the future.

crates/egui/src/ui_stack.rs Show resolved Hide resolved
crates/egui_extras/src/layout.rs Outdated Show resolved Hide resolved
examples/hello_world/src/main.rs Outdated Show resolved Hide resolved
abey79 and others added 7 commits June 4, 2024 09:19
@abey79 abey79 merged commit a287921 into master Jun 4, 2024
35 checks passed
@abey79 abey79 deleted the antoine/ui-stack branch June 4, 2024 08:12
abey79 added a commit to rerun-io/rerun that referenced this pull request Jun 4, 2024
### What

- Fixes #6246
- Very tiny bit of #4569

This PR uses emilk/egui#4588 to replace the
`full_span` mechanism, which requires less boilerplate and makes it
available in many more places (including tooltips). The
`get_full_span()` function now lives in a `Ui` extension trait, where
the rest of `re_ui` should eventually migrate (#4569).

This PR also updates egui/egui_tiles/egui_commonmark to the latest
commits.

### Checklist
* [x] I have read and agree to [Contributor
Guide](https://github.com/rerun-io/rerun/blob/main/CONTRIBUTING.md) and
the [Code of
Conduct](https://github.com/rerun-io/rerun/blob/main/CODE_OF_CONDUCT.md)
* [x] I've included a screenshot or gif (if applicable)
* [x] I have tested the web demo (if applicable):
* Using examples from latest `main` build:
[rerun.io/viewer](https://rerun.io/viewer/pr/6491?manifest_url=https://app.rerun.io/version/main/examples_manifest.json)
* Using full set of examples from `nightly` build:
[rerun.io/viewer](https://rerun.io/viewer/pr/6491?manifest_url=https://app.rerun.io/version/nightly/examples_manifest.json)
* [x] The PR title and labels are set such as to maximize their
usefulness for the next release's CHANGELOG
* [x] If applicable, add a new check to the [release
checklist](https://github.com/rerun-io/rerun/blob/main/tests/python/release_checklist)!

- [PR Build Summary](https://build.rerun.io/pr/6491)
- [Recent benchmark results](https://build.rerun.io/graphs/crates.html)
- [Wasm size tracking](https://build.rerun.io/graphs/sizes.html)

To run all checks from `main`, comment on the PR with `@rerun-bot
full-check`.
hacknus pushed a commit to hacknus/egui that referenced this pull request Oct 30, 2024
* Closes emilk#4534

This PR:
- Introduces `Ui::stack()`, which returns the `UiStack` structure
providing information on the current `Ui` hierarchy.
- **BREAKING**: `Ui::new()` now takes a `UiStackInfo` argument, which is
used to populate some of this `Ui`'s `UiStack`'s fields.
- **BREAKING**: `Ui::child_ui()` and `Ui::child_ui_with_id_source()` now
take an `Option<UiStackInfo>` argument, which is used to populate some
of the children `Ui`'s `UiStack`'s fields.
- New `Area::kind()` builder function, to set the `UiStackKind` value of
the `Area`'s `Ui`.
- Adds a (minimalistic) demo to egui demo (in the "Misc Demos" window).
- Adds a more thorough `test_ui_stack` test/playground demo.

TODO:
- [x] benchmarks
- [x] add example to demo

Future work:
- Add `UiStackKind` and related support for more container (e.g.
`CollapsingHeader`, etc.)
- Add a tag/property system that would allow adding arbitrary data to a
stack node. This data could then be queried by nested `Ui`s. Probably
needed for emilk#3284.
- Add support to track columnar layouts.

---------

Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
egui feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Store a Ui/Frame-stack
2 participants