Simplify kittest readme example (#5486)
Updates the example using the new_ui function, and call fit_contents - [x] I have followed the instructions in the PR template
This commit is contained in:
parent
320377e3ca
commit
69dbb00087
|
|
@ -4,21 +4,16 @@ Ui testing library for egui, based on [kittest](https://github.com/rerun-io/kitt
|
||||||
|
|
||||||
## Example usage
|
## Example usage
|
||||||
```rust
|
```rust
|
||||||
use egui::accesskit::{Role, Toggled};
|
use egui::accesskit::Toggled;
|
||||||
use egui::{CentralPanel, Context, TextEdit, Vec2};
|
use egui_kittest::{Harness, kittest::Queryable};
|
||||||
use egui_kittest::Harness;
|
|
||||||
use kittest::Queryable;
|
|
||||||
use std::cell::RefCell;
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let mut checked = false;
|
let mut checked = false;
|
||||||
let app = |ctx: &Context| {
|
let app = |ui: &mut egui::Ui| {
|
||||||
CentralPanel::default().show(ctx, |ui| {
|
ui.checkbox(&mut checked, "Check me!");
|
||||||
ui.checkbox(&mut checked, "Check me!");
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut harness = Harness::builder().with_size(egui::Vec2::new(200.0, 100.0)).build(app);
|
let mut harness = Harness::new_ui(app);
|
||||||
|
|
||||||
let checkbox = harness.get_by_label("Check me!");
|
let checkbox = harness.get_by_label("Check me!");
|
||||||
assert_eq!(checkbox.toggled(), Some(Toggled::False));
|
assert_eq!(checkbox.toggled(), Some(Toggled::False));
|
||||||
|
|
@ -28,6 +23,9 @@ fn main() {
|
||||||
|
|
||||||
let checkbox = harness.get_by_label("Check me!");
|
let checkbox = harness.get_by_label("Check me!");
|
||||||
assert_eq!(checkbox.toggled(), Some(Toggled::True));
|
assert_eq!(checkbox.toggled(), Some(Toggled::True));
|
||||||
|
|
||||||
|
// Shrink the window size to the smallest size possible
|
||||||
|
harness.fit_contents();
|
||||||
|
|
||||||
// You can even render the ui and do image snapshot tests
|
// You can even render the ui and do image snapshot tests
|
||||||
#[cfg(all(feature = "wgpu", feature = "snapshot"))]
|
#[cfg(all(feature = "wgpu", feature = "snapshot"))]
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,3 @@
|
||||||
version https://git-lfs.github.com/spec/v1
|
version https://git-lfs.github.com/spec/v1
|
||||||
oid sha256:36c1b432140456ea5cbb687076b1c910aea8b31affd33a0ece22218f60af2d6e
|
oid sha256:31bd906040fcc356c19dc36036fbfd2a28dfcef54c7a073f584f4a9abddbdb4c
|
||||||
size 2296
|
size 1699
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue