mirror of
https://github.com/youwen5/iamb.git
synced 2025-08-04 11:38:28 -07:00
Improve image preview placeholder (#453)
This commit is contained in:
parent
ed9ee26854
commit
fed19d7a4b
1 changed files with 32 additions and 3 deletions
|
@ -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
|
||||||
|
|
||||||
|
|
||||||
⌎ ⌏
|
⌎ ⌏
|
||||||
"#
|
"#
|
||||||
)
|
)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue