Compare commits

..
Author SHA1 Message Date
Martin BallandClaude Opus 5.5 190fcafd47 fix(equation): draw symbol and structure pictures without the checkerboard, symbols at a readable size (#7975)
Pictures are alpha ink masks drawn without the transparency grid. The symbol strip requests
its picture from the tile's short side (the tiles are 24 x 52 pt and the picture is fitted),
and sets symbols at 22 pt, so they read at about 16 pt.

Partial: the Tools labels (Unicode, LaTeX, Normal Text) are still icon-only at 1440, as the
ribbon fit keeps Tools at the compact level.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FypgCWNarDG3QfXK2YMzdx
2026-11-28 05:27:16 +00:00
Martin BallandClaude Opus 5.5 00866e3b65 fix(ribbon): Diagram Design layouts in one strip, Size fields labelled H:/W: (#7974)
size_field is shared, so Picture Format and Shape Format Size also gain the visible H:/W: labels.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FypgCWNarDG3QfXK2YMzdx
2026-11-28 04:19:17 +00:00
Martin BallandClaude Opus 5.5 aaab1bbc9d fix(diagram): Insert Diagram shows every layout (#7973)
The same max_rows item-count cap showed 3 of 8 layouts. Partial: the names "Basic Process"
and "Basic Pyramid" are still elided, since wider cells break the pinned 75x93 cell size test
and two-line captions need card text the dialog does not use.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FypgCWNarDG3QfXK2YMzdx
2026-11-28 04:19:17 +00:00
Martin BallandClaude Opus 5.5 e50ab14771 fix(symbol): show the Symbols map in rows, with the Recently used heading and from Unicode (hex) (#7972)
max_rows counts items, not grid rows, so the 8-row cap showed one row; cap it by items.
The Recently used row already existed; its heading now shows (as the row's label) while
the row is empty too, and the code field says it is Unicode hex.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FypgCWNarDG3QfXK2YMzdx
2026-11-28 04:19:17 +00:00
10 changed files with 171 additions and 33 deletions
+7
View File
@@ -39,6 +39,13 @@ pub(crate) use host::close_all;
pub(crate) use mailings::{FilterRow, RecipientDraft, RecipientFilter, RecipientListDialog, hold_rows, merge_order, visible_recipients};
pub(crate) use page_setup::PAPER_LABELS;
/// `max_rows` for a `TileGrid` that shows `rows` rows of `columns` tiles. The collection counts the cap in
/// items (the tile `rows` in, not the grid row it is in), so a cap of `rows` shows one row; a cap past the item
/// count adds blank rows, so it stops at `len`. lean: upstream fix in craft-libs `rows_height`, then drop this.
pub(crate) fn tile_rows_cap(len: usize, columns: usize, rows: usize) -> u16 {
u16::try_from(len.min(columns * rows)).unwrap_or(u16::MAX)
}
/// Opens the dialog `name` for a script, a button or a command, with `params`; the module of the name reads what it
/// needs of them. Returns the dialog's id, or `None` when no dialog opened (an unknown name, nothing to show, or a
/// pane such as Restrict Editing).
@@ -3,23 +3,24 @@ use std::sync::Arc;
use craft::behavior::{ColumnWidth, Selection, SelectionChange, keyed};
use craft::font_manager::Catalog;
use craft::font_manager::picker::FontPickerSettings;
use craft::ui::contract::{Bind, CollectionEvent, ColumnKey, ColumnSpec, SelectMode, Show as _, ShowCollection as _, ShowContainer as _};
use craft::ui::contract::{Bind, CollectionEvent, ColumnKey, ColumnSpec, Props as _, SelectMode, Show as _, ShowCollection as _, ShowContainer as _};
use craft::ui::dialog::{DialogId, DialogResult, DialogStack, HeldAnswer, HeldOk, StackDialog, dialog_id};
use craft::ui::display::{Kbd, Text};
use craft::ui::form::Field;
use craft::ui::layout_components::Stack;
use craft::ui::layout_components::{Row, Stack};
use craft::ui::list::{ListRow, ThumbAspect, ThumbSize};
use craft::ui::patterns::form_dialogs::{FormCx, FormDialog};
use craft::ui::primitives::ContentPainterCx;
use craft::ui::runtime::env::Label;
use craft::ui::table::Table;
use craft::ui::tabs::{Tab, TabKind, TabStrip};
use craft::ui::text::TextField;
use craft::ui::tile_grid::{CaptionPlace, Tile, TileGrid};
use egui::Ui;
use serde::{Deserialize, Serialize};
use serde_json::{Value, json};
use super::{select_index, settled, text_field, word};
use super::{select_index, settled, word};
use crate::WordApp;
use crate::dialogs::host::{DialogHooks, Settle, open_with};
use crate::widgets::font_box::font_picker;
@@ -36,6 +37,12 @@ pub struct RecentSymbol {
pub font: String,
}
/// Characters per row of the Symbols map (Word's grid is 16 wide).
// lean: the cap assumes this many columns; read the laid-out count if the map becomes resizable.
const GRID_COLUMNS: usize = 16;
/// Rows of the Symbols map shown before it scrolls.
const GRID_ROWS: usize = 8;
/// How many recent symbols are kept.
pub const RECENT_SYMBOLS: usize = 20;
@@ -621,7 +628,13 @@ fn symbol_page(ui: &mut Ui, form: &mut SymbolForm, catalog: Option<&Arc<Catalog>
Text::new(Label::from(format!("U+{:04X}", c as u32))).show(ui);
}
let before = form.code.clone();
text_field(ui, "symbol_code", &word("Character code:"), &mut form.code);
let label = word("Character code:");
Field::new(label.clone()).id_salt("symbol_code").show(ui, |ui, _| {
Row::new().show(ui, |ui, _| {
TextField::new(label.clone(), Bind::bound(&mut form.code)).show(ui);
Text::new(word("from Unicode (hex)")).show(ui);
});
});
if form.code != before {
let code = form.code.clone();
form.select_code(&code);
@@ -631,14 +644,17 @@ fn symbol_page(ui: &mut Ui, form: &mut SymbolForm, catalog: Option<&Arc<Catalog>
/// The recently inserted symbols as one row of glyphs, each in its own font; a click picks one.
fn recent_row(ui: &mut Ui, form: &mut SymbolForm, dark: bool) {
// The heading shows while the row is empty too, as Word does; with symbols it labels the row.
if form.recent.is_empty() {
Text::new(word("Recently used symbols:")).show(ui);
return;
}
let positions: Vec<usize> = (0..form.recent.len()).collect();
let source = keyed(&positions, |at: &usize| *at);
let events = {
let mut events = Vec::new();
Field::new(word("Recently used symbols:")).show(ui, |ui, _| {
let recent = &form.recent;
TileGrid::new(word("Recently used symbols:"))
events = TileGrid::new(word("Recently used symbols:"))
.thumb_size(ThumbSize::Medium)
.select(SelectMode::Single)
.caption(CaptionPlace::None)
@@ -652,8 +668,8 @@ fn recent_row(ui: &mut Ui, form: &mut SymbolForm, dark: bool) {
Tile::new(r.ch).thumb(ThumbAspect::SQUARE, move |cx, rect| paint_glyph(cx, rect, ch, &font, dark))
})
.response
.events
};
.events;
});
for event in events {
if let CollectionEvent::Selection { change: SelectionChange::Set(rows), .. } = event
&& let Some(r) = rows.last().and_then(|i| form.recent.get(*i)).cloned()
@@ -685,7 +701,8 @@ fn glyph_grid(ui: &mut Ui, form: &mut SymbolForm, dark: bool) -> bool {
let mut grid = TileGrid::new(word("Symbols"))
.thumb_size(ThumbSize::Medium)
.select(SelectMode::Single)
.max_rows(8)
.max_rows(crate::dialogs::tile_rows_cap(form.chars.len(), GRID_COLUMNS, GRID_ROWS))
.card_columns(GRID_COLUMNS)
.caption(CaptionPlace::None)
.selection(Bind::bound(&mut selection));
if let Some(at) = reveal {
@@ -138,6 +138,43 @@ fn symbol_dialog_uses_compact_tile_grids() {
assert!(recent.height() < 80.0, "recently used symbols row should be compact: {}", recent.height());
}
fn h_recent(a: &mut WordApp) {
remember_symbol(a, "©", "DejaVu Sans");
}
/// #7972: the Symbols map shows rows of characters (not one strip), with the Recently used heading
/// and the note that the code is Unicode hex.
#[test]
fn symbol_dialog_shows_the_map_in_rows() {
use egui::accesskit::Role;
let mut a = app();
h_recent(&mut a);
let mut h = testing::harness(a);
crate::dialogs::open(h.state_mut(), "symbol", &json!({})).expect("symbol dialog opens");
h.run_steps(3);
assert_eq!(h.query_all_by_label("Recently used symbols:").count(), 1, "the heading is the row's one name");
h.get_by_role_and_label(Role::ListBox, "Recently used symbols:");
let map = h.get_by_role_and_label(Role::ListBox, "Symbols").rect();
let tile = h.query_all_by_label("A").map(|n| n.rect()).find(|r| map.contains_rect(*r)).expect("a tile in the map");
assert!(map.height() > 3.0 * tile.height(), "the map is several rows tall: {} vs a tile {}", map.height(), tile.height());
h.get_by_label("from Unicode (hex)");
}
/// #7973: Insert Diagram offers every layout in its grid, not the first row of three.
#[test]
fn insert_diagram_dialog_shows_every_layout() {
use egui::accesskit::Role;
let mut h = testing::harness(app());
crate::dialogs::open(h.state_mut(), "insertSmartArt", &json!({})).expect("the dialog opens");
// The tiles' heights settle over a few passes.
h.run_steps(10);
let grid = h.get_by_role_and_label(Role::ListBox, "Layouts").rect();
for layout in wordcraft_doc::smart_art::SmartArtLayout::ALL {
let shown = h.query_all_by_label(layout.label()).any(|n| grid.contains(n.rect().center()));
assert!(shown, "{} is shown in the grid", layout.label());
}
}
/// The Field dialog builds the field code from its options.
#[test]
fn field_dialog_builds_the_instruction() {
@@ -321,7 +321,7 @@ fn layout_tiles(ui: &mut Ui, theme: &[Rgb], form: &mut SmartArtForm) -> bool {
.card_columns(3)
// Production's picker is three tile rows high and scrolls the rest; the cap also makes the grid the one owner
// of its scroll inside the dialog's scrolling body.
.max_rows(3)
.max_rows(crate::dialogs::tile_rows_cap(shown.len(), 3, 3))
.selection(Bind::given(Selection::single(current)))
.show_items(ui, &keyed(&positions, |i| *i), &mut |key, _| {
let layout = shown.get(*key).copied().unwrap_or_default();
+11 -6
View File
@@ -21,7 +21,7 @@ use wordcraft_doc::math::{MNode, MRun, parse_linear};
use wordcraft_engine::math_gallery::{BUILT_INS, STRUCTURES, SYMBOL_SETS};
use crate::WordApp;
use crate::previews::{MathSource, math_key, math_picture, math_thumbnails};
use crate::previews::{MathSource, math_key, math_painter, math_picture, math_thumbnails};
use crate::ribbon::common::menu_button;
/// What each structure button shows.
@@ -154,10 +154,14 @@ fn math_menu_button(ui: &mut Ui, picture: &str, label: &str, body: impl FnMut(&m
let _ = menu_button(ui, face, tl!(label).to_string(), None, body);
}
/// The size a symbol is set at. The strip's tiles are 24 pt wide and the picture is fitted to them, so it reads at
/// about 16 pt (11 pt drew a speck).
const SYMBOL_PT: f32 = 22.0;
/// The picture source of one symbol, as a literal run.
fn symbol_source(c: char, ink: Color32) -> MathSource {
pub(crate) fn symbol_source(c: char, ink: Color32) -> MathSource {
let nodes = vec![MNode::Run(MRun { text: c.to_string(), lit: true, ..Default::default() })];
MathSource::new(nodes, false, 11.0, [1, 1], ink)
MathSource::new(nodes, false, SYMBOL_PT, [1, 1], ink)
}
/// A grid of rendered math tiles, `(name, picture key)` each over its own source, shaped as the sources are;
@@ -221,13 +225,14 @@ fn symbols(ui: &mut Ui, app: &mut WordApp) {
let ink = ink(ui);
let thumbs = math_thumbnails(ui.ctx());
let sources: Vec<MathSource> = all.iter().map(|c| symbol_source(*c, ink)).collect();
let painters: Vec<_> = all.iter().zip(&sources).map(|(c, source)| math_painter(math_key(&format!("sym:{c}")), &thumbs, source)).collect();
let items: Vec<GalleryItem<'_, char>> = all
.iter()
.zip(&sources)
.map(|(c, source)| GalleryItem {
.zip(&painters)
.map(|(c, paint)| GalleryItem {
key: *c,
label: Label::from(symbol_tooltip(*c, &math_placeholder(ui, &c.to_string()))),
face: GalleryFace::rendered(math_key(&format!("sym:{c}")), &thumbs, source),
face: GalleryFace::Paint(paint),
})
.collect();
let mut sets = |ui: &mut Ui| {
+22 -2
View File
@@ -10,7 +10,10 @@ use std::sync::Arc;
use craft::theme::Mode;
use craft::ui::display::Picture;
use craft::ui::list::ThumbAspect;
use craft::ui::primitives::textures::{LoadedPicture, Revision, ThumbRender, ThumbRequest, ThumbSource, ThumbnailOptions, Thumbnails};
use craft::ui::primitives::ContentPainterCx;
use craft::ui::primitives::textures::{
LoadedPicture, Priority, Revision, ThumbPaint, ThumbRender, ThumbRequest, ThumbSource, ThumbnailOptions, Thumbnails,
};
use craft::ui::runtime::env::Label;
use egui::{Color32, ColorImage, Vec2};
use wordcraft_doc::props::CharProps;
@@ -225,9 +228,26 @@ pub(crate) fn math_thumbnails(ctx: &egui::Context) -> Thumbnails<u64> {
Thumbnails::in_context(ctx, "wordcraft.math", ThumbnailOptions::new())
}
/// The picture request for a tile `rect`: sized by its short side. The picture is fitted into the rect, so a
/// request from the long side of a tall tile (24 x 52 pt in the ribbon) shrinks the symbol to a speck.
pub(crate) fn cell_request(rect: egui::Rect, pixels_per_point: f32) -> ThumbRequest {
ThumbRequest::for_cell(rect.width().min(rect.height()), pixels_per_point)
}
/// Paints the equation picture `key` in a rect, asked for at the size it is painted, for a `GalleryFace::Paint`. The
/// picture is an ink mask, so it is drawn without the transparency grid; the store's placeholder shows until the render
/// lands. lean: only `GalleryFace::rendered` lacks `Picture`'s `checker(false)`; drop this once it has one.
pub(crate) fn math_painter<'a>(key: u64, thumbnails: &'a Thumbnails<u64>, source: &'a MathSource) -> impl Fn(&ContentPainterCx, egui::Rect) + 'a {
move |cx, rect| {
let request = cell_request(rect, cx.pixels_per_point());
let state = thumbnails.state(cx.painter.ctx(), source, &key, &request, Priority::VISIBLE);
thumbnails.paint(cx, rect, &state, &ThumbPaint::default().checker(false));
}
}
/// An equation picture that shows the framework's placeholder until the render lands.
pub(crate) fn math_picture<'a>(label: impl Into<Label>, key: u64, thumbnails: &'a Thumbnails<u64>, source: &'a MathSource) -> Picture<'a> {
Picture::rendered(label, key, thumbnails, source)
Picture::rendered(label, key, thumbnails, source).checker(false)
}
/// An equation rasterised for a tile of `w`×`h` points, as an ink mask.
+20
View File
@@ -53,3 +53,23 @@ fn font_sample_shows_small_caps_and_the_script_mark() {
assert_ne!(draw(&plain, None, false), draw(&plain, sup, false), "the mark is drawn");
assert_ne!(draw(&plain, None, false), draw(&plain, None, true), "Switch Modes transforms the preview");
}
/// #7975: a symbol in the Equation tab's strip reads in its tile, not as a speck. The real tile is 24 x 52 pt and the
/// picture is fitted into it, so the ink as shown spans a third of the tile's width; wide arrows and operators keep
/// their whole ink inside the picture (no clipping).
#[test]
fn symbol_thumbnails_read_in_the_strips_real_tiles() {
let tile = egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(24.0, 52.0));
for c in ['=', '+', '\u{221E}', '\u{00B1}', '\u{27F9}', '\u{27FA}', '\u{27F7}', '\u{2230}'] {
let source = crate::equation_tab::symbol_source(c, Color32::WHITE);
let size = source.size_for(&cell_request(tile, 1.0));
let img = math_image(&source.nodes, source.display, source.pt, size.x, size.y, 1.0).expect("renders");
let [w, h] = img.size;
let inked: Vec<(usize, usize)> = (0..w * h).filter(|i| img.pixels[*i].a() > 64).map(|i| (i % w, i / w)).collect();
let (lo, hi) = (inked.iter().map(|p| p.0).min().unwrap_or(0), inked.iter().map(|p| p.0).max().unwrap_or(0));
let fit = (tile.width() / w as f32).min(tile.height() / h as f32);
let shown = (hi - lo + 1) as f32 * fit;
assert!(shown * 3.0 >= tile.width(), "{c} is a speck: {shown} pt wide in a {} pt tile", tile.width());
assert!(lo > 0 && hi + 1 < w, "{c} touches the picture's edge ({lo}..{hi} of {w})");
}
}
+18 -10
View File
@@ -1,17 +1,15 @@
use craft::behavior::IconId;
use craft::keymap::CommandRef;
use craft::menu::ribbon::{RibbonGroup, RibbonRow};
use craft::menu::ribbon::{Gallery, GalleryFace, GalleryItem, RibbonGroup, RibbonRow};
use craft::ui::buttons::{Arrangement, Button, ToggleButton};
use craft::ui::contract::{Gap, Props as _, Show as _, ShowContainer as _};
use craft::ui::layout_components::Stack;
use craft::ui::list::ThumbAspect;
use craft::ui::menu::MenuItem;
use craft::ui::primitives::FacePaint;
use craft::ui::tile_grid::{CaptionPlace, Tile};
use craft::ui::primitives::{ContentPainterCx, FacePaint};
use super::common::{menu_button, size_field};
use super::{WordApp, json};
use crate::equation_tab::pick_tile;
/// Chart Design and SmartArt Design › Size: the selected graphic's height and width in points. A
/// size outside the range is shown as it is and writes nothing.
@@ -62,13 +60,23 @@ pub(super) fn smart_art_design(row: &mut RibbonRow<'_>, app: &mut WordApp) {
let colors = g.colors;
let theme = &theme;
let line = ui.visuals().weak_text_color();
let picked = pick_tile(ui, tl!("Layouts"), 4, CaptionPlace::None, on, layouts.len(), |at| match layouts.get(at).copied() {
Some(layout) => Tile::new(tl!(layout.label()).to_string())
.thumb(ThumbAspect::new(46, 31), move |cx, r| crate::dialogs_smart_art::preview(cx, r, layout, colors, theme, line)),
None => Tile::new(String::new()),
});
// One strip of small previews, as the old ribbon: the strip steps and its More button lists them all.
let painters: Vec<Box<dyn Fn(&ContentPainterCx, egui::Rect) + '_>> = layouts
.iter()
.map(|&layout| {
Box::new(move |cx: &ContentPainterCx, r: egui::Rect| crate::dialogs_smart_art::preview(cx, r, layout, colors, theme, line))
as Box<dyn Fn(&ContentPainterCx, egui::Rect) + '_>
})
.collect();
let items: Vec<GalleryItem<'_, usize>> = layouts
.iter()
.zip(&painters)
.enumerate()
.map(|(at, (layout, paint))| GalleryItem { key: at, label: tl!(layout.label()).into(), face: GalleryFace::Paint(&**paint) })
.collect();
let out = Gallery::new(tl!("Layouts").to_string(), &items, on.as_ref()).tiles(6, 3).aspect(ThumbAspect::new(46, 31)).show(ui);
// A pick of the current layout does nothing.
if let Some(layout) = picked.and_then(|i| layouts.get(i)).copied().filter(|l| *l != g.layout) {
if let Some(layout) = out.picked.and_then(|i| layouts.get(i)).copied().filter(|l| *l != g.layout) {
let _ = app.run("smartArt.layout", json!({"layout": layout.id()}));
}
});
+13 -5
View File
@@ -5,12 +5,13 @@ use craft::menu::ribbon::{RibbonGroup, RibbonRow};
use craft::ui::buttons::{Arrangement, Button};
use craft::ui::contract::{Bind, BodyCx, Gap, Props as _, Show as _, ShowContainer as _, TooltipSpec, Trigger};
use craft::ui::controls::disclosure::DisclosureGlyph;
use craft::ui::display::Divider;
use craft::ui::display::{Divider, Text};
use craft::ui::layout_components::{Row, Stack};
use craft::ui::list::ThumbAspect;
use craft::ui::menu::{Menu, MenuItem, MenuOutput};
use craft::ui::primitives::{FacePaint, IconSpec};
use craft::ui::runtime::env::Label;
use craft::ui::style::TypeRole;
use craft::ui::text::NumberField;
use serde_json::Value;
@@ -89,11 +90,18 @@ pub(super) fn custom_groups(row: &mut RibbonRow<'_>, app: &mut WordApp, groups:
/// Esc cancels. A value outside `range` (points) is shown and writes nothing. `lock_aspect` false
/// resizes the one side only.
pub(super) fn size_field(ui: &mut Ui, app: &mut WordApp, label: &str, key: &str, pt: f32, lock_aspect: bool, range: RangeInclusive<f32>) {
let field = NumberField::length(tl!(label).to_string(), Bind::given(Some(f64::from(pt))), crate::options::lengths(app.session.units()))
.range(f64::from(*range.start())..=f64::from(*range.end()))
.id_salt(("size_field", key));
let events = field.show(ui).edit.events;
let lengths = crate::options::lengths(app.session.units());
let mut events = None;
// The label shows beside the field, as the old ribbon drew `H: 252 pt`; it is the field's accessible name too.
Row::new().gap(Gap::Tight).show(ui, |ui, _| {
Text::new(tl!(label).to_string()).role(TypeRole::Caption).show(ui);
let field = NumberField::length(tl!(label).to_string(), Bind::given(Some(f64::from(pt))), lengths)
.range(f64::from(*range.start())..=f64::from(*range.end()))
.id_salt(("size_field", key));
events = Some(field.show(ui).edit.events);
});
let key = key.to_string();
let Some(events) = events else { return };
apply_edits(app, events, move |app, v: Option<f64>| {
let Some(v) = v.map(|v| v as f32).filter(|v| range.contains(v)) else { return };
let params = if lock_aspect { json!({ key.as_str(): v }) } else { json!({ key.as_str(): v, "lockAspect": false }) };
+16
View File
@@ -392,6 +392,22 @@ fn contextual_tabs_follow_the_selection() {
}
}
/// #7974: SmartArt Design keeps its Layouts gallery to one strip, as tall as the other groups, and the Size
/// fields show their H: and W: labels.
#[test]
fn smart_art_design_layouts_are_one_strip_and_size_is_labelled() {
use egui::accesskit::Role;
let mut a = WordApp::new(Session::new(wordcraft_doc::Document::new()), crate::Services::default());
a.run("insert.smartArt", json!({"layout": "cycle"})).unwrap();
let h = tab_harness(a, "SmartArt Design");
let height = |name: &str| h.get_by_role_and_label(Role::Group, name).rect().height();
assert!(height("Layouts") <= height("Create Graphic") * 1.2, "Layouts: {} vs {}", height("Layouts"), height("Create Graphic"));
for side in ["H:", "W:"] {
let shown = h.query_all(By::new().label(side)).any(|n| n.accesskit_node().role() != Role::SpinButton);
assert!(shown, "{side} is drawn beside its field");
}
}
/// No group's content runs into its label: View › Show stacked four check boxes in a column
/// made for three, so "Hide White Space" was drawn under "Show". Every tab, every language: each
/// control lies inside its group's access node.