diff --git a/crates/draw/src/ui/connector/bar.rs b/crates/draw/src/ui/connector/bar.rs index 34519c2ed..f2d6511b2 100644 --- a/crates/draw/src/ui/connector/bar.rs +++ b/crates/draw/src/ui/connector/bar.rs @@ -5,10 +5,10 @@ use craft_ui::choice::Segmented; use craft_ui::contract::{Bind, Entry, Outcome, Show as _, ShowContainer as _}; use craft_ui::display::Divider; use craft_ui::layout_components::Row; -use craft_ui::list::ThumbSize; use craft_ui::pickers::Select; +use craft_ui::primitives::ContentPainterCx; use craft_ui::runtime::env::Env; -use egui::{Response, Ui}; +use egui::{Rect, Response, Ui}; use super::words::ConnectorBarWords; use crate::geometry::connector::Routing; @@ -136,10 +136,13 @@ impl<'a> ConnectorBar<'a> { let mut select = Select::new(name.clone(), Bind::given(current), &entries); if let Some(paint) = &row.paint { let choices = row.choices; - select = select.decorate(move |id: &String, list_row| match choices.iter().find(|c| &c.id == id) { - Some(choice) => list_row.thumb(ThumbSize::Small, move |cx, rect| paint.paint(cx, rect, choice)), - None => list_row, - }); + select = select + .picture(move |id: &String, cx: &ContentPainterCx, rect: Rect| { + if let Some(choice) = choices.iter().find(|c| &c.id == id) { + paint.paint(cx, rect, choice); + } + }) + .picture_only(); } if let Some(id) = select.show(ui).value().cloned() { *slot = Some(id); @@ -164,13 +167,15 @@ impl<'a> ConnectorBar<'a> { Mixed::Same(held) => held, Mixed::Mixed => ConnectorLine::default(), }; - let select = Select::new(words.line_style.clone(), Bind::given(current), &entries).decorate(move |pick: &LinePick, list_row| { - let (dashed, weight) = match *pick { - LinePick::Style(dashed) => (dashed, held.weight), - LinePick::Weight(index) => (held.dashed, ConnectorLine::WEIGHTS[index]), - }; - list_row.thumb(ThumbSize::Small, move |cx, rect| StrokePreview::new(&sample(weight, dashed), weight as f32).paint(cx, rect)) - }); + let select = Select::new(words.line_style.clone(), Bind::given(current), &entries) + .picture(move |pick: &LinePick, cx: &ContentPainterCx, rect: Rect| { + let (dashed, weight) = match *pick { + LinePick::Style(dashed) => (dashed, held.weight), + LinePick::Weight(index) => (held.dashed, ConnectorLine::WEIGHTS[index]), + }; + StrokePreview::new(&sample(weight, dashed), weight as f32).paint(cx, rect); + }) + .picture_only(); if let Some(pick) = select.show(ui).value().copied() { line_pick = Some(match pick { LinePick::Style(dashed) => ConnectorLine { dashed, ..held }, diff --git a/crates/draw/src/ui/stroke/editor.rs b/crates/draw/src/ui/stroke/editor.rs index 7e349a005..765dc3ace 100644 --- a/crates/draw/src/ui/stroke/editor.rs +++ b/crates/draw/src/ui/stroke/editor.rs @@ -16,11 +16,11 @@ use craft_ui::form::{Field, FieldGroup}; use craft_ui::layout_components::{Row, Stack}; use craft_ui::list::{List, ListRow, ThumbAspect, ThumbSize}; use craft_ui::pickers::Select; -use craft_ui::primitives::IconSpec; +use craft_ui::primitives::{ContentPainterCx, IconSpec}; use craft_ui::runtime::env::{Env, Label, UnitKind}; use craft_ui::style::{ComponentStyle, StyleCx, SurfaceLook, TypeRole}; use craft_ui::text::NumberField; -use egui::{Response, Ui, Vec2}; +use egui::{Rect, Response, Ui, Vec2}; use std::sync::Arc; use super::{ @@ -383,9 +383,10 @@ impl Body<'_> { Field::new(row.label.clone()).id_salt(("row", row.id.as_str())).show(ui, |ui, _| { let mut select = Select::new(row.label.clone(), Bind::given(current.clone()), &entries); if let Some(painter) = &row.paint { - select = select.decorate(move |id: &String, entry| match row.choices.iter().find(|choice| &choice.id == id) { - Some(choice) => entry.thumb(ThumbSize::Small, move |cx, rect| painter.paint(cx, rect, choice)), - None => entry, + select = select.picture(move |id: &String, cx: &ContentPainterCx, rect: Rect| { + if let Some(choice) = row.choices.iter().find(|choice| &choice.id == id) { + painter.paint(cx, rect, choice); + } }); } picked = select.show(ui).value().cloned(); diff --git a/crates/text/src/ui/tabs_dialog.rs b/crates/text/src/ui/tabs_dialog.rs index 2ed6f6ca4..efbeebf48 100644 --- a/crates/text/src/ui/tabs_dialog.rs +++ b/crates/text/src/ui/tabs_dialog.rs @@ -316,7 +316,11 @@ impl TabStopsDialog { let stops = self.stops.clone(); let unit = self.unit; let aligns: Vec> = TabAlign::ALL.into_iter().map(|align| Entry::new(align, align_text(words, align))).collect(); - let leaders: Vec> = TabLeader::ALL.into_iter().map(|leader| Entry::new(leader, leader_text(words, leader))).collect(); + // The closed box shows the fill alone, as Word's does; the list reads "1 ……". + let leaders: Vec> = TabLeader::ALL + .into_iter() + .map(|leader| Entry::new(leader, leader_text(words, leader)).closed_label(leader_face(words, leader))) + .collect(); let range = -f64::from(MAX_POSITION)..=f64::from(MAX_POSITION); let edits: RefCell> = RefCell::new(Vec::new()); let position_ids: RefCell> = RefCell::new(Vec::new()); @@ -423,6 +427,11 @@ fn align_text(words: &TabStopsWords, align: TabAlign) -> String { .to_owned() } +/// A leader's text in its closed box: "None", or the fill alone. +pub fn leader_face(words: &TabStopsWords, kind: TabLeader) -> String { + if kind == TabLeader::None { words.leader_none.as_str().to_owned() } else { kind.sample().to_owned() } +} + /// A leader option's text as Word's list reads: "None", or the fill after its number. pub fn leader_text(words: &TabStopsWords, kind: TabLeader) -> String { match TabLeader::ALL.iter().position(|other| *other == kind) { diff --git a/crates/ui-contract/src/contract/entry.rs b/crates/ui-contract/src/contract/entry.rs index 5fb570fae..51bae9f28 100644 --- a/crates/ui-contract/src/contract/entry.rs +++ b/crates/ui-contract/src/contract/entry.rs @@ -26,6 +26,7 @@ enum Row { struct Item { value: T, label: Label, + closed: Option