From b000357c8f0adee7783ad43caaa28034d5f51457 Mon Sep 17 00:00:00 2001 From: Martin Ball Date: Sat, 21 Nov 2026 10:26:04 +0000 Subject: [PATCH] #7149 item 8: review fixes: text glyphs at the remaining call sites, grey when disabled Home (group icons, grow/shrink, clear/phonetic, enclose, sort, Show/Hide pilcrow, Paragraph Tools), the mini toolbar, Developer controls and the Draw font colour use icons::spec so they draw the text glyph. A disabled glyph paints both inks in text.disabled, as production did. The icon-name scan fails on a glyph name passed through IconId::new or icons::id. Doc link and ATTRIBUTION.md order fixed. Co-Authored-By: Claude Opus 5.5 --- ATTRIBUTION.md | 2 +- crates/ui-egui/src/icons.rs | 8 +++- crates/ui-egui/src/icons/glyphs.rs | 64 ++++++++++++++++++++++++++++- crates/ui-egui/src/mini_toolbar.rs | 2 +- crates/ui-egui/src/ribbon/draw.rs | 2 +- crates/ui-egui/src/ribbon/home.rs | 14 +++---- crates/ui-egui/src/ribbon/review.rs | 2 +- 7 files changed, 80 insertions(+), 14 deletions(-) diff --git a/ATTRIBUTION.md b/ATTRIBUTION.md index f3f5588283..611c6961f1 100644 --- a/ATTRIBUTION.md +++ b/ATTRIBUTION.md @@ -352,8 +352,8 @@ The UI icons are SVG files in `crates/ui-egui/icons/`, one row each below. Gener | `crates/ui-egui/icons/table.svg` | WordCraft contributors | original: exported from WordCraft's own code-drawn icons (`crates/ui-egui/src/icons.rs` before the craft port), text glyphs redrawn as paths | MIT OR Apache-2.0 | UI icon | | `crates/ui-egui/icons/tableOfAuthorities.svg` | WordCraft contributors | original: exported from WordCraft's own code-drawn icons (`crates/ui-egui/src/icons.rs` before the craft port), text glyphs redrawn as paths | MIT OR Apache-2.0 | UI icon | | `crates/ui-egui/icons/tableOfFigures.svg` | WordCraft contributors | original: exported from WordCraft's own code-drawn icons (`crates/ui-egui/src/icons.rs` before the craft port), text glyphs redrawn as paths | MIT OR Apache-2.0 | UI icon | -| `crates/ui-egui/icons/tableStyles.svg` | WordCraft contributors | original: drawn for WordCraft in the style of the code-drawn icon set (#7149) | MIT OR Apache-2.0 | UI icon | | `crates/ui-egui/icons/tableStyleOptions.svg` | WordCraft contributors | original: drawn for WordCraft in the style of the code-drawn icon set (#7149) | MIT OR Apache-2.0 | UI icon | +| `crates/ui-egui/icons/tableStyles.svg` | WordCraft contributors | original: drawn for WordCraft in the style of the code-drawn icon set (#7149) | MIT OR Apache-2.0 | UI icon | | `crates/ui-egui/icons/textBox.svg` | WordCraft contributors | original: exported from WordCraft's own code-drawn icons (`crates/ui-egui/src/icons.rs` before the craft port), text glyphs redrawn as paths | MIT OR Apache-2.0 | UI icon | | `crates/ui-egui/icons/textBoxLink.svg` | WordCraft contributors | original: exported from WordCraft's own code-drawn icons (`crates/ui-egui/src/icons.rs` before the craft port), text glyphs redrawn as paths | MIT OR Apache-2.0 | UI icon | | `crates/ui-egui/icons/textBoxUnlink.svg` | WordCraft contributors | original: exported from WordCraft's own code-drawn icons (`crates/ui-egui/src/icons.rs` before the craft port), text glyphs redrawn as paths | MIT OR Apache-2.0 | UI icon | diff --git a/crates/ui-egui/src/icons.rs b/crates/ui-egui/src/icons.rs index b4d041e1ef..a6e9190951 100644 --- a/crates/ui-egui/src/icons.rs +++ b/crates/ui-egui/src/icons.rs @@ -552,13 +552,18 @@ mod tests { register(); let mut files = Vec::new(); rs_files(&std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("src"), &mut files); - let (mut seen, mut missing) = (0, Vec::new()); + let (mut seen, mut missing, mut svg_only) = (0, Vec::new(), Vec::new()); for file in files.iter().filter(|f| !f.ends_with("icons.rs")) { let text = std::fs::read_to_string(file).unwrap_or_default(); for call in ["IconId::new(\"", "icons::id(\"", "icons::spec(\""] { for part in text.split(call).skip(1) { let Some(name) = part.split('"').next() else { continue }; seen += 1; + // A text glyph resolves only through `icons::spec`; the SVG-only calls draw its SVG instead. + if call != "icons::spec(\"" && glyphs::ICONS.iter().any(|g| g.0 == name) { + svg_only.push(format!("{name} ({}): use icons::spec", file.display())); + continue; + } let known = match call { "IconId::new(\"" => craft::ui::primitives::has_icon(&IconId::from(Cow::Owned(name.to_owned()))), _ => { @@ -577,5 +582,6 @@ mod tests { } assert!(seen > 200, "the scan found only {seen} names"); assert!(missing.is_empty(), "icons used but not in the app set or the catalog: {missing:?}"); + assert!(svg_only.is_empty(), "text glyphs passed through the SVG-only IconId::new / icons::id: {svg_only:?}"); } } diff --git a/crates/ui-egui/src/icons/glyphs.rs b/crates/ui-egui/src/icons/glyphs.rs index c21c8304b8..39564890bc 100644 --- a/crates/ui-egui/src/icons/glyphs.rs +++ b/crates/ui-egui/src/icons/glyphs.rs @@ -83,7 +83,11 @@ pub(super) struct TextIcon(pub(super) &'static str); impl Glyph for TextIcon { fn paint(&self, painter: &Painter, tokens: &UiTokens, rect: Rect, color: Color32, _mirrored: bool) { - let pen = Pen { p: painter, r: rect, c: color, a: rgba_color(tokens.color.accent.solid), w: 1.25 }; + // The framework passes `text.disabled` as `color` to a disabled button, and a glyph has no other way + // to learn that; then both inks go grey (the accent ink would stay bright on a disabled button). + let disabled = color == rgba_color(tokens.color.text.disabled); + let accent = if disabled { color } else { rgba_color(tokens.color.accent.solid) }; + let pen = Pen { p: painter, r: rect, c: color, a: accent, w: 1.25 }; paint(&pen, self.0); } } @@ -149,7 +153,7 @@ impl Pen<'_> { } } -/// Draws `name`; false when it is not one of [`NAMES`]. +/// Draws `name`; false when it is not one of [`ICONS`]. fn paint(pen: &Pen, name: &str) -> bool { let (c, a) = (pen.c, pen.a); let red = Color32::from_rgb(0xD1, 0x3B, 0x3B); @@ -408,4 +412,60 @@ mod tests { out.textures_delta.clear(); assert_eq!(ICONS.len(), 65); } + + /// Every colour the shapes of `shape` paint with. + fn ink_of(shape: &Shape, out: &mut Vec) { + match shape { + Shape::Vec(v) => v.iter().for_each(|s| ink_of(s, out)), + Shape::LineSegment { stroke, .. } => out.push(stroke.color), + Shape::Path(p) => { + out.push(p.fill); + if let egui::epaint::ColorMode::Solid(c) = p.stroke.color { + out.push(c); + } + } + Shape::Circle(c) => out.extend([c.stroke.color, c.fill]), + Shape::Rect(r) => out.extend([r.stroke.color, r.fill]), + Shape::Text(t) => { + out.push(t.fallback_color); + out.extend(t.galley.job.sections.iter().map(|s| s.format.color)); + } + _ => {} + } + } + + /// A disabled button hands its glyph `text.disabled` as the colour: no shape may then be in the accent + /// colour (production painted both inks grey). Enabled, the glyphs do use the accent. + #[test] + fn a_disabled_text_glyph_paints_no_accent_colour() { + use craft::theme::{Appearance, Contrast, Mode, Size, TextSize}; + let themes = craft::theme::builtins(); + let theme = themes.iter().find(|theme| theme.id.as_str() == craft::theme::SUITE_DEFAULT).unwrap(); + let appearance = Appearance { + mode: Mode::Light, + contrast: Contrast::Standard, + size: Size::Compact, + text_size: TextSize::default(), + reduced_motion: false, + }; + let tokens = UiTokens::new(std::sync::Arc::new(craft::theme::resolve(theme, appearance, None).tokens), Contrast::Standard, Size::Compact); + let (accent, disabled, normal) = + (rgba_color(tokens.color.accent.solid), rgba_color(tokens.color.text.disabled), rgba_color(tokens.color.text.normal)); + assert_ne!(accent, disabled); + let inks = |color: Color32| { + let mut out = Vec::new(); + let ctx = egui::Context::default(); + let mut run = ctx.run_ui(egui::RawInput::default(), |ui| { + let painter = ui.painter().clone(); + for icon in ICONS { + icon.paint(&painter, &tokens, Rect::from_min_size(pos2(0.0, 0.0), vec2(20.0, 20.0)), color, false); + } + }); + run.textures_delta.clear(); + run.shapes.iter().for_each(|clipped| ink_of(&clipped.shape, &mut out)); + out + }; + assert!(inks(normal).contains(&accent), "an enabled glyph uses the accent ink"); + assert!(!inks(disabled).contains(&accent), "a disabled glyph painted in the accent colour"); + } } diff --git a/crates/ui-egui/src/mini_toolbar.rs b/crates/ui-egui/src/mini_toolbar.rs index de2571ed84..6d0786cd4e 100644 --- a/crates/ui-egui/src/mini_toolbar.rs +++ b/crates/ui-egui/src/mini_toolbar.rs @@ -173,7 +173,7 @@ pub(crate) fn members(app: &mut WordApp, ui: &mut Ui, preview: bool) { } for (id, icon) in [("format.growFont", "grow"), ("format.shrinkFont", "shrink")] { - let b = IconButton::command(crate::icons::id(icon), CommandRef::new(id)).show(ui); + let b = IconButton::command(crate::icons::spec(icon), CommandRef::new(id)).show(ui); preview_on_hover(app, b.hover, b.response.enabled(), id, json!({}), preview); } }); diff --git a/crates/ui-egui/src/ribbon/draw.rs b/crates/ui-egui/src/ribbon/draw.rs index 35295ff1e9..ddaee321bb 100644 --- a/crates/ui-egui/src/ribbon/draw.rs +++ b/crates/ui-egui/src/ribbon/draw.rs @@ -75,7 +75,7 @@ pub(super) fn draw(row: &mut RibbonRow<'_>, app: &mut WordApp) { })), ) .label(crate::tl!("Color")) - .icon(IconSpec::from(IconId::new("fontcolor")).with_mark(IconMark::bar(DataColor::new(ink)))) + .icon(crate::icons::spec("fontcolor").with_mark(IconMark::bar(DataColor::new(ink)))) .show(ui); menu_button( ui, diff --git a/crates/ui-egui/src/ribbon/home.rs b/crates/ui-egui/src/ribbon/home.rs index 924b6c927c..83c5248d8e 100644 --- a/crates/ui-egui/src/ribbon/home.rs +++ b/crates/ui-egui/src/ribbon/home.rs @@ -24,7 +24,7 @@ use crate::colors::{Remember, Target}; /// A ribbon group titled `title`, with the Dialog Launcher `launcher` when it has one. fn ribbon_group(key: &'static str, title: &str, icon: &'static str, launcher: Option<&str>) -> RibbonGroup<'static> { - let group = RibbonGroup::new(key, tl!(title).to_string(), crate::icons::id(icon).into()); + let group = RibbonGroup::new(key, tl!(title).to_string(), crate::icons::spec(icon)); match launcher { Some(id) => group.launcher(CommandRef::new(id)), None => group, @@ -193,7 +193,7 @@ pub(super) fn home(row: &mut RibbonRow<'_>, app: &mut WordApp) { let _ = app.run("format.size", json!({"size": x})); } for (icon, tip, id) in [("grow", "Increase Font Size", "format.growFont"), ("shrink", "Decrease Font Size", "format.shrinkFont")] { - IconButton::command(crate::icons::id(icon), CommandRef::new(id)) + IconButton::command(crate::icons::spec(icon), CommandRef::new(id)) .label(tl!(tip).to_string()) .tooltip(tl!(tip).to_string()) .show(ui); @@ -211,7 +211,7 @@ pub(super) fn home(row: &mut RibbonRow<'_>, app: &mut WordApp) { } }); for (icon, tip, id) in [("clear", "Clear All Formatting", "format.clear"), ("phonetic", "Phonetic Guide", "format.phonetic")] { - IconButton::command(crate::icons::id(icon), CommandRef::new(id)) + IconButton::command(crate::icons::spec(icon), CommandRef::new(id)) .label(tl!(tip).to_string()) .tooltip(tl!(tip).to_string()) .show(ui); @@ -247,7 +247,7 @@ pub(super) fn home(row: &mut RibbonRow<'_>, app: &mut WordApp) { .tooltip(tl!(tip).to_string()) .show(ui); } - IconButton::command(IconId::new("enclose"), CommandRef::new("format.enclose")) + IconButton::command(crate::icons::spec("enclose"), CommandRef::new("format.enclose")) .label(tl!("Enclose Characters").to_string()) .tooltip(tl!("Enclose Characters").to_string()) .show(ui); @@ -338,13 +338,13 @@ pub(super) fn home(row: &mut RibbonRow<'_>, app: &mut WordApp) { for (icon, tip, id) in [("outdent", "Decrease Indent", "para.outdent"), ("indent", "Increase Indent", "para.indent"), ("sort", "Sort", "para.sort")] { - IconButton::command(crate::icons::id(icon), CommandRef::new(id)) + IconButton::command(crate::icons::spec(icon), CommandRef::new(id)) .label(tl!(tip).to_string()) .tooltip(tl!(tip).to_string()) .show(ui); } ToggleButton::command(CommandRef::new("view.marks")) - .icon(IconId::new("wordcraft.pilcrow")) + .icon(crate::icons::spec("pilcrow")) .icon_only() .selected(marks) .tooltip(tl!("Show/Hide ΒΆ").to_string()) @@ -413,7 +413,7 @@ pub(super) fn home(row: &mut RibbonRow<'_>, app: &mut WordApp) { // whole document with Ctrl+A first (the commands take `scope: "all"` for that as well). row.group(ribbon_group("paragraphTools", "Paragraph Tools", "pilcrow", None), |ui| { let face = Button::new(tl!("Paragraph\nTools").to_string()) - .icon(IconId::new("wordcraft.pilcrow")) + .icon(crate::icons::spec("pilcrow")) .tooltip(tl!("Paragraph Tools").to_string()) .arrangement(Arrangement::Stacked); menu_button(ui, face, tl!("Paragraph Tools").to_string(), None, |ui, _| { diff --git a/crates/ui-egui/src/ribbon/review.rs b/crates/ui-egui/src/ribbon/review.rs index 26aebadb22..9e1b74962c 100644 --- a/crates/ui-egui/src/ribbon/review.rs +++ b/crates/ui-egui/src/ribbon/review.rs @@ -199,7 +199,7 @@ pub(super) fn developer(row: &mut RibbonRow<'_>, app: &mut WordApp) { for cells in rows { Row::new().show(ui, |ui, _| { for (icon_name, id) in cells { - IconButton::command(crate::icons::id(icon_name), CommandRef::new(id)).show(ui); + IconButton::command(crate::icons::spec(icon_name), CommandRef::new(id)).show(ui); } }); }