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

Add Harness::new_ui, Harness::fit_contents #5301

Merged
merged 55 commits into from
Nov 1, 2024
Merged

Conversation

lucasmerlin
Copy link
Collaborator

This adds a Harness::new_ui, which accepts a Ui closure and shows the ui in a central panel. One big benefit is that this allows us to add a fit_contents method that can run the ui closure with a sizing pass and resize the "screen" based on the content size.

I also used this to add a snapshot test for the rendering_test at different scales.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I wonder, should we add some margin by default? I think no margin is more correct, since it is actually what the ui is but more margin would make the screenshots look nicer. Also, should I change the background to be transparent?

Copy link
Owner

Choose a reason for hiding this comment

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

Once #4019 is done, widget should just perfectly kiss the border, so we need some way to see that.

So I think it makes sense to add a transparent margin. The opaque background then signifies the rectangle of the Ui, but we can still see wether or not a widget paints outside of that area (which could be a bug)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Makes sense! I added an 8px margin with transparent bg and you can immedeately see that the separator is one px too wide:

image

Also, I noticed that the snapshot ignores alpha, meaning a completely transparent is the same as a completely black one and the snapshot test will succeed. I'll open an issue in dify

@lucasmerlin lucasmerlin added exclude from changelog tests Unit tests, regression tests, manual tests, … labels Oct 23, 2024
Copy link

Preview available at https://egui-pr-preview.github.io/pr/5301-lucas/basic_tests
Note that it might take a couple seconds for the update to show up after the preview_build workflow has completed.

crates/egui_demo_lib/src/demo/widget_gallery.rs Outdated Show resolved Hide resolved
Copy link
Owner

Choose a reason for hiding this comment

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

Once #4019 is done, widget should just perfectly kiss the border, so we need some way to see that.

So I think it makes sense to add a transparent margin. The opaque background then signifies the rectangle of the Ui, but we can still see wether or not a widget paints outside of that area (which could be a bug)

crates/egui_kittest/src/harness_kind.rs Outdated Show resolved Hide resolved
pub fn run_sizing_pass(&mut self, ctx: &egui::Context) -> Option<egui::Response> {
match self {
AppKind::Context(f) => {
f(ctx);
Copy link
Owner

Choose a reason for hiding this comment

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

Maybe we should panic here, since we're not setting any sizing-pass specialness in the Context case?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I added an assert in #5313

@lucasmerlin lucasmerlin added egui_kittest and removed tests Unit tests, regression tests, manual tests, … labels Oct 29, 2024
@lucasmerlin lucasmerlin merged commit ad14bf2 into master Nov 1, 2024
47 checks passed
@lucasmerlin lucasmerlin deleted the lucas/basic_tests branch November 1, 2024 17:30
lucasmerlin added a commit that referenced this pull request Nov 6, 2024
The allows us to pass any state to the ui closure. While it is possible
to just store state in the closure itself, accessing that state after
the harness was created to e.g. read or modify it would require interior
mutability. With this change there are new `Harness::new_state`,
`Harness::run_state`, ... methods that allow passing state on each run.

This builds on top of #5301, which should be merged first

---------

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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants