From da38e0da6f28571a15210dc35e39dfd8932d9bec Mon Sep 17 00:00:00 2001 From: Eric Kaden <608341+EricKaden@users.noreply.github.com> Date: Mon, 19 Oct 2026 15:26:37 -0400 Subject: [PATCH] M12: an XFA button without a height is as tall as its caption A button with no height was sized like a text field in its field font, with text-field padding, so DA Form 31's Instructions button (10 pt field font, 8 pt caption) came out about 17 pt tall and over the form below it. It is now as tall as its caption, never below its minimum. --- crates/xfa/src/layout.rs | 12 ++++++++++++ crates/xfa/src/tests.rs | 14 ++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/crates/xfa/src/layout.rs b/crates/xfa/src/layout.rs index f44a23478..72b515137 100644 --- a/crates/xfa/src/layout.rs +++ b/crates/xfa/src/layout.rs @@ -1060,6 +1060,18 @@ impl Layouter<'_> { let lines = if f.multiline { 3.0 } else { 1.0 }; let ui = match f.ui { Ui::CheckButton => f.check_size.unwrap_or(10.0).max(text::line_height(font.size)), + // A button shows its caption: as tall as the caption's text in its own font. + Ui::Button if f.caption.as_ref().is_some_and(|c| !c.value.is_empty()) => { + let cap = f.caption.as_ref().map_or(0.0, |c| { + let rich = match &c.value { + Value::Rich(r) => r.clone(), + other => text::plain(&other.plain().unwrap_or_default()), + }; + let w = (inner_w - f.ui_margin.horizontal()).max(1.0); + text::measure_height(&rich, w, &ctx.para.apply(&c.para), &Face::of(&ctx.font.apply(&c.font)), &|id| self.embed(id)) + }); + cap + f.ui_margin.vertical() + } _ => (text::line_height(font.size) * lines).max(self.grown_text_height(f, inner_w, ctx)) + 4.0 + f.ui_margin.vertical(), }; match self.caption_reserve(f, inner_w, ctx) { diff --git a/crates/xfa/src/tests.rs b/crates/xfa/src/tests.rs index 02bb07dfc..e14917b7e 100644 --- a/crates/xfa/src/tests.rs +++ b/crates/xfa/src/tests.rs @@ -1252,6 +1252,20 @@ fn a_button_without_a_width_is_as_wide_as_its_caption() { assert!((button.rect.w - 200.0).abs() < 0.05, "{}", button.rect.w); } +#[test] +fn a_button_without_a_height_is_as_tall_as_its_caption() { + // A 10pt field font, an 8pt caption: the button is as tall as its caption's line (no + // text-field padding), and never below its minimum height. + let button = |min_h: &str| { + let items = positioned(&format!( + r#"