-
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
egui_kittest: Allow passing state to the app closure #5313
Conversation
# 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
Preview available at https://egui-pr-preview.github.io/pr/5313-lucas/kittest_state |
I just realized that it would also possible to store the generic state in the Harness, making it accessible via a state_mut function (or just making it public on the Harness struct). That would allow us to get rid of all the extra |
So we want to have mutable state that is both easily accessible from the ui closure, but that can also be inspected at the end of the test so we can check that the state ended up in the correct, well, state. 🤔 I agree that forcing users to use I also agree that the Putting the state in the harness does seem more attractive. We could make |
I've updated it so the harness owns the state. I think this is a bit nicer, but I think tests using this are now a bit less readable. But still, I think the benefits outweigh the disadvantage here. Also, if you only need to check the state at the end of the test, and not somewhere in between, one could also just reference it in the closure and then drop() the harness and then the state can be accessed again to do a final assert |
41fa5d6
to
01e157a
Compare
…ing outside of the aspected area
01e157a
to
f3e5d55
Compare
f3e5d55
to
e38fe1d
Compare
# Conflicts: # crates/egui_kittest/src/app_kind.rs # crates/egui_kittest/src/builder.rs # crates/egui_kittest/src/lib.rs
Somehow the spell checker suddenly finds some old typos not introduced in this PR 🤔 I've fixed them in #5339 |
The spell check pipeline in #5313 suddenly failed, this fixes these typos and some more found via my IDEs spell checker tool
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