From 3c1c1284d860559dc525b96adff149cf96bc8e04 Mon Sep 17 00:00:00 2001 From: aiongg Date: Sun, 22 Nov 2026 17:01:21 +0000 Subject: [PATCH] FontSample: a face not yet ready reserves the room's width Without a ready face the sample measured no width, so an unavailable sample allocated nothing. It reserves the most the ready layout can take, the width it is offered, at LINE_EM of its size: the band the sample will draw in. A ready face lays out as before. --- crates/font-manager/src/panel/specimen.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/crates/font-manager/src/panel/specimen.rs b/crates/font-manager/src/panel/specimen.rs index 6c45f0059..64e4a50a4 100644 --- a/crates/font-manager/src/panel/specimen.rs +++ b/crates/font-manager/src/panel/specimen.rs @@ -61,8 +61,9 @@ impl SampleFace<'_> { /// `DocRun::size`), not a UI size. The label names the sample for a screen reader (the family and the sample text). /// /// Its measure is the sample laid out in the face at `points` on one row, cut with an ellipsis where the room does -/// not fit it (`faces::sample_text`, the layout `paint` draws); without a ready face, no width and [`LINE_EM`] of -/// `points` high. +/// not fit it (`faces::sample_text`, the layout `paint` draws). Without a ready face it reserves the most that layout +/// can take, the room's width, at [`LINE_EM`] of `points` high: the band the sample will draw in, so the face +/// arriving never widens it. #[derive(craft_ui::contract::Component)] #[component(content_painter)] pub(crate) struct FontSample<'a> { @@ -99,7 +100,7 @@ impl Component for FontSample<'_> { fn measure(&mut self, cx: &MeasureCx<'_, Self>) -> Vec2 { let Some(font) = self.face.ready(cx) else { - return Vec2::new(0.0, self.points * LINE_EM); + return Vec2::new(cx.room.unwrap_or(0.0), self.points * LINE_EM); }; let runs = [DocRun::new(self.text.as_ref(), font, self.points, DataColor::new(Color32::PLACEHOLDER))]; cx.layout_doc(&faces::sample_text(&runs, cx.room)).size()