From 912aa16df2c14a5016db46544e2aad7107062329 Mon Sep 17 00:00:00 2001 From: aiongg Date: Thu, 12 Nov 2026 01:32:34 +0000 Subject: [PATCH] Completion list: the mark and the candidate in the Mono role, through ListRow's lead_role and role --- crates/ui-widgets/src/list/row.rs | 6 +++++- crates/ui-widgets/src/list/row/placement.rs | 6 +++--- crates/ui-widgets/src/list/row/show.rs | 2 +- crates/ui-widgets/src/text/completions.rs | 2 +- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/crates/ui-widgets/src/list/row.rs b/crates/ui-widgets/src/list/row.rs index 9d79d5063..35ecf5938 100644 --- a/crates/ui-widgets/src/list/row.rs +++ b/crates/ui-widgets/src/list/row.rs @@ -201,6 +201,9 @@ pub struct ListRow<'a> { pub(super) lead_paint: Option>, /// The leading text and the widest text its slot is sized for (`lead_text`). pub(super) lead_text: Option<(Label, Label)>, + /// The type role of the leading text: `Caption` unless set. + #[prop] + pub(super) lead_role: TypeRole, pub(super) thumb: ThumbSize, pub(super) thumb_aspect: ThumbAspect, pub(super) first: Option>, @@ -273,6 +276,7 @@ impl<'a> ListRow<'a> { icon: None, lead_paint: None, lead_text: None, + lead_role: TypeRole::Caption, thumb: ThumbSize::None, thumb_aspect: ThumbAspect::SQUARE, first: None, @@ -504,7 +508,7 @@ impl<'a> ListRow<'a> { self } - /// A short text in the leading slot (a page number), in the detail's role and ink, at the slot's end so the labels + /// A short text in the leading slot (a page number), in `lead_role` and the detail's ink, at the slot's end so the labels /// after it line up: the slot is as wide as `widest` measures. It takes the icon's place; thumbnails replace it. /// A click on it picks the row as a click on the row does and reports [`RowEvent::LeadClicked`]; a double click /// there does not activate the row. diff --git a/crates/ui-widgets/src/list/row/placement.rs b/crates/ui-widgets/src/list/row/placement.rs index 32ddf5b51..3ad2dbd0f 100644 --- a/crates/ui-widgets/src/list/row/placement.rs +++ b/crates/ui-widgets/src/list/row/placement.rs @@ -119,8 +119,8 @@ pub(super) struct Widths { } /// The run of a leading text, without its colour. -pub(super) fn lead_run(text: &Label) -> TextRun<'_> { - TextRun::new(text.as_str()).role(TypeRole::Caption) +pub(super) fn lead_run(text: &Label, role: TypeRole) -> TextRun<'_> { + TextRun::new(text.as_str()).role(role) } /// The cells of a row that lead and trail its label band. @@ -264,7 +264,7 @@ impl ListRow<'_> { ItemWidth { width, least: least(&trailing.item, width), optional: trailing.optional } }) .collect(); - let lead = self.lead_text.as_ref().map(|(_, widest)| text_width(&lead_run(widest))); + let lead = self.lead_text.as_ref().map(|(_, widest)| text_width(&lead_run(widest, self.lead_role))); Widths { items, lead } } diff --git a/crates/ui-widgets/src/list/row/show.rs b/crates/ui-widgets/src/list/row/show.rs index a4d8a6c5a..9bb77f6c8 100644 --- a/crates/ui-widgets/src/list/row/show.rs +++ b/crates/ui-widgets/src/list/row/show.rs @@ -458,7 +458,7 @@ impl Component for ListRow<'_> { let ink = cx.resolve(&style.text.color); if let (Some(slot), Some((text, _))) = (placed.icon, &self.lead_text) { let draw = ui.draw(); - let run = lead_run(text).color(cx.resolve(&style.detail.color)); + let run = lead_run(text, self.lead_role).color(cx.resolve(&style.detail.color)); let shown = draw.layout(&run, slot.width()); let x = if rtl { slot.left() } else { slot.right() - shown.size().x }; draw.galley(Pos2::new(x, slot.center().y - shown.size().y / 2.0), &shown); diff --git a/crates/ui-widgets/src/text/completions.rs b/crates/ui-widgets/src/text/completions.rs index a60bc3e29..79095b70d 100644 --- a/crates/ui-widgets/src/text/completions.rs +++ b/crates/ui-widgets/src/text/completions.rs @@ -63,7 +63,7 @@ pub(crate) fn show(ui: &mut OverlayUi<'_>, cx: &mut Cx let overlay = Overlay::dropdown().focus(focus); let events = ui.show(popup, overlay, |ui, _| { let list = List::options(name.clone()).rows_stamp(stamp).show_items(ui, &Candidates { labels: &labels }, &mut |at, _| { - let row = ListRow::new(labels[*at].clone()).option(); + let row = ListRow::new(labels[*at].clone()).option().role(TypeRole::Mono).lead_role(TypeRole::Mono); match (&marks[*at], &widest) { (Some(mark), Some(widest)) => row.lead_text(mark.clone(), widest.clone()), (None, Some(widest)) => row.lead_text(Label::Empty, widest.clone()),