From 76758ecfddc527b5d53cc308f0518a8d4c2b28f8 Mon Sep 17 00:00:00 2001 From: aiongg Date: Tue, 17 Nov 2026 15:00:38 +0000 Subject: [PATCH] Wrap::Clip: one line cut at the room's edge without an ellipsis; panel tab labels use it --- crates/ui-contract/src/primitives/text.rs | 9 +++++++-- crates/ui-widgets/src/tabs/tab.rs | 8 ++------ 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/crates/ui-contract/src/primitives/text.rs b/crates/ui-contract/src/primitives/text.rs index a4d18bf78..8257570d5 100644 --- a/crates/ui-contract/src/primitives/text.rs +++ b/crates/ui-contract/src/primitives/text.rs @@ -21,6 +21,9 @@ pub enum Wrap { Line, /// Wraps at the room's width. Wrap, + /// One line, cut at the room's edge with no ellipsis, as many characters as fit: tabs that shrink to their first + /// letters. The full text is the tooltip and accessible name, as for an elided run. + Clip, /// One line, cut with an ellipsis at the end: names, titles, labels beside fixed controls. Elide, /// One line, cut with an ellipsis at the start: anything whose end says the most. @@ -267,14 +270,16 @@ impl TextRun<'_> { fn job<'s>(&self, env: &TextEnv<'_>, parts: impl Iterator, &'s str)>, max_width: f32) -> LayoutJob { let elide = self.wrap.cuts(); + let clip = self.wrap == Wrap::Clip; let wrap = TextWrapping { max_width: if self.wrap == Wrap::Line { f32::INFINITY } else { max_width }, max_rows: match self.wrap { Wrap::Clamp(lines) => usize::from(lines.max(1)), - _ if elide => 1, + _ if elide || clip => 1, _ => usize::MAX, }, - break_anywhere: elide, + break_anywhere: elide || clip, + overflow_character: if clip { None } else { TextWrapping::default().overflow_character }, ..TextWrapping::default() }; let mut job = paragraph_job(env.direction, self.ltr, wrap); diff --git a/crates/ui-widgets/src/tabs/tab.rs b/crates/ui-widgets/src/tabs/tab.rs index 12a9ef292..2909a2577 100644 --- a/crates/ui-widgets/src/tabs/tab.rs +++ b/crates/ui-widgets/src/tabs/tab.rs @@ -13,7 +13,7 @@ use crate::contract::{ Styled as _, WordSetCx as _, }; use crate::display::Progress; -use crate::primitives::{IconSpec, PaintShape, RectSide, StrokeWidth, TextRun}; +use crate::primitives::{IconSpec, PaintShape, RectSide, StrokeWidth, TextRun, Wrap}; use crate::runtime::env::Label; use crate::style::{ComponentStyle, Flags, IconLook, RuleKind, StyleColor, StyleCx, SurfaceLook, TextLook}; use craft_behavior::{Flow, IconId, Insets, Metrics, PartKey, PointerButton, PressPhase, Proposal, Sense}; @@ -418,11 +418,7 @@ impl Component for Tab<'_> { draw.stroke(&line, StrokeWidth::Thick, style.underline); } let label = self.label_run(style, cx.resolved.label).color(cx.resolve(&style.label.color)); - if self.kind.clips_label() { - draw.clipped(placed.label, |draw| draw.text(placed.label, &label)); - } else { - draw.text(placed.label, &label.elide()); - } + draw.text(placed.label, &if self.kind.clips_label() { label.wrap(Wrap::Clip) } else { label.elide() }); if let (Some(at), Some(detail)) = (placed.detail, self.detail_text()) { draw.text(at, &TextRun::new(detail).role(style.detail.role).color(cx.resolve(&style.detail.color)).elide()); }