Missing Fonts: one compact row per font (#7283)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FypgCZhHKRuRB5wZUiw6BE
This commit is contained in:
Martin Ball
2026-11-23 02:25:33 +00:00
co-authored by Claude Opus 5.5
parent c369c3a20b
commit e0b201102f
2 changed files with 49 additions and 13 deletions
+19 -13
View File
@@ -17,9 +17,11 @@ use craft::ui::choice::Checkbox;
use craft::ui::contract::{Bind, Props as _, Show as _, ShowContainer as _, clicked};
use craft::ui::dialog::{Dialog, DialogId, DialogResult, DialogStack, StackDialog, dialog_id};
use craft::ui::display::{Badge, Icon, Shade, Text};
use craft::ui::layout_components::Row as Line;
use craft::ui::layout::RowAlign;
use craft::ui::layout_components::{Row as Line, Stack};
use craft::ui::primitives::IconSpec;
use craft::ui::sections::{DialogRole, FooterButton, GroupBox};
use craft::ui::sections::{DialogRole, FooterButton};
use craft::ui::style::TypeRole;
use egui::Ui;
use serde::Serialize;
@@ -272,19 +274,23 @@ impl StackDialog for FontBox {
.shade(Shade::Faint)
.show(ui);
for (at, g) in groups(fonts).into_iter().enumerate() {
// The names are the document's own words, not interface text.
GroupBox::new(g.fonts.join(", "), None).id_salt(("download", at)).show(ui, |ui, _| {
let shown_as =
crate::i18n::fmt(tl!("Shown as {fonts} · {publisher}"), &[("fonts", &g.shown_as.join(", ")), ("publisher", g.publisher)]);
Text::new(shown_as).shade(Shade::Faint).show(ui);
if g.restricted {
Text::new(tl!("Its licence limits who may use it: read the terms first.")).shade(Shade::Faint).show(ui);
}
Line::new().show(ui, |ui, _| {
if clicked(&Button::new(tl!("Download")).variant(Variant::PRIMARY).id_salt(("download_button", at)).show(ui)) {
asks.push(Ask::Download(g.url.to_string()));
// One row per download, as before the craft port: the names, what they are shown as and the licence
// note stacked at the start edge, the button at the end. The names are the document's own words.
Line::new().fill_width().align(RowAlign::SpaceBetween).id_salt(("download", at)).show(ui, |ui, _| {
Stack::new().show(ui, |ui, _| {
Text::new(g.fonts.join(", ")).role(TypeRole::BodyStrong).show(ui);
let shown_as = crate::i18n::fmt(
tl!("Shown as {fonts} · {publisher}"),
&[("fonts", &g.shown_as.join(", ")), ("publisher", g.publisher)],
);
Text::new(shown_as).shade(Shade::Faint).show(ui);
if g.restricted {
Text::new(tl!("Its licence limits who may use it: read the terms first.")).shade(Shade::Faint).show(ui);
}
});
if clicked(&Button::new(tl!("Download")).variant(Variant::PRIMARY).id_salt(("download_button", at)).show(ui)) {
asks.push(Ask::Download(g.url.to_string()));
}
});
}
// Whose part the licence is: WordCraft only points at the publisher's page.
+30
View File
@@ -233,3 +233,33 @@ fn only_so_many_documents_are_remembered() {
assert_eq!(a.font_notice_seen.len(), REMEMBERED);
assert_eq!(a.font_notice_seen.last(), Some(&(REMEMBERED as u64 + 49)));
}
/// Each missing font's names, substitute and Download button sit in one compact row, not one under another, and a
/// narrow window keeps them inside the box.
#[test]
fn each_download_is_one_row() {
let row = |font: &str, shown: &str, url: &str| Row {
font: font.into(),
shown_as: vec![shown.into()],
download: font.into(),
publisher: "Microsoft".into(),
url: url.into(),
restricted: false,
};
for width in [1440.0, 520.0] {
let mut a = WordApp::new(Session::new(wordcraft_doc::Document::new()), crate::Services::default());
let fonts = vec![row("Aptos", "Carlito", "https://a"), row("Cascadia Code", "Liberation Mono", "https://c")];
open_with(&mut a, None, FontBox::new(fonts, false), DialogHooks { prepare: None, settle });
let h = harness_sized(a, egui::vec2(width, 900.0));
let buttons: Vec<_> = h.query_all_by_role_and_label(egui::accesskit::Role::Button, "Download").collect();
assert_eq!(buttons.len(), 2);
for (button, shown) in buttons.iter().zip(["Shown as Carlito · Microsoft", "Shown as Liberation Mono · Microsoft"]) {
let shown = h.get_by_label(shown).rect();
let button = button.rect();
// The button is beside the text block, level with it, not under it.
assert!(button.min.x >= shown.max.x, "{width}: {button:?} {shown:?}");
assert!(button.center().y < shown.max.y, "{width}: button under the text: {button:?} {shown:?}");
assert!(button.max.x <= width, "{width}: clipped {button:?}");
}
}
}