-
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::fit_contents and add rendering_test snapshot test
- Loading branch information
1 parent
e824e01
commit 7cad2da
Showing
16 changed files
with
192 additions
and
24 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
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
3 changes: 3 additions & 0 deletions
3
crates/egui_demo_lib/tests/snapshots/rendering_test/dpi_1.00.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
crates/egui_demo_lib/tests/snapshots/rendering_test/dpi_1.25.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
crates/egui_demo_lib/tests/snapshots/rendering_test/dpi_1.50.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
crates/egui_demo_lib/tests/snapshots/rendering_test/dpi_1.67.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
crates/egui_demo_lib/tests/snapshots/rendering_test/dpi_1.75.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
crates/egui_demo_lib/tests/snapshots/rendering_test/dpi_2.00.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
use egui::Frame; | ||
|
||
type AppKindContext<'a> = Box<dyn FnMut(&egui::Context) + 'a>; | ||
type AppKindUi<'a> = Box<dyn FnMut(&mut egui::Ui) + 'a>; | ||
|
||
pub enum AppKind<'a> { | ||
Context(AppKindContext<'a>), | ||
Ui(AppKindUi<'a>), | ||
} | ||
|
||
// TODO: These aren't working unfortunately :( | ||
// I think they should work though: https://geo-ant.github.io/blog/2021/rust-traits-and-variadic-functions/ | ||
// pub trait IntoAppKind<'a, UiKind> { | ||
// fn into_harness_kind(self) -> AppKind<'a>; | ||
// } | ||
// | ||
// impl<'a, F> IntoAppKind<'a, &egui::Context> for F | ||
// where | ||
// F: FnMut(&egui::Context) + 'a, | ||
// { | ||
// fn into_harness_kind(self) -> AppKind<'a> { | ||
// AppKind::Context(Box::new(self)) | ||
// } | ||
// } | ||
// | ||
// impl<'a, F> IntoAppKind<'a, &mut egui::Ui> for F | ||
// where | ||
// F: FnMut(&mut egui::Ui) + 'a, | ||
// { | ||
// fn into_harness_kind(self) -> AppKind<'a> { | ||
// AppKind::Ui(Box::new(self)) | ||
// } | ||
// } | ||
|
||
impl<'a> AppKind<'a> { | ||
pub fn run(&mut self, ctx: &egui::Context) -> Option<egui::Response> { | ||
match self { | ||
AppKind::Context(f) => { | ||
f(ctx); | ||
None | ||
} | ||
AppKind::Ui(f) => Some(Self::run_ui(f, ctx, false)), | ||
} | ||
} | ||
|
||
pub fn run_sizing_pass(&mut self, ctx: &egui::Context) -> Option<egui::Response> { | ||
match self { | ||
AppKind::Context(f) => { | ||
f(ctx); | ||
None | ||
} | ||
AppKind::Ui(f) => Some(Self::run_ui(f, ctx, true)), | ||
} | ||
} | ||
|
||
fn run_ui(f: &mut AppKindUi<'a>, ctx: &egui::Context, sizing_pass: bool) -> egui::Response { | ||
egui::CentralPanel::default() | ||
.frame( | ||
Frame::central_panel(&ctx.style()) | ||
.inner_margin(0.0) | ||
.outer_margin(0.0), | ||
) | ||
.show(ctx, |ui| { | ||
let mut builder = egui::UiBuilder::new(); | ||
if sizing_pass { | ||
builder.sizing_pass = true; | ||
} | ||
ui.scope_builder(builder, f).response | ||
}) | ||
.inner | ||
} | ||
} |
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,14 @@ | ||
use egui_kittest::Harness; | ||
|
||
#[test] | ||
fn test_shrink() { | ||
let mut harness = Harness::new_ui(|ui| { | ||
ui.label("Hello, world!"); | ||
ui.separator(); | ||
ui.label("This is a test"); | ||
}); | ||
|
||
harness.fit_contents(); | ||
|
||
harness.wgpu_snapshot("test_shrink"); | ||
} |