-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Conversation
…disable dithering
# Conflicts: # Cargo.lock # crates/egui_demo_lib/src/demo/widget_gallery.rs # crates/egui_demo_lib/tests/snapshots/widget_gallery.png # crates/egui_kittest/Cargo.toml # crates/egui_kittest/README.md # crates/egui_kittest/src/builder.rs # crates/egui_kittest/src/lib.rs # crates/egui_kittest/src/snapshot.rs # crates/egui_kittest/src/wgpu.rs
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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:
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
Preview available at https://egui-pr-preview.github.io/pr/5301-lucas/basic_tests |
There was a problem hiding this comment.
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)
pub fn run_sizing_pass(&mut self, ctx: &egui::Context) -> Option<egui::Response> { | ||
match self { | ||
AppKind::Context(f) => { | ||
f(ctx); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
…ing outside of the aspected area
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>
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.