From 81dc35e2581814ed55292c0cc87e94b6fafb11b2 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sat, 28 Nov 2026 09:31:21 -0800 Subject: [PATCH 1/3] Panels: Document Info, Info, Image Trace and Links spacing and labels - Document Info: each value stands at the end of its row again, in a column apart from its label. The row no longer wraps, since a wrapping row places its children at the start. The sections fill the panel's width, and a section gap sets each divider apart from the sections around it. - Info: the two columns of numbers split the panel in halves, and a section gap sets the paints and the type apart from the divider. - Image Trace: Create: shows the Fills and Strokes labels after their check boxes. Inside the Create field a check box's own label was not drawn, so each box now takes a field with its label after it. - Links: an empty panel shows the link icon, "No images" and the hint that File > Place brings an image in. Tests in panels/tests_panel_spacing.rs cover each change. --- crates/ui-egui/src/panels.rs | 2 + crates/ui-egui/src/panels/doc_info.rs | 67 +++++++++-------- crates/ui-egui/src/panels/image_trace/rows.rs | 11 ++- crates/ui-egui/src/panels/info.rs | 57 ++++++++------ crates/ui-egui/src/panels/links.rs | 13 +++- .../ui-egui/src/panels/tests_panel_spacing.rs | 75 +++++++++++++++++++ crates/ui-egui/src/tests/panel_harness.rs | 10 +++ 7 files changed, 176 insertions(+), 59 deletions(-) create mode 100644 crates/ui-egui/src/panels/tests_panel_spacing.rs diff --git a/crates/ui-egui/src/panels.rs b/crates/ui-egui/src/panels.rs index a3f5071435..e9340a8987 100644 --- a/crates/ui-egui/src/panels.rs +++ b/crates/ui-egui/src/panels.rs @@ -1237,6 +1237,8 @@ mod tests_maskview; #[cfg(test)] mod tests_panel_rows; #[cfg(test)] +mod tests_panel_spacing; +#[cfg(test)] mod tests_script_console; #[cfg(test)] mod tests_stroke; diff --git a/crates/ui-egui/src/panels/doc_info.rs b/crates/ui-egui/src/panels/doc_info.rs index 41ec089303..d116498346 100644 --- a/crates/ui-egui/src/panels/doc_info.rs +++ b/crates/ui-egui/src/panels/doc_info.rs @@ -6,7 +6,7 @@ use std::sync::Arc; use craft::keymap::CommandRef; -use craft::ui::contract::{Show as _, ShowContainer as _}; +use craft::ui::contract::{Gap, Show as _, ShowContainer as _}; use craft::ui::display::{Divider, Shade, Text}; use craft::ui::layout::RowAlign; use craft::ui::layout_components::{Row, Stack}; @@ -35,7 +35,8 @@ pub struct DocInfoView { /// the second or third click of a double or triple click. pub(crate) fn row(ui: &mut Ui, label: &str, value: &str) -> bool { let mut clicked = false; - Row::new().fill_width().align(RowAlign::SpaceBetween).wrap(true).show(ui, |ui, _| { + // A wrapping row places its children as `Start` does, so the row does not wrap and the value stands at its end. + Row::new().fill_width().align(RowAlign::SpaceBetween).show(ui, |ui, _| { Text::new(label.to_string()).shade(Shade::Muted).show(ui); // The value can be selected and copied, and a click copies all of it (#8432). A drag selects // and a Shift-click extends the selection, so neither copies. @@ -154,7 +155,9 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) { }; let DocInfoView { selection_only: sel_only, category } = app.ui.doc_info.clone(); let mut copy = None; - Stack::new().show(ui, |ui, _| { + // The sections fill the panel's width, so each row's value stands at its end, and a section gap sets the + // dividers apart from the sections around them. + Stack::new().fill_width().gap(Gap::Section).show(ui, |ui, _| { if sel_only && no_artwork_selected(app) { Text::new(tl!("(No artwork selected)").to_string()).shade(Shade::Muted).show(ui); } @@ -164,38 +167,40 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) { if n > 0 { Divider::horizontal().show(ui); } - let title = s["title"].as_str().unwrap_or_default(); - let rows = s["rows"].as_array().map_or(&[][..], Vec::as_slice); - // Lists show how many they hold; the selection scope shows on the first. - let title = match s["id"].as_str() { - Some("document" | "objects") => tl!(title).to_string(), - _ => format!("{} ({})", tl!(title), rows.len()), - }; - let title = - if sel_only && n == 0 && category.is_empty() { crate::i18n::fmt(tl!("{title} (selection)"), &[("title", &title)]) } else { title }; - Text::new(title).role(TypeRole::Heading).show(ui); - if rows.is_empty() { - Text::new(tl!("None").to_string()).shade(Shade::Muted).show(ui); - } - let id = s["id"].as_str().unwrap_or_default(); - let named = named_rows(id, rows); - for (k, r) in rows.iter().enumerate() { - let (label, value) = (r[0].as_str().unwrap_or_default(), r[1].as_str().unwrap_or_default()); - if value.is_empty() { - if named.contains(&k) && !label.is_empty() { - if copy_value(ui, label, label, false) { - copy = Some(label.to_string()); + Stack::new().fill_width().show(ui, |ui, _| { + let title = s["title"].as_str().unwrap_or_default(); + let rows = s["rows"].as_array().map_or(&[][..], Vec::as_slice); + // Lists show how many they hold; the selection scope shows on the first. + let title = match s["id"].as_str() { + Some("document" | "objects") => tl!(title).to_string(), + _ => format!("{} ({})", tl!(title), rows.len()), + }; + let title = + if sel_only && n == 0 && category.is_empty() { crate::i18n::fmt(tl!("{title} (selection)"), &[("title", &title)]) } else { title }; + Text::new(title).role(TypeRole::Heading).show(ui); + if rows.is_empty() { + Text::new(tl!("None").to_string()).shade(Shade::Muted).show(ui); + } + let id = s["id"].as_str().unwrap_or_default(); + let named = named_rows(id, rows); + for (k, r) in rows.iter().enumerate() { + let (label, value) = (r[0].as_str().unwrap_or_default(), r[1].as_str().unwrap_or_default()); + if value.is_empty() { + if named.contains(&k) && !label.is_empty() { + if copy_value(ui, label, label, false) { + copy = Some(label.to_string()); + } + } else { + Text::new(super::label_or_name(label, !named.contains(&k)).to_string()).shade(Shade::Muted).show(ui); } } else { - Text::new(super::label_or_name(label, !named.contains(&k)).to_string()).shade(Shade::Muted).show(ui); - } - } else { - let shown = shown_value(&i, id, k, (label, value), named.contains(&k)).unwrap_or_else(|| value.to_string()); - if row(ui, super::label_or_name(label, !named.contains(&k)), &shown) { - copy = Some(shown); + let shown = shown_value(&i, id, k, (label, value), named.contains(&k)).unwrap_or_else(|| value.to_string()); + if row(ui, super::label_or_name(label, !named.contains(&k)), &shown) { + copy = Some(shown); + } } } - } + }); } }); if let Some(text) = copy { diff --git a/crates/ui-egui/src/panels/image_trace/rows.rs b/crates/ui-egui/src/panels/image_trace/rows.rs index 98aa304d2e..73f3034177 100644 --- a/crates/ui-egui/src/panels/image_trace/rows.rs +++ b/crates/ui-egui/src/panels/image_trace/rows.rs @@ -10,7 +10,7 @@ use craft::color_ui::ui::{ColorPopover, PickedColor}; use craft::theme::Srgba; use craft::ui::buttons::ToggleButton; use craft::ui::choice::{Checkbox, Segmented}; -use craft::ui::contract::{Bind, Entry, Props as _, Show as _, ShowContainer as _}; +use craft::ui::contract::{Bind, Entry, FieldLayout, Props as _, Show as _, ShowContainer as _}; use craft::ui::form::{Field, SliderField, SliderFieldLayout}; use craft::ui::layout_components::Row; use craft::ui::pickers::Select; @@ -265,7 +265,14 @@ pub(crate) fn advanced_rows(ui: &mut Ui, params: &mut Value, _data: &RowsData, _ Row::new().show(ui, |ui, _| { let mut hit = None; for (key, on, other, label) in [("fills", fills, strokes, tl!("Fills")), ("strokes", strokes, fills, tl!("Strokes"))] { - if check(ui, label, on, !on || other) { + // Inside the Create field a check box's own label is not drawn, so each box takes a field of + // its own with the label after it. + let enabled = !on || other; + let mut value = on; + Field::new(label).layout(FieldLayout::After).enabled(enabled).show(ui, |ui, _| { + Checkbox::new(Bind::bound(&mut value)).enabled(enabled).show(ui); + }); + if value != on { hit = Some(key); } } diff --git a/crates/ui-egui/src/panels/info.rs b/crates/ui-egui/src/panels/info.rs index 3c2df76111..c0986e921d 100644 --- a/crates/ui-egui/src/panels/info.rs +++ b/crates/ui-egui/src/panels/info.rs @@ -5,7 +5,7 @@ use craft::behavior::ColumnWidth; use craft::keymap::CommandRef; -use craft::ui::contract::{Show as _, ShowContainer as _}; +use craft::ui::contract::{Gap, Show as _, ShowContainer as _}; use craft::ui::display::{Divider, Picture}; use craft::ui::layout_components::{Grid, Row, Stack}; use craft::ui::list::ThumbAspect; @@ -249,34 +249,43 @@ const HALVES: &[ColumnWidth] = &[ColumnWidth::fill(1.0); 2]; pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) { let l = lines(app, ui.ctx()); let mut copy = None; - // Two equal halves of the panel, as the reference app's columns were. - let _ = Grid::new(HALVES).show(ui, |ui, _| { - for column in [&l.left, &l.right] { - Stack::new().show(ui, |ui, _| { - for s in column { - if mono(ui, s) { - copy = Some(s.clone()); + // The numbers, the paints and the type are groups a section gap sets apart from the dividers between them. + Stack::new().fill_width().gap(Gap::Section).show(ui, |ui, _| { + Stack::new().fill_width().show(ui, |ui, _| { + // Two equal halves of the panel, as the reference app's columns were. + let _ = Grid::new(HALVES).show(ui, |ui, _| { + for column in [&l.left, &l.right] { + Stack::new().show(ui, |ui, _| { + for s in column { + if mono(ui, s) { + copy = Some(s.clone()); + } + } + }); + } + }); + for s in l.zoom.iter().chain(&l.brush) { + if mono(ui, s) { + copy = Some(s.clone()); + } + } + }); + Divider::horizontal().show(ui); + Stack::new().fill_width().show(ui, |ui, _| { + copy = paint_block(ui, &l.fill).or(copy.take()); + copy = paint_block(ui, &l.stroke).or(copy.take()); + }); + if let Some((font, size)) = &l.type_block { + Divider::horizontal().show(ui); + Stack::new().fill_width().show(ui, |ui, _| { + for value in [font, size] { + if mono(ui, value) { + copy = Some(value.clone()); } } }); } }); - for s in l.zoom.iter().chain(&l.brush) { - if mono(ui, s) { - copy = Some(s.clone()); - } - } - Divider::horizontal().show(ui); - copy = paint_block(ui, &l.fill).or(copy); - copy = paint_block(ui, &l.stroke).or(copy); - if let Some((font, size)) = &l.type_block { - Divider::horizontal().show(ui); - for value in [font, size] { - if mono(ui, value) { - copy = Some(value.clone()); - } - } - } if let Some(text) = copy { app.clipboard_out = Some(text); app.status("Copied the value"); diff --git a/crates/ui-egui/src/panels/links.rs b/crates/ui-egui/src/panels/links.rs index 881129e87f..7bb641fe84 100644 --- a/crates/ui-egui/src/panels/links.rs +++ b/crates/ui-egui/src/panels/links.rs @@ -786,8 +786,17 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) { }); }) .show(ui, |ui, _| { - let empty = if o.show == "all" { tl!("No images") } else { tl!("Nothing matches the Show filter.") }; - let mut list = List::::new(tl!("Links")).selection(Bind::bound(&mut selection)).empty(empty).row_menu(); + // With no rows the body says how to bring an image in, as the other panels' empty states do. + if row_ids.is_empty() { + let detail = if o.show == "all" { + tl!("File › Place… brings in an image, linked or embedded.") + } else { + tl!("Nothing matches the Show filter.") + }; + super::empty_state(ui, "link", tl!("No images"), detail); + return; + } + let mut list = List::::new(tl!("Links")).selection(Bind::bound(&mut selection)).row_menu(); if let Some(id) = reveal { list = list.reveal(id); } diff --git a/crates/ui-egui/src/panels/tests_panel_spacing.rs b/crates/ui-egui/src/panels/tests_panel_spacing.rs new file mode 100644 index 0000000000..d93eefca3a --- /dev/null +++ b/crates/ui-egui/src/panels/tests_panel_spacing.rs @@ -0,0 +1,75 @@ +//! Headless frames of the Document Info, Info, Image Trace and Links panels: values line up, groups stand apart from +//! their dividers, every check box shows its label, and an empty Links panel says how to bring an image in. + +use egui::Rect; +use serde_json::json; + +use super::tests_appearance::{app_with_rect, run}; +use super::*; +use crate::tests::panel_harness::{Panel, ROOM}; + +/// The first run the latest frame painted that starts with `prefix`. +fn run_starting(panel: &Panel, prefix: &str) -> Rect { + let texts = panel.texts(); + texts.iter().find(|(t, _)| t.starts_with(prefix)).map(|(_, r)| *r).unwrap_or_else(|| panic!("no run starting {prefix:?} in {texts:?}")) +} + +/// The single run of `text` the latest frame painted. +fn one(panel: &Panel, text: &str) -> Rect { + let rects = panel.painted(text); + assert_eq!(rects.len(), 1, "{text:?} painted {} times in {:?}", rects.len(), panel.texts()); + rects[0] +} + +#[test] +fn document_info_values_end_at_one_edge() { + let mut panel = Panel::new(app_with_rect(), doc_info::show); + panel.frame(); + let ends: Vec = ["Untitled-1", "RGB", "Points"].iter().map(|v| one(&panel, v).right()).collect(); + for end in &ends { + assert!((end - ends[0]).abs() < 1.0, "the values end at {ends:?}, not at one edge"); + } + let (label, value) = (one(&panel, "Color Mode"), one(&panel, "RGB")); + assert!(value.left() > label.right() + label.width(), "the value {value:?} sits against its label {label:?}"); +} + +#[test] +fn info_paints_stand_a_section_apart_from_the_numbers() { + let mut app = app_with_rect(); + run(&mut app, "shape.rectangle", json!({"x": 150, "y": 60, "width": 80, "height": 50})); + run(&mut app, "select.all", json!({})); + let mut panel = Panel::new(app, info::show); + panel.frame(); + let numbers = run_starting(&panel, "D:"); + let paint = run_starting(&panel, "R:"); + let gap = paint.top() - numbers.bottom(); + assert!(gap >= numbers.height(), "the paints start {gap} below the numbers, closer than a line"); + // The two columns split the panel in halves: the right column starts at the panel's middle. + let (x, w) = (run_starting(&panel, "X:"), run_starting(&panel, "W:")); + let half = (ROOM.x - x.left()) / 2.0; + assert!(w.left() - x.left() >= half - 1.0, "W: starts {} in, before the half at {half}", w.left() - x.left()); +} + +#[test] +fn image_trace_create_shows_fills_and_strokes() { + let mut app = crate::testing::windowed(VectorcraftApp::new(vectorcraft_engine::Session::new(), Default::default())); + run(&mut app, "file.new", json!({"width": 200, "height": 200})); + app.ui.image_trace_advanced = true; + let mut panel = Panel::new(app, image_trace::show); + panel.frame(); + let create = one(&panel, "Create:"); + for label in ["Fills", "Strokes"] { + let at = one(&panel, label); + assert!(at.left() > create.right() && (at.center().y - create.center().y).abs() < create.height(), "{label} at {at:?}"); + } +} + +#[test] +fn empty_links_panel_says_how_to_bring_an_image_in() { + let mut app = crate::testing::windowed(VectorcraftApp::new(vectorcraft_engine::Session::new(), Default::default())); + run(&mut app, "file.new", json!({"width": 200, "height": 200})); + let mut panel = Panel::new(app, links::show); + panel.frame(); + one(&panel, "No images"); + one(&panel, "File › Place… brings in an image, linked or embedded."); +} diff --git a/crates/ui-egui/src/tests/panel_harness.rs b/crates/ui-egui/src/tests/panel_harness.rs index f1f58c89ad..b6eb72391e 100644 --- a/crates/ui-egui/src/tests/panel_harness.rs +++ b/crates/ui-egui/src/tests/panel_harness.rs @@ -360,6 +360,16 @@ impl Panel { (shapes, images) } + /// The runs of text the latest frame painted, with their rects. + pub(crate) fn texts(&self) -> Vec<(String, Rect)> { + self.fixture.texts().iter().map(|t| (t.text.clone(), t.rect)).collect() + } + + /// Where the latest frame painted `text` as a whole run. + pub(crate) fn painted(&self, text: &str) -> Vec { + self.texts().into_iter().filter(|(t, _)| t == text).map(|(_, r)| r).collect() + } + /// Where the control of `role` named `name` is, where nodes of other roles share the name. pub(crate) fn rect_role(&self, name: &str, role: craft::ui::contract::Role) -> Rect { self.look_role(name, role).rect From 85ce8013023066859489c59956428fcc67b36b3c Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sat, 28 Nov 2026 09:43:21 -0800 Subject: [PATCH 2/3] Panels: format the Document Info section title --- crates/ui-egui/src/panels/doc_info.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/crates/ui-egui/src/panels/doc_info.rs b/crates/ui-egui/src/panels/doc_info.rs index d116498346..ad8b8ce9f7 100644 --- a/crates/ui-egui/src/panels/doc_info.rs +++ b/crates/ui-egui/src/panels/doc_info.rs @@ -175,8 +175,11 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) { Some("document" | "objects") => tl!(title).to_string(), _ => format!("{} ({})", tl!(title), rows.len()), }; - let title = - if sel_only && n == 0 && category.is_empty() { crate::i18n::fmt(tl!("{title} (selection)"), &[("title", &title)]) } else { title }; + let title = if sel_only && n == 0 && category.is_empty() { + crate::i18n::fmt(tl!("{title} (selection)"), &[("title", &title)]) + } else { + title + }; Text::new(title).role(TypeRole::Heading).show(ui); if rows.is_empty() { Text::new(tl!("None").to_string()).shade(Shade::Muted).show(ui); From 592ad486db83fc03da4ff4f58be431d2adbb0688 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sat, 28 Nov 2026 13:09:52 -0800 Subject: [PATCH 3/3] Links: a Show filter that hides every image titles the panel No matching images Show Missing or another filter can leave the list empty while the document still holds images, and the empty panel said "No images". The filtered empty state now says "No matching images"; Show All keeps "No images". --- crates/ui-egui/src/panels/links.rs | 11 ++++++----- crates/ui-egui/src/panels/tests_links.rs | 14 ++++++++++++++ 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/crates/ui-egui/src/panels/links.rs b/crates/ui-egui/src/panels/links.rs index 7bb641fe84..ba3723a24e 100644 --- a/crates/ui-egui/src/panels/links.rs +++ b/crates/ui-egui/src/panels/links.rs @@ -786,14 +786,15 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) { }); }) .show(ui, |ui, _| { - // With no rows the body says how to bring an image in, as the other panels' empty states do. + // With no rows the body says how to bring an image in, as the other panels' empty states do; + // under a Show filter the document can still hold images that the filter hides. if row_ids.is_empty() { - let detail = if o.show == "all" { - tl!("File › Place… brings in an image, linked or embedded.") + let (title, detail) = if o.show == "all" { + (tl!("No images"), tl!("File › Place… brings in an image, linked or embedded.")) } else { - tl!("Nothing matches the Show filter.") + (tl!("No matching images"), tl!("Nothing matches the Show filter.")) }; - super::empty_state(ui, "link", tl!("No images"), detail); + super::empty_state(ui, "link", title, detail); return; } let mut list = List::::new(tl!("Links")).selection(Bind::bound(&mut selection)).row_menu(); diff --git a/crates/ui-egui/src/panels/tests_links.rs b/crates/ui-egui/src/panels/tests_links.rs index e1a60e1c45..e817ac9f36 100644 --- a/crates/ui-egui/src/panels/tests_links.rs +++ b/crates/ui-egui/src/panels/tests_links.rs @@ -203,6 +203,20 @@ fn opening_the_panel_on_the_selected_image_leaves_another_document_alone() { assert_eq!(h.state().ui.links.show, None, "the request is dropped"); } +/// A Show filter that hides every image titles the empty panel "No matching images", since the +/// document still holds images; "No images" stays for a document with none. +#[test] +fn a_filter_that_hides_every_image_says_no_matching_images() { + let dir = Folder::new("empty-filter-title"); + let (app, _, _) = app(&dir); + let mut h = rig(app); + command(&mut h, "ui.links.show", json!({"show": "missing"})); + assert!(shown(&h, "No matching images"), "Show Missing with nothing missing"); + assert!(!shown(&h, "No images"), "the document holds two images"); + command(&mut h, "ui.links.show", json!({"show": "all"})); + assert!(shown(&h, "linked.png") && !shown(&h, "No matching images"), "Show All lists the rows"); +} + /// A frame that fetches nothing keeps the stored rows and Link Info as they are, without a copy; the /// two-second recheck, another first selected image and an edit each store a new cache. #[test]