Completion list: the mark and the candidate in the Mono role, through ListRow's lead_role and role

This commit is contained in:
aiongg
2026-11-12 14:32:44 +00:00
parent f6a5328ecf
commit 912aa16df2
4 changed files with 10 additions and 6 deletions
+5 -1
View File
@@ -201,6 +201,9 @@ pub struct ListRow<'a> {
pub(super) lead_paint: Option<LeadPaintFn<'a>>,
/// 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<ThumbPaint<'a>>,
@@ -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.
+3 -3
View File
@@ -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 }
}
+1 -1
View File
@@ -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);
+1 -1
View File
@@ -63,7 +63,7 @@ pub(crate) fn show<C: Component, V: 'static>(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()),