Improve image preview placeholder (#453)

This commit is contained in:
VAWVAW 2025-06-21 18:25:46 +00:00 committed by GitHub
parent ed9ee26854
commit fed19d7a4b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -176,7 +176,9 @@ fn placeholder_frame(
} }
let mut placeholder = "\u{230c}".to_string(); let mut placeholder = "\u{230c}".to_string();
placeholder.push_str(&" ".repeat(width - 2)); placeholder.push_str(&" ".repeat(width - 2));
placeholder.push_str("\u{230d}\n"); placeholder.push('\u{230d}');
placeholder.push_str(&"\n".repeat((height - 1) / 2));
if *height > 2 { if *height > 2 {
if let Some(text) = text { if let Some(text) = text {
if text.width() <= width - 2 { if text.width() <= width - 2 {
@ -186,7 +188,7 @@ fn placeholder_frame(
} }
} }
placeholder.push_str(&"\n".repeat(height - 2)); placeholder.push_str(&"\n".repeat(height / 2));
placeholder.push('\u{230e}'); placeholder.push('\u{230e}');
placeholder.push_str(&" ".repeat(width - 2)); placeholder.push_str(&" ".repeat(width - 2));
placeholder.push_str("\u{230f}\n"); placeholder.push_str("\u{230f}\n");
@ -1087,7 +1089,7 @@ impl Message {
}, },
ImageStatus::Loaded(backend) => { ImageStatus::Loaded(backend) => {
proto = Some(backend); proto = Some(backend);
placeholder_frame(Some("Loading..."), width, &backend.area().into()) placeholder_frame(Some("Cut off..."), width, &backend.area().into())
}, },
ImageStatus::Error(err) => Some(format!("[Image error: {err}]\n")), ImageStatus::Error(err) => Some(format!("[Image error: {err}]\n")),
}; };
@ -1357,6 +1359,33 @@ pub mod tests {
OK OK
"#
)
);
assert_eq!(
placeholder_frame(Some("OK"), 6, &ImagePreviewSize { width: 6, height: 6 }),
pretty_frame_test(
r#"
OK
"#
)
);
assert_eq!(
placeholder_frame(Some("OK"), 6, &ImagePreviewSize { width: 6, height: 7 }),
pretty_frame_test(
r#"
OK
"# "#
) )