From da06c8270dc9f2d6858b19acd5bb3fdeca6fb905 Mon Sep 17 00:00:00 2001 From: Martin Ball Date: Wed, 18 Nov 2026 16:25:18 +0000 Subject: [PATCH 1/2] rc-chrome-w6: a multi-line field grows with the lines of its own text up to max_lines (DIAG print in measure) The height came from the codec's width sample, which a plain field leaves empty, so a capped field never grew past its lines. --- crates/ui-widgets/src/text/text_field.rs | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/crates/ui-widgets/src/text/text_field.rs b/crates/ui-widgets/src/text/text_field.rs index fb07382c0..94ea1a261 100644 --- a/crates/ui-widgets/src/text/text_field.rs +++ b/crates/ui-widgets/src/text/text_field.rs @@ -9,7 +9,7 @@ use crate::contract::{ Bind, BindMut, Common, Component, Cx, Edit as _, EditResponse, MeasureCx, OverlayUi, PaintUi, PartsCx, Pointer as _, Props as _, Role, Sizing, Styled as _, WordSetCx as _, }; -use crate::primitives::{Completer, IconSpec, TabKey, TextOptions, TextRun}; +use crate::primitives::{Completer, IconSpec, TabKey, TextOptions, TextRun, Wrap}; use crate::runtime::env::{Label, Message}; use craft_behavior::{Codec, EditEvent, IconId, Mixed, PartKey, PlainText, Proposal, Sense}; use egui::{Id, Rect, Vec2}; @@ -318,11 +318,22 @@ impl Component for TextField<'_, C> { let text = if sample.is_empty() { self.options.placeholder.as_ref().map_or("", Label::as_str) } else { sample.as_ref() }; let mut size = cx.field_text(&TextRun::new(text).role(self.options.role)); // A multi-line field takes the height of its lines, and grows past them with longer text, as the editor does, up - // to `max_lines`; past that its text scrolls inside it (the text part is its scroll owner). + // to `max_lines`; past that its text scrolls inside it (the text part is its scroll owner). The rows are the + // field's own text wrapped as the editor wraps it, not the codec's width sample, which a plain field leaves + // empty. if let Some(lines) = self.options.lines.filter(|_| self.options.multiline()) { let line = cx.layout(&TextRun::new("M").role(self.options.role)).size().y; let height = |lines: usize| cx.style.metrics().min_size.y + line * lines.saturating_sub(1) as f32; - size.y = size.y.max(height(lines)); + let shown = cx.value().map(|value| self.codec.format(value)).unwrap_or_default(); + let tall = cx.layout(&TextRun::new(shown).role(self.options.role).wrap(Wrap::Wrap)).size().y; + let rows = if line > 0.0 { (tall / line).round() as usize } else { 1 }; + size.y = size.y.max(height(lines.max(rows))); + if self.max_lines.is_some() { + eprintln!( + "DIAG a_capped_field_grows_to_its_lines_then_scrolls_with_the_caret_in_view: measure line={line} tall={tall} rows={rows} room={:?} size_y={}", + cx.room, size.y + ); + } if let Some(most) = self.max_lines { size.y = size.y.min(height(most.max(lines))); } From ddfdf22507285a45bdb5f7c32fbea5fb3b23e4af Mon Sep 17 00:00:00 2001 From: Martin Ball Date: Wed, 18 Nov 2026 16:25:21 +0000 Subject: [PATCH 2/2] rc-chrome-w6: the named-length story shows on the registered NumberField card NumberField> has no registration; the story keeps its named-or-length field and files under NumberField<'static> (S-L185). --- crates/ui-widgets/src/text/number/stories.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/crates/ui-widgets/src/text/number/stories.rs b/crates/ui-widgets/src/text/number/stories.rs index 0fcc29d42..95e2c183d 100644 --- a/crates/ui-widgets/src/text/number/stories.rs +++ b/crates/ui-widgets/src/text/number/stories.rs @@ -169,8 +169,10 @@ impl NumberName for LengthName { } } -/// A named-or-length field: "Auto" is a name, and the lengths are stored in points and shown in inches. -#[story(NumberField<'static, NamedOr>, covers = [], drive = Drive::Never)] +/// A named-or-length field: "Auto" is a name, and the lengths are stored in points and shown in inches. It is a story +/// of the registered `NumberField` card: the named instantiation shares its parts, style and value cases, and a +/// registration of its own would need a full set of state stories for one builder. +#[story(NumberField<'static>, covers = [], drive = Drive::Never)] fn number_field_named_length(ui: &mut Ui, data: &mut StoryData) -> StoryOutput { let presets = [Entry::new(NumberPick::Choice(0), "Auto")]; let lengths = LengthUnits::new(UnitKind::Points, UnitKind::Inches, 72.0);