Skip to content

Commit

Permalink
Simplify kittest readme example (#5486)
Browse files Browse the repository at this point in the history
Updates the example using the new_ui function, and call fit_contents
- [x] I have followed the instructions in the PR template
  • Loading branch information
lucasmerlin authored Dec 16, 2024
1 parent 320377e commit 69dbb00
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
18 changes: 8 additions & 10 deletions crates/egui_kittest/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,16 @@ Ui testing library for egui, based on [kittest](https://github.com/rerun-io/kitt

## Example usage
```rust
use egui::accesskit::{Role, Toggled};
use egui::{CentralPanel, Context, TextEdit, Vec2};
use egui_kittest::Harness;
use kittest::Queryable;
use std::cell::RefCell;
use egui::accesskit::Toggled;
use egui_kittest::{Harness, kittest::Queryable};

fn main() {
let mut checked = false;
let app = |ctx: &Context| {
CentralPanel::default().show(ctx, |ui| {
ui.checkbox(&mut checked, "Check me!");
});
let app = |ui: &mut egui::Ui| {
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!");
assert_eq!(checkbox.toggled(), Some(Toggled::False));
Expand All @@ -28,6 +23,9 @@ fn main() {

let checkbox = harness.get_by_label("Check me!");
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
#[cfg(all(feature = "wgpu", feature = "snapshot"))]
Expand Down
4 changes: 2 additions & 2 deletions crates/egui_kittest/tests/snapshots/readme_example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 69dbb00

Please sign in to comment.