Skip to content

DesignCraft: An open-source page and layout design editor written by scratch in pure Rust

Merge #255 (update): fix(ui): Compact the Advanced object Control panel into aligned rows

aiongg8e212fb611d3
diff --cc ROADMAP.md
index 1b8ee7a18,8a28b39bf..815b55958
--- a/ROADMAP.md
+++ b/ROADMAP.md
@@@ -156,41 -132,13 +156,43 @@@ Newest first
- **2026-10-12** · Window close and application/menu Quit ask about unsaved documents; later Cancel keeps every tab open, including earlier Don't Save choices. Approvals are rechecked after edits. Cancelable macOS Dock Quit remains open (#544). No readiness percentage change.
- **2026-10-12** · Each running app keeps recovery data in its own locked folder; current folder and lock ownership are checked before writes and cleanup. Failed isolation disables recovery with a warning instead of sharing document IDs. No readiness percentage change.
- **2026-10-12** · Native engine saves and exports replace files atomically; failed writes retain the original, private staging preserves Unix permissions, and valid long filenames work. Desktop Services and CLI raster exports remain separate follow-ups. No readiness percentage change.
+- **2026-10-11** · Document chapter numbering (#341): style, automatic, start at, same as previous
+ document in the book; Update Numbering resolves it in book order.
+ - **2026-10-11** · Advanced workspace's object Control panel compacted into aligned two-row
+ groups (#255): spinners, fill/stroke chips, proportion links, corners, Auto-Fit, alignment.
- **2026-10-12** · Words in capitals hyphenate like capitalized words (FERRUM COM-MODI), as in InDesign; Hyphenate Capitalized Words off keeps them whole. No readiness percentage change.
+- **2026-10-12** · Load Swatches refuses an `.ase` file with more than 100,000 colors, and `swatch.load` merges a file of 100,000 colors in under 0.1 s (it took 9.6 s of CPU in a test build). No readiness percentage change.
+- **2026-10-11 (printing):** `file.printers` and `file.print` use craft-libs/craft-print for CUPS and Windows. DesignCraft retains PDF export, page selection, spreads, marks and bleed; dry runs create no temporary PDF or print job. Windows selects matching or default driver paper and shrinks oversized sheets without enlarging smaller ones; queue duplex defaults are preserved. Headless tests exercise exported bytes, job settings, dry runs and refusals; shared native Windows CI passes, including paused-queue submission and cleanup. PostScript, production print controls and physical output validation remain open. No readiness percentage change.
+- **2026-10-11** · The View menu follows InDesign's: proofing first, then zoom, Rotate Spread, Screen Mode, Display Performance, rulers, Extras, Grids & Guides and Structure; the view items that sat at the end of the Type menu moved there. No readiness percentage change.
+- **2026-10-11** · Properties › Appearance's Fill and Stroke menus gain InDesign's Tint field and, for a text frame, Apply To: Frame / Text. No readiness percentage change.
+- **2026-10-11** · `story.replaceRange`, `story.setText`, notes, footnotes, endnotes, type on a path and table cells read `\r` and `\r\n` as paragraph returns, as `frame.create` and `text.insert` already did. No readiness percentage change.
+- **2026-10-11** · Corner Options keep curved sides curved and round every corner point, including where an arc meets a line (a Pathfinder quarter circle with rounded corners stayed a triangle). No readiness percentage change.
+- **2026-10-11:** Type › Justification… (Cmd+Alt+Shift+J, also in the Paragraph panel menu) sets word and letter spacing, glyph scaling and the composer on the selected paragraphs, sharing the Paragraph Style Options section (#531). No readiness percentage change.
+- **2026-10-11** · Properties gains InDesign's Pathfinder section (Add, Subtract, Intersect, Exclude Overlap, Minus Back) with several objects selected; section titles and icon buttons have accessible names. No readiness percentage change.
- **2026-10-11** · `transform.move {copy}`, Edit › Duplicate and Step and Repeat return the copies' ids, so a script can go on with them. No readiness percentage change.
- **2026-10-11** · `object.fill` and `object.stroke` refuse a swatch name the document doesn't have (it painted nothing) and suggest the name meant (`Paper` → `[Paper]`). No readiness percentage change.
-- **2026-10-11 (printing):** `file.printers` and `file.print` use craft-libs/craft-print for CUPS and Windows. DesignCraft retains PDF export, page selection, spreads, marks and bleed; dry runs create no temporary PDF or print job. Windows selects matching or default driver paper and shrinks oversized sheets without enlarging smaller ones; queue duplex defaults are preserved. Headless tests exercise exported bytes, job settings, dry runs and refusals; shared native Windows CI passes, including paused-queue submission and cleanup. PostScript, production print controls and physical output validation remain open. No readiness percentage change.
-
+- **2026-10-11** · Japanese captions now cover print ranges, imported style handling and table
+ row/column movement, including row-height distribution. Existing translation and RTL helpers
+ handle the display; command IDs, stored option values and user-defined style names are unchanged.
+- **2026-10-11** · Moving a sheared and rotated text frame no longer leaves trails of text behind: canvas repaints cover the frame's whole text box, not just its outline. No readiness percentage change.
+- **2026-10-11** · Live corners: the yellow widget on a selected rectangle frame shows corner
+ diamonds; dragging one rounds the corners, Alt-click steps the corner shape (#186).
+- **2026-10-11** · Optical kerning (#181): pairs are spaced from their outlines (ink gap per band,
+ pulled towards the font's stem gap, bounded) instead of silently using the font's kern pairs.
+- **2026-10-11** · New Document laid out like InDesign's (#325): Recent, Saved, Print, Web and
+ Mobile preset tabs beside the preset's details; saved document presets live in the engine
+ (`file.savePreset`, `file.deletePreset`, `file.new {preset}`); `file.new` takes intent, units,
+ start page and per-edge bleed and slug.
+- **2026-10-11** · macOS: fonts that font services and managers activate (Adobe Fonts,
+ RightFont) are listed, read from the files CoreText has available (#261, #327).
+- **2026-10-11:** Document pages take their parent page's margins and columns (left or right parent page by side) and follow its changes unless they have their own; parent ruler guides draw and snap on the pages based on it. IDML import marks a page margin preference that differs from its parent as the page's own. No readiness percentage change.
+- **2026-10-11** · Document Setup laid out like InDesign's: Page Size, Margins (new: every
+ page's, `layout.documentSetup {margins}`), Bleed and Slug with links, Adjust Layout.
+- **2026-10-11** · IDML reads and writes a spread's view rotation (Rotate Spread) as the
+ rotation part of the spread transform (#484).
+- **2026-10-11** · The document grid is drawn (View ▸ Grids & Guides ▸ Show/Hide Document Grid,
+ ⌘'), on the lines Snap to Document Grid uses, behind or in front of page items (#530).
+- **2026-10-12** · Double-clicking the Fill or Stroke box in the Tools panel opens the Color Picker with the selection's colour, as in InDesign (it opened the Swatches panel). No readiness percentage change.
- **2026-10-10 (UI.4–UI.5):** Panel tabs can move into other groups, split the dock, float, resize and return to their saved locations through shared docking transactions. Layouts persist in custom workspaces; UI and control commands share the same validated action path. Shared pane geometry and widget-state theme application retain all five palettes and local fonts. Split panes send keyboard input only to the focused canvas and scope contextual toolbar IDs per pane. No readiness percentage change.
- **2026-10-10** · Version 0.6.0; releases add a Linux riscv64 tar.gz (cross-compiled, CLI
smoke-tested under QEMU).
diff --cc crates/ui-egui/src/panels/mod.rs
index 2854f661f,2a07f34ed..8cc2d2df7
--- a/crates/ui-egui/src/panels/mod.rs
+++ b/crates/ui-egui/src/panels/mod.rs
@@@ -251,63 -181,224 +251,74 @@@ pub fn swatch_menu_row(ui: &mut egui::U
resp.clicked()
}
+/// The list in a swatch popup → the swatch picked. It is as wide as its longest name (within
+/// limits), and its rows stop short of the scroll bar that floats over the list's edge.
+pub fn swatch_list(ui: &mut egui::Ui, doc: &designcraft_doc::Document, current: &str) -> Option<String> {
+ let font = swatch_menu_font();
+ let widest = doc
+ .swatches
+ .iter()
+ .map(|sw| ui.painter().layout_no_wrap(sw.name.clone(), font.clone(), egui::Color32::PLACEHOLDER).size().x)
+ .fold(0.0, f32::max);
+ let scroll = &ui.spacing().scroll;
+ let bar = scroll.bar_inner_margin + scroll.bar_width + scroll.bar_outer_margin;
+ let width = (SWATCH_MENU_TEXT_X + widest + 10.0 + bar).clamp(200.0, 360.0);
+ ui.set_min_width(width);
+ ui.set_max_width(width);
+ let mut picked = None;
+ egui::ScrollArea::vertical().max_height(320.0).show(ui, |ui| {
+ for sw in &doc.swatches {
+ if swatch_menu_row(ui, doc, &sw.name, current, width - bar) {
+ picked = Some(sw.name.clone());
+ ui.close();
+ }
+ }
+ });
+ picked
+}
+
- /// A swatch dropdown showing a chip and name; `on_pick` gets the chosen swatch name.
- pub fn swatch_picker(app: &mut DesignApp, ui: &mut egui::Ui, id: &str, current: Option<String>, on_pick: impl FnOnce(&mut DesignApp, String)) {
- let Some(doc) = app.session.active().map(|d| d.doc.clone()) else { return };
+ /// A swatch dropdown showing a chip and name; `on_pick` gets the chosen swatch name. Returns the
+ /// chip's response (`None` without a document), for a caller to label or annotate.
+ pub fn swatch_picker(
+ app: &mut DesignApp,
+ ui: &mut egui::Ui,
+ id: &str,
+ current: Option<String>,
+ on_pick: impl FnOnce(&mut DesignApp, String),
+ ) -> Option<egui::Response> {
+ let doc = app.session.active().map(|d| d.doc.clone())?;
let cur = current.unwrap_or_default();
let (c, g) = crate::widgets::swatch_colors(&doc, &cur, 1.0);
let mut picked = None;
- ui.push_id(id, |ui| {
- let (r, resp) = ui.allocate_exact_size(vec2(30.0, 18.0), egui::Sense::click());
- crate::widgets::paint_chip(
- ui.painter(),
- egui::Rect::from_min_size(r.min, vec2(18.0, 18.0)),
- if cur.is_empty() { Some(egui::Color32::GRAY) } else { c },
- g,
- );
- crate::icons::paint(
- ui.painter(),
- egui::Rect::from_min_size(r.min + vec2(18.0, 3.0), vec2(12.0, 12.0)),
- "chevron-down",
- Tokens::get(ui.ctx()).icon,
- );
- egui::Popup::menu(&resp).show(|ui| {
- picked = swatch_list(ui, &doc, &cur);
- });
- });
+ let resp = ui
+ .push_id(id, |ui| {
+ let (r, resp) = ui.allocate_exact_size(vec2(30.0, 18.0), egui::Sense::click());
+ crate::widgets::paint_chip(
+ ui.painter(),
+ egui::Rect::from_min_size(r.min, vec2(18.0, 18.0)),
+ if cur.is_empty() { Some(egui::Color32::GRAY) } else { c },
+ g,
+ );
+ crate::icons::paint(
+ ui.painter(),
+ egui::Rect::from_min_size(r.min + vec2(18.0, 3.0), vec2(12.0, 12.0)),
+ "chevron-down",
+ Tokens::get(ui.ctx()).icon,
+ );
+ egui::Popup::menu(&resp).show(|ui| {
- ui.set_min_width(200.0);
- ui.set_max_width(280.0);
- egui::ScrollArea::vertical().max_height(320.0).show(ui, |ui| {
- for sw in &doc.swatches {
- if swatch_menu_row(ui, &doc, &sw.name, &cur) {
- picked = Some(sw.name.clone());
- ui.close();
- }
- }
- });
++ picked = swatch_list(ui, &doc, &cur);
+ });
+ resp
+ })
+ .inner;
if let Some(p) = picked {
on_pick(app, p);
}
+ Some(resp)
}
-/// A five-pointed star (filled, or outlined).
-fn paint_star(p: &egui::Painter, c: egui::Pos2, r: f32, filled: bool, color: egui::Color32) {
- let pt = |i: usize, rad: f32| {
- let a = -std::f32::consts::FRAC_PI_2 + i as f32 * std::f32::consts::PI / 5.0;
- c + egui::vec2(a.cos(), a.sin()) * rad
- };
- let outline: Vec<egui::Pos2> = (0..10).map(|i| pt(i, if i % 2 == 0 { r } else { r * 0.42 })).collect();
- if filled {
- // The inner pentagon and the five points (each convex).
- let inner: Vec<egui::Pos2> = (0..5).map(|i| outline[2 * i + 1]).collect();
- p.add(egui::Shape::convex_polygon(inner, color, egui::Stroke::NONE));
- for i in 0..5 {
- p.add(egui::Shape::convex_polygon(vec![outline[(2 * i + 9) % 10], outline[2 * i], outline[2 * i + 1]], color, egui::Stroke::NONE));
- }
- } else {
- p.add(egui::Shape::closed_line(outline, egui::Stroke::new(1.0, color)));
- }
-}
-
-/// The font menu's state while it is open: the search, Show Favorites Only, the match ↑/↓ highlight
-/// and the frame it was last shown (a menu not shown the frame before has just opened).
-#[derive(Clone, Default)]
-struct FontMenuState {
- query: String,
- only_favs: bool,
- highlight: Option<usize>,
- frame: Option<u64>,
-}
-
-/// The Font menu, inside any font field's popup or combo box: a search field (it has the keyboard
-/// while the menu is open, and starts empty each time it opens), favourites (★, Show Favorites
-/// Only), and each family's name with a sample in that family, the script groups apart. ↑/↓ move
-/// through the matches, Return picks one and Escape closes the menu; none of them reach a dialog
-/// under the menu. Returns the family picked and closes the menu; the search, Favorites and the
-/// stars keep it open (the popup closes on a click outside only).
-pub fn font_menu_body(app: &mut DesignApp, ui: &mut egui::Ui, menu: &[designcraft_fonts::FamilyInfo], current: &str, width: f32) -> Option<String> {
- let (fonts, scope) = (fonts(app), font_scope(app));
- let english = app.session.prefs.show_font_names_in_english;
- let mut favs = app.session.prefs.favorite_fonts.clone();
- let mut pick = None;
- let mut favs_changed = false;
- let state_id = egui::Id::new("font_menu_state");
- let mut st: FontMenuState = ui.data(|d| d.get_temp(state_id)).unwrap_or_default();
- let frame = ui.ctx().cumulative_frame_nr();
- if st.frame.is_none_or(|f| f.saturating_add(1) < frame) {
- st.query.clear();
- st.highlight = None;
- }
- st.frame = Some(frame);
- let t = crate::theme::Tokens::get(ui.ctx());
- ui.set_width(width.max(300.0));
- let search = ui
- .horizontal(|ui| {
- let search = ui.add(
- egui::TextEdit::singleline(&mut st.query)
- .hint_text(crate::rtl::widget(ui, crate::i18n::tr(&app.ui.language, "Search fonts")))
- .desired_width(200.0)
- // Return picks the highlighted match instead of leaving the field.
- .return_key(None),
- );
- ui.toggle_value(&mut st.only_favs, crate::rtl::widget(ui, crate::i18n::tr(&app.ui.language, "Favorites"))).on_hover_ui(|ui| {
- crate::rtl::label(ui, crate::i18n::tr(&app.ui.language, "Show Favorites Only"));
- });
- search
- })
- .inner;
- // Typing always goes to the search, never to the document under the menu.
- if !search.has_focus() {
- search.request_focus();
- }
- let q = st.query.to_lowercase();
- let shown: Vec<&designcraft_fonts::FamilyInfo> = menu.iter().filter(|f| f.matches(&q) && (!st.only_favs || favs.contains(&f.family))).collect();
- if search.changed() {
- st.highlight = if q.is_empty() { None } else { Some(0) };
- }
- // The menu owns these keys while it is open: a dialog under it must not take Return as OK or
- // Escape as Cancel.
- let (down, up, enter, escape) = ui.input_mut(|i| {
- let mut key = |k| i.consume_key(egui::Modifiers::NONE, k);
- (key(egui::Key::ArrowDown), key(egui::Key::ArrowUp), key(egui::Key::Enter), key(egui::Key::Escape))
- });
- let last = shown.len().checked_sub(1);
- st.highlight = match (st.highlight, last) {
- (_, None) => None,
- (None, Some(_)) if down => Some(0),
- (Some(h), Some(l)) if down => Some((h + 1).min(l)),
- (Some(h), Some(l)) if up => Some(h.saturating_sub(1).min(l)),
- (h, Some(l)) => h.map(|h| h.min(l)),
- };
- if enter && let Some(f) = st.highlight.and_then(|h| shown.get(h)) {
- pick = Some(f.family.clone());
- }
- let ppp = ui.ctx().pixels_per_point();
- egui::ScrollArea::vertical().max_height(380.0).auto_shrink([false, true]).show(ui, |ui| {
- let mut group = None;
- for (k, info) in shown.iter().enumerate() {
- // A separator between the Western fonts and each CJK language's.
- if group.is_some_and(|g| g != info.group) {
- ui.separator();
- }
- group = Some(info.group);
- let f = &info.family;
- let label = info.label(english);
- let (row, mut resp) = ui.allocate_exact_size(egui::vec2(ui.available_width(), 24.0), egui::Sense::click());
- let highlighted = st.highlight == Some(k);
- if highlighted && (down || up) {
- ui.scroll_to_rect(row, None);
- }
- if !ui.is_rect_visible(row) {
- continue;
- }
- resp.widget_info(|| egui::WidgetInfo::selected(egui::WidgetType::SelectableLabel, true, f == current, label));
- if label != f {
- resp = resp.on_hover_text(f);
- }
- if f == current {
- ui.painter().rect_filled(row, 0.0, t.row_selected);
- } else if highlighted || resp.hovered() {
- ui.painter().rect_filled(row, 0.0, t.hover);
- }
- // Favourite star.
- let star = egui::Rect::from_min_size(row.min + egui::vec2(2.0, 4.0), egui::vec2(16.0, 16.0));
- let fav = favs.contains(f);
- let sr = ui.interact(star, ui.id().with(("fav", f)), egui::Sense::click());
- paint_star(ui.painter(), star.center(), 6.5, fav, if fav { t.accent } else { t.text_dim });
- if sr.clicked() {
- if fav {
- favs.retain(|x| x != f);
- } else {
- favs.push(f.clone());
- }
- favs_changed = true;
- }
- ui.painter().text(row.min + egui::vec2(22.0, 12.0), egui::Align2::LEFT_CENTER, label, egui::FontId::proportional(12.0), t.text);
- // The name in its own face (rendered once per family and scale).
- let key = egui::Id::new(("font_preview", f, scope, (ppp * 100.0) as u32, t.text.to_array()));
- let tex: Option<egui::TextureHandle> = ui.data(|d| d.get_temp(key));
- let tex = tex.unwrap_or_else(|| {
- let img = designcraft_render::glyphs::text_line(&fonts, f, "Regular", "Sample", (18.0 * ppp) as u32, t.text.to_array());
- let ci = egui::ColorImage::from_rgba_premultiplied([img.width as usize, img.height as usize], &img.pixels);
- let h = ui.ctx().load_texture(format!("font_preview_{f}"), ci, egui::TextureOptions::LINEAR);
- ui.data_mut(|d| d.insert_temp(key, h.clone()));
- h
- });
- let size = tex.size_vec2() / ppp;
- let at = egui::pos2(row.max.x - size.x - 4.0, row.center().y - size.y / 2.0);
- ui.painter().image(
- tex.id(),
- egui::Rect::from_min_size(at, size),
- egui::Rect::from_min_max(egui::pos2(0.0, 0.0), egui::pos2(1.0, 1.0)),
- egui::Color32::WHITE,
- );
- if resp.clicked() && !sr.clicked() {
- pick = Some(f.clone());
- }
- }
- });
- ui.data_mut(|d| d.insert_temp(state_id, st));
- if favs_changed {
- let _ = app.run("prefs.set", json!({ "favoriteFonts": favs }));
- }
- if pick.is_some() || escape {
- ui.close();
- }
- pick
-}
-
/// A font family combo box showing `current` by its menu name, with [`font_menu_body`] as its menu.
-/// Returns the family picked.
+/// Returns the font picked.
pub fn font_combo(
app: &mut DesignApp,
ui: &mut egui::Ui,
@@@ -734,118 -709,3 +745,120 @@@ mod font_menu_ui_tests
}
}
}
+
+#[cfg(test)]
+mod swatch_list_tests {
+ use super::*;
+
+ fn rects(shapes: &[egui::epaint::ClippedShape]) -> Vec<(egui::Rect, egui::Color32)> {
+ fn walk(s: &egui::Shape, out: &mut Vec<(egui::Rect, egui::Color32)>) {
+ match s {
+ egui::Shape::Rect(r) => out.push((r.rect, r.fill)),
+ egui::Shape::Vec(v) => v.iter().for_each(|s| walk(s, out)),
+ _ => {}
+ }
+ }
+ let mut out = vec![];
+ shapes.iter().for_each(|s| walk(&s.shape, &mut out));
+ out
+ }
+
+ fn texts(shapes: &[egui::epaint::ClippedShape]) -> Vec<(String, egui::Rect)> {
+ fn walk(s: &egui::Shape, out: &mut Vec<(String, egui::Rect)>) {
+ match s {
+ egui::Shape::Text(t) => out.push((t.galley.job.text.clone(), t.visual_bounding_rect())),
+ egui::Shape::Vec(v) => v.iter().for_each(|s| walk(s, out)),
+ _ => {}
+ }
+ }
+ let mut out = vec![];
+ shapes.iter().for_each(|s| walk(&s.shape, &mut out));
+ out
+ }
+
+ #[test]
+ fn the_swatch_under_the_pointer_is_highlighted_and_names_clear_the_scroll_bar() {
+ let mut app = DesignApp::new(designcraft_engine::Session::new(), crate::Services::default());
+ app.run("file.new", serde_json::json!({})).unwrap();
+ // A long name, as process swatches have.
+ app.run("swatch.create", serde_json::json!({"name": "C=15 M=100 Y=100 K=0 Long Name", "color": {"c": 15, "m": 100, "y": 100, "k": 0}}))
+ .unwrap();
+ let long = "C=15 M=100 Y=100 K=0 Long Name";
+ let ctx = egui::Context::default();
+ crate::theme::install_fonts(&ctx, "");
+ let tokens = Tokens::for_brightness(crate::theme::Brightness::MediumDark);
+ crate::theme::apply(&ctx, &tokens);
+ let mut time = 0.0;
+ let mut frame = |app: &mut DesignApp, events: Vec<egui::Event>| {
+ time += 0.1;
+ let raw = egui::RawInput {
+ screen_rect: Some(egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(800.0, 700.0))),
+ time: Some(time),
+ events,
+ ..Default::default()
+ };
- let mut out = ctx.run_ui(raw, |ui| swatch_picker(app, ui, "list", Some("[Black]".into()), |_, _| {}));
++ let mut out = ctx.run_ui(raw, |ui| {
++ swatch_picker(app, ui, "list", Some("[Black]".into()), |_, _| {});
++ });
+ out.textures_delta.clear();
+ out.shapes
+ };
+ frame(&mut app, vec![]);
+ let chip = egui::pos2(17.0, 17.0);
+ for pressed in [true, false] {
+ frame(
+ &mut app,
+ vec![
+ egui::Event::PointerMoved(chip),
+ egui::Event::PointerButton { pos: chip, button: egui::PointerButton::Primary, pressed, modifiers: Default::default() },
+ ],
+ );
+ }
+ let shapes = frame(&mut app, vec![]);
+ let (_, name) = texts(&shapes).into_iter().find(|(t, _)| t == "[Registration]").expect("the list is open");
+ let pointer = name.center();
+ frame(&mut app, vec![egui::Event::PointerMoved(pointer)]);
+ let shapes = frame(&mut app, vec![]);
+ let all = rects(&shapes);
+ let (row, _) = *all.iter().find(|(r, c)| *c == tokens.accent_strong && r.contains(pointer)).expect("the hovered row is highlighted");
+ let (list, _) = *all
+ .iter()
+ .filter(|(r, c)| *c == tokens.panel && r.contains_rect(row))
+ .min_by(|a, b| a.0.area().total_cmp(&b.0.area()))
+ .expect("the popup");
+ let scroll = ctx.global_style().spacing.scroll;
+ assert!(row.right() + scroll.bar_width <= list.right(), "rows {row:?} stop short of the scroll bar in {list:?}");
+ let (_, long_rect) = texts(&shapes).into_iter().find(|(t, _)| t == long).unwrap();
+ assert!(long_rect.right() <= row.right(), "the longest name {long_rect:?} fits its row {row:?}");
+ assert!(texts(&shapes).iter().any(|(t, r)| t == "[Black]" && r.right() <= row.right()));
+ }
+}
+
+#[cfg(test)]
+mod content_selection_tests {
+ use serde_json::json;
+
+ /// With a placed graphic selected (Direct Selection), X/Y/W/H are the graphic's: what the
+ /// Transform fields then set.
+ #[test]
+ fn a_selected_graphic_shows_its_own_bounds() {
+ let mut app = crate::DesignApp::new(designcraft_engine::Session::new(), crate::Services::default());
+ app.run("file.new", json!({})).unwrap();
+ let f = app.run("frame.create", json!({"rect": [100, 100, 300, 300], "content": "graphic"})).unwrap()["id"].clone();
+ let png = designcraft_render::Rendered { width: 400, height: 400, pixels: vec![200u8; 400 * 400 * 4] }.to_png();
+ let b64 = designcraft_engine::cmd::base64_encode(&png);
+ app.run("file.place", json!({"base64": b64, "name": "a.png", "frame": f})).unwrap();
+ app.run("selection.set", json!({"ids": [f]})).unwrap();
+ let frame = super::sel_info(&app).unwrap().page_rect;
+ assert!((frame.width() - 200.0).abs() < 1e-6, "{frame:?}");
+ app.run("selection.set", json!({"ids": [f], "content": true})).unwrap();
+ // Placing fitted it to 50%: back to its own 400 pt.
+ app.run("transform.set", json!({"scaleX": 100, "scaleY": 100})).unwrap();
+ let g = super::sel_info(&app).unwrap().page_rect;
+ assert!((g.width() - 400.0).abs() < 1e-6, "the graphic's width, not the frame's: {g:?}");
+ // So a width typed from it scales the graphic by that ratio, not by half.
+ app.run("transform.set", json!({"width": 401})).unwrap();
+ let after = super::sel_info(&app).unwrap().page_rect;
+ assert!((after.width() - 401.0).abs() < 1e-6, "{after:?}");
+ }
+}