PdfCraft: An open-source PDF reader and editor written by scratch in pure Rust
Sign: long digital ID names stay inside the picker (#743)
mmmaarian03-cryptof8c463416a37
diff --git a/crates/ui-egui/src/sign_ui.rs b/crates/ui-egui/src/sign_ui.rsindex 36b7fc873..77f588f53 100644--- a/crates/ui-egui/src/sign_ui.rs+++ b/crates/ui-egui/src/sign_ui.rs@@ -478,7 +478,14 @@ fn choose(ui: &mut egui::Ui, app: &mut PdfCraftApp, t: &Tokens) -> bool {};ui.painter().rect_filled(rect, CornerRadius::same(6), fill);icons::paint(ui, Rect::from_min_size(rect.min + vec2(10.0, 15.0), vec2(20.0, 20.0)), "badge-check", 18.0, t.accent);- ui.painter().text(rect.min + vec2(40.0, 9.0), egui::Align2::LEFT_TOP, &e.name, theme::semibold(13.0), t.text);+ // Certificate names can be any length: cut both lines with "…" at the row's edge+ // and show them whole on hover.+ let line = |text: &str, font: egui::FontId, color: Color32| {+ let mut job = egui::text::LayoutJob::simple_singleline(text.to_owned(), font, color);+ job.wrap = egui::text::TextWrapping::truncate_at_width((rect.width() - 50.0).max(0.0));+ ui.painter().layout_job(job)+ };+ let name = line(&e.name, theme::semibold(13.0), t.text);let sub = format!("{keychain}{email}{issued}{issuer}{expires}{date}",keychain = if e.path.starts_with("keychain:") {@@ -494,7 +501,11 @@ fn choose(ui: &mut egui::Ui, app: &mut PdfCraftApp, t: &Tokens) -> bool {expires = tl!(", Expires: "),date = e.expires,);- ui.painter().text(rect.min + vec2(40.0, 28.0), egui::Align2::LEFT_TOP, sub, theme::regular(11.5), t.text_muted);+ let details = line(&sub, theme::regular(11.5), t.text_muted);+ let elided = name.elided || details.elided;+ ui.painter().galley(rect.min + vec2(40.0, 9.0), name, t.text);+ ui.painter().galley(rect.min + vec2(40.0, 28.0), details, t.text_muted);+ let resp = if elided { resp.on_hover_text(format!("{}\n{sub}", e.name)) } else { resp };if resp.clicked() {d.selected = Some(i);}diff --git a/crates/ui-egui/tests/signing.rs b/crates/ui-egui/tests/signing.rsindex a777517e6..09c3246ed 100644--- a/crates/ui-egui/tests/signing.rs+++ b/crates/ui-egui/tests/signing.rs@@ -297,3 +297,40 @@ fn windows_store_identity_does_not_ask_for_a_file_password() {assert_eq!(h.state().dialog, Some(Dialog::Sign));assert!(h.state().sign_draft.as_ref().unwrap().error.as_ref().unwrap().contains("Windows certificate store"));}++/// Certificate names are as long as their owners made them: the picker cuts both lines of a+/// row with "…" instead of painting them past the dialog's edge.+#[test]+fn long_digital_id_names_stay_inside_the_picker() {+ let mut h = harness(dir());+ h.state_mut().start_signing(0, None, None, None);+ let long = "a certificate subject much longer than the picker is wide ".repeat(4);+ h.state_mut().digital_ids.push(pdfcraft_ui_egui::DigitalIdEntry {+ path: "windows:No Such Signer".into(),+ name: long.clone(),+ issuer: long,+ email: String::new(),+ expires: "2030.01.01".into(),+ });+ h.state_mut().sign_draft.as_mut().unwrap().step = SignStep::Choose;+ h.run_steps(3);+ let right = h.get_by_label("Continue").rect().right();+ let lines: Vec<_> = h+ .output()+ .shapes+ .iter()+ .filter_map(|s| match &s.shape {+ egui::Shape::Text(t) if t.galley.job.text.contains("much longer") => Some(t),+ _ => None,+ })+ .collect();+ assert_eq!(lines.len(), 2, "the name and the details line");+ for line in lines {+ assert!(line.galley.elided, "{}", line.galley.job.text);+ assert!(+ line.pos.x + line.galley.size().x <= right,+ "the line ends at {} but the dialog's buttons end at {right}",+ line.pos.x + line.galley.size().x+ );+ }+}