From 539e6574a872ae8207e49628138245252a14bd79 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Thu, 14 Sep 2023 13:44:24 +0200 Subject: [PATCH] Slightly better error message on image load failure --- crates/egui/src/widgets/image.rs | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/crates/egui/src/widgets/image.rs b/crates/egui/src/widgets/image.rs index 163e264e492..576c21c9c15 100644 --- a/crates/egui/src/widgets/image.rs +++ b/crates/egui/src/widgets/image.rs @@ -311,13 +311,17 @@ impl<'a> Widget for Image<'a> { if show_spinner { Spinner::new().paint_at(ui, response.rect); } - response.on_hover_text(format!("Loading {:?}…", self.uri())) + + let uri = self.source.uri().unwrap_or("image"); + response.on_hover_text(format!("Loading {uri}…")) } } } - Err(err) => ui - .colored_label(ui.visuals().error_fg_color, "⚠") - .on_hover_text(err.to_string()), + Err(err) => { + let uri = self.source.uri().unwrap_or("image"); + ui.colored_label(ui.visuals().error_fg_color, "⚠") + .on_hover_text(format!("Failed loading {uri}: {err}")) + } } } } @@ -547,13 +551,13 @@ pub fn texture_load_result_response( match tlr { Ok(TexturePoll::Ready { .. }) => response, Ok(TexturePoll::Pending { .. }) => { - if let Some(uri) = source.uri() { - response.on_hover_text(format!("Loading {uri}…")) - } else { - response.on_hover_text("Loading image…") - } + let uri = source.uri().unwrap_or("image"); + response.on_hover_text(format!("Loading {uri}…")) + } + Err(err) => { + let uri = source.uri().unwrap_or("image"); + response.on_hover_text(format!("Failed loading {uri}: {err}")) } - Err(err) => response.on_hover_text(err.to_string()), } }