From 4b4abd000e79fd2ab733db043466fde8dffb01f3 Mon Sep 17 00:00:00 2001 From: Martin Ball Date: Thu, 19 Nov 2026 19:53:56 +0000 Subject: [PATCH 1/2] look-7b: a text field and a text form row can ask for a width in characters (TextField::width_chars, Param::field_chars: n times the body face's '0', as CSS's ch, plus the field padding) over the field length; a row that lacks room still narrows it; gallery stories and trials --- .../src/patterns/form_dialogs/param.rs | 17 +++++++++++ .../src/patterns/form_dialogs/rows.rs | 3 ++ .../src/patterns/form_dialogs/rows/stories.rs | 3 +- .../tests/it/form_dialogs/params.rs | 17 +++++++++++ crates/ui-widgets/src/text/mod.rs | 8 ++++++ crates/ui-widgets/src/text/text_field.rs | 21 +++++++++++++- .../ui-widgets/src/text/text_field/stories.rs | 15 ++++++++++ crates/ui-widgets/tests/it/text/widths.rs | 28 +++++++++++++++++++ 8 files changed, 110 insertions(+), 2 deletions(-) diff --git a/crates/ui-patterns/src/patterns/form_dialogs/param.rs b/crates/ui-patterns/src/patterns/form_dialogs/param.rs index 33288fbb2..05a72184f 100644 --- a/crates/ui-patterns/src/patterns/form_dialogs/param.rs +++ b/crates/ui-patterns/src/patterns/form_dialogs/param.rs @@ -476,6 +476,8 @@ pub(crate) struct RowOptions { max_chars: Option, /// Whether a text row shows its text in the monospace face ([`Param::mono`]). mono: bool, + /// The width a text row's field asks for, in characters ([`Param::field_chars`]). + field_chars: Option, units: Option, /// The ids of the options a choice row shows disabled. disabled_options: Vec, @@ -782,6 +784,16 @@ impl Param { self } + /// The width of a [`ParamKind::Text`] row's field, in characters (`TextField::width_chars`): the field asks for + /// `chars` times the width of a `0` in its face instead of the field length, so one row of a form can be wider or + /// narrower than the others (a watermark's text against a short name). A row that lacks room still narrows it. + /// `0` keeps the field length; other kinds, and a text row with a Browse button, are unchanged. + #[must_use] + pub fn field_chars(mut self, chars: u16) -> Self { + self.options.get_or_insert_default().field_chars = (chars > 0).then_some(chars); + self + } + /// Hover text for the whole row, label and control, of any kind. #[must_use] pub fn tooltip(mut self, text: impl Into