mirror of
https://github.com/emilk/egui.git
synced 2026-08-29 04:40:03 -04:00
Add ImageLoader::has_pending and wait_for_pending_images (#7030)
With kittest it was difficult to wait for images to be loaded before taking a snapshot test. This PR adds `Harness::with_wait_for_pending_images` (true by default) which will cause `Harness::run` to sleep until all images are loaded (or `HarnessBuilder::with_max_steps` is exceeded). It also adds a new ImageLoader::has_pending and BytesLoader::has_pending, which should be implemented if things are loaded / decoded asynchronously. It reverts https://github.com/emilk/egui/pull/6901 which was my previous attempt to fix this (but this didn't work since only the tested crate is compiled with cfg(test) and not it's dependencies)
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:6298e67d099002808d51e7494e4174adee66d7ef2880728126c1d761d1432372
|
||||
size 2145
|
||||
@@ -1,4 +1,4 @@
|
||||
use egui::Modifiers;
|
||||
use egui::{include_image, Modifiers, Vec2};
|
||||
use egui_kittest::Harness;
|
||||
use kittest::{Key, Queryable as _};
|
||||
|
||||
@@ -57,3 +57,29 @@ fn test_modifiers() {
|
||||
assert!(state.cmd_z_pressed, "Cmd+Z wasn't pressed");
|
||||
assert!(state.cmd_y_pressed, "Cmd+Y wasn't pressed");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn should_wait_for_images() {
|
||||
let mut harness = Harness::builder()
|
||||
.with_size(Vec2::new(60.0, 120.0))
|
||||
.build_ui(|ui| {
|
||||
egui_extras::install_image_loaders(ui.ctx());
|
||||
let size = Vec2::splat(30.0);
|
||||
ui.label("Url:");
|
||||
ui.add_sized(
|
||||
size,
|
||||
egui::Image::new(
|
||||
"https://raw.githubusercontent.com\
|
||||
/emilk/egui/refs/heads/main/crates/eframe/data/icon.png",
|
||||
),
|
||||
);
|
||||
|
||||
ui.label("Include:");
|
||||
ui.add_sized(
|
||||
size,
|
||||
egui::Image::new(include_image!("../../eframe/data/icon.png")),
|
||||
);
|
||||
});
|
||||
|
||||
harness.snapshot("should_wait_for_images");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user