From 03bb7eeede4b7be85874921c43286bd48a2e8b85 Mon Sep 17 00:00:00 2001 From: "Pedro M. de Echanove Pasquin" Date: Wed, 16 Sep 2026 22:12:14 +0200 Subject: [PATCH] button: elide the label against a minimal inset instead of the horizontal padding `draw_text_button` elided the label against the granted width less twice `PAD_H`. That padding is 24 design px resolved through the widget-scaling mode, up to 36 logical px in fluid mode, so on a scale-2 laptop each side took 72 physical px off the label area. A PIN key pinned at 80 logical px kept 16 px for its digit: "1" fitted, "2" onwards did not, and `elide` returned "..." although that did not fit either. loginmanager's keys, at 56 dp, ended with a negative area and drew no digit at all. Icon buttons never went through that cut, which is why backspace and OK still showed. The padding belongs to the preferred size of an auto-width button, whose granted rect already contains it, so it has nothing to protect at draw time. A pinned width, or a row shrunk below its preferred width, may leave less than the padding; the label now keeps only `LABEL_INSET`, 4 design px, off the frame and uses the rest of the rect before eliding. --- src/widget/button/mod.rs | 5 +++-- src/widget/button/theme.rs | 3 +++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/widget/button/mod.rs b/src/widget/button/mod.rs index 10c820d..8ff627f 100644 --- a/src/widget/button/mod.rs +++ b/src/widget/button/mod.rs @@ -415,8 +415,9 @@ impl Button let fs = self.label_font_size( canvas ); let text_y = rect.y + (rect.height + fs) / 2.0 - 2.0; // `rect` is what the layout granted, which is not always the - // preferred width: a row that cannot fit its children shrinks them. - let label = super::elide( canvas, label, fs, rect.width - canvas.geom_px( theme::PAD_H ) * 2.0 ); + // preferred width: a pinned width or a shrunk row may leave less + // than the padding, so only the inset is kept off the label. + let label = super::elide( canvas, label, fs, rect.width - canvas.geom_px( theme::LABEL_INSET ) * 2.0 ); let text_c = self.paint_frame( canvas, rect, focused ); let text_w = canvas.measure_text( &label, fs ); canvas.draw_text( diff --git a/src/widget/button/theme.rs b/src/widget/button/theme.rs index e941697..a0a87b5 100644 --- a/src/widget/button/theme.rs +++ b/src/widget/button/theme.rs @@ -46,3 +46,6 @@ pub const HEIGHT: f32 = 48.0; pub const RADIUS: f32 = 100.0; pub const FONT_SIZE: f32 = 16.0; pub const PAD_H: f32 = 24.0; +/// Smallest gap kept between the label and the frame when the button +/// is narrower than its preferred width (a pinned width, a shrunk row). +pub const LABEL_INSET: f32 = 4.0;