-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Harness::builder and add README.md
- Loading branch information
1 parent
e0d8263
commit e1a8196
Showing
10 changed files
with
244 additions
and
164 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# egui_kittest | ||
|
||
Ui testing library for egui, based on [kittest](https://github.com/rerun-io/kittest) (a AccessKit based testing library). | ||
|
||
```rust | ||
use egui::accesskit::{Role, Toggled}; | ||
use egui::{CentralPanel, Context, TextEdit, Vec2}; | ||
use egui_kittest::Harness; | ||
use kittest::Queryable; | ||
use std::cell::RefCell; | ||
|
||
fn main() { | ||
let mut checked = false; | ||
let app = |ctx: &Context| { | ||
CentralPanel::default().show(ctx, |ui| { | ||
ui.checkbox(&mut checked, "Check me!"); | ||
}); | ||
}; | ||
|
||
let mut harness = Harness::builder().with_size(egui::Vec2::new(200.0, 100.0)).build(app); | ||
|
||
let checkbox = harness.get_by_name("Check me!"); | ||
assert_eq!(checkbox.toggled(), Some(Toggled::False)); | ||
checkbox.click(); | ||
|
||
harness.run(); | ||
|
||
let checkbox = harness.get_by_name("Check me!"); | ||
assert_eq!(checkbox.toggled(), Some(Toggled::True)); | ||
|
||
// You can even render the ui and do image snapshot tests | ||
#[cfg(all(feature = "wgpu", feature = "snapshot"))] | ||
egui_kittest::image_snapshot(&egui_kittest::wgpu::TestRenderer::new().render(&harness), "readme_example"); | ||
} | ||
``` |
This file was deleted.
Oops, something went wrong.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
use crate::Harness; | ||
use egui::{Pos2, Rect, Vec2}; | ||
|
||
pub struct HarnessBuilder { | ||
pub(crate) screen_rect: Rect, | ||
pub(crate) dpi: f32, | ||
} | ||
|
||
impl Default for HarnessBuilder { | ||
fn default() -> Self { | ||
Self { | ||
screen_rect: Rect::from_min_size(Pos2::ZERO, Vec2::new(800.0, 600.0)), | ||
dpi: 1.0, | ||
} | ||
} | ||
} | ||
|
||
impl HarnessBuilder { | ||
pub fn with_size(mut self, size: Vec2) -> Self { | ||
self.screen_rect.set_width(size.x); | ||
self.screen_rect.set_height(size.y); | ||
self | ||
} | ||
|
||
pub fn with_dpi(mut self, dpi: f32) -> Self { | ||
self.dpi = dpi; | ||
self | ||
} | ||
|
||
pub fn build<'a>(self, app: impl FnMut(&egui::Context) + 'a) -> Harness<'a> { | ||
Harness::from_builder(&self, app) | ||
} | ||
} |
Oops, something went wrong.