From 7e7707e107148c366feb870d89c1330eea73edda Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Sat, 21 Nov 2026 23:38:35 -0500 Subject: [PATCH] Notice cards are as wide as their text up to the card width --- crates/ui-widgets/src/notices/notice.rs | 6 ++++-- crates/ui-widgets/tests/it/notices.rs | 17 +++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/crates/ui-widgets/src/notices/notice.rs b/crates/ui-widgets/src/notices/notice.rs index ae2f34037..4bcbaa47e 100644 --- a/crates/ui-widgets/src/notices/notice.rs +++ b/crates/ui-widgets/src/notices/notice.rs @@ -587,10 +587,12 @@ impl Component for Notice<'_> { let texts = self.texts(&cx.env, &cx.words::(), cx.format(), cx.resolved.label); let natural = self.plan(cx, &texts, f32::INFINITY).needs; let width = match (self.layout, cx.room) { - // The card is the card width wide, its padding included, where the room allows. + // The card is as wide as its text, up to the card width (padding included) where the room allows. A card + // that hosts content (a progress bar) has no text width of its own and takes the card width. (NoticeLayout::Card, room) => { let padding = cx.style.metrics.padding; - let width = cx.style.card_width - padding.start - padding.end; + let cap = cx.style.card_width - padding.start - padding.end; + let width = if self.content_sizes.is_empty() { natural.min(cap) } else { cap }; room.map_or(width, |room| width.min(room)) } (NoticeLayout::Centred, None) => natural.min(cx.style.reading_width), diff --git a/crates/ui-widgets/tests/it/notices.rs b/crates/ui-widgets/tests/it/notices.rs index 1ae69779a..9e1b6e03e 100644 --- a/crates/ui-widgets/tests/it/notices.rs +++ b/crates/ui-widgets/tests/it/notices.rs @@ -167,3 +167,20 @@ fn a_wide_notice_wraps_its_message_beside_its_actions() { assert!(text.top() >= action.top(), "the message begins within the action line: {text:?}, {action:?}"); assert!(text.top() < action.bottom() && action.top() < text.bottom(), "the actions share the message's first line"); } + +/// A card with a short message is as wide as its text, not the card width; a long one wraps at the card width. +#[trial] +fn a_card_is_as_wide_as_its_text_up_to_the_card_width() { + let width = |message: String| { + let seen = Rc::new(Cell::new(0.0_f32)); + let out = seen.clone(); + let mut fixture = Fixture::new(move |ui| { + out.set(Notice::new(Tone::Neutral, message.clone()).layout(NoticeLayout::Card).show(ui).response.rect.width()); + }); + fixture.settle(); + seen.get() + }; + let (short, long) = (width("No recent files".to_owned()), width("Couldn't read the file. ".repeat(20))); + assert!(short < long, "a short card is narrower than a long one: {short} vs {long}"); + assert!(long < 400.0, "a long card wraps at the card width: {long}"); +}