diff --git a/crates/ui-egui/src/font_menu.rs b/crates/ui-egui/src/font_menu.rs index c7a74e3178..554eb9229f 100644 --- a/crates/ui-egui/src/font_menu.rs +++ b/crates/ui-egui/src/font_menu.rs @@ -1642,18 +1642,20 @@ pub(crate) fn render_sample_for_test(family: &str, text: &str, px: u32) -> Optio } /// Waits for the samples rendering on this thread's behalf and keeps them, so the next frame -/// draws them. +/// draws them. Returns `false` when no sample was rendering. #[cfg(all(test, not(target_arch = "wasm32")))] -pub(crate) fn wait_for_samples(ctx: &egui::Context) { +pub(crate) fn wait_for_samples(ctx: &egui::Context) -> bool { SAMPLES.with(|s| { let mut s = s.borrow_mut(); let pending: Vec<_> = s.pending.drain().collect(); + let waited = !pending.is_empty(); for (key, rx) in pending { let tex = rx.recv().ok().flatten().map(|img| ctx.load_texture(format!("font-sample-{}-{}", key.0, key.3), img, egui::TextureOptions::LINEAR)); s.ready.insert(key, tex); } - }); + waited + }) } // ---------- applying a pick ---------- diff --git a/crates/ui-egui/src/tests/font_menu.rs b/crates/ui-egui/src/tests/font_menu.rs index 7ab5378e14..2c600d1aa3 100644 --- a/crates/ui-egui/src/tests/font_menu.rs +++ b/crates/ui-egui/src/tests/font_menu.rs @@ -1031,8 +1031,15 @@ fn open_menu_with(id: &str, left: f32, width: f32, screen: egui::Vec2, look: Men for _ in 0..if tokens.is_some() { 15 } else { 5 } { frame(vec![]); } - crate::font_menu::wait_for_samples(&ctx); - let shapes = frame(vec![]); + // A frame starts only a few samples, and none while several are rendering: draw until a frame + // leaves none rendering, so that frame drew every shown row's sample. + let mut shapes = frame(vec![]); + let mut frames = 0; + while crate::font_menu::wait_for_samples(&ctx) { + frames += 1; + assert!(frames < 1000, "the menu's samples are still rendering after {frames} frames"); + shapes = frame(vec![]); + } let mut texts = vec![]; let mut samples = vec![]; let mut tints = vec![];