Merge pull request #9963 from dotCooCoo/fix/ui-sweep-dock-panels-b

Panels: Document Info values line up, Image Trace Create shows its labels, and Info and Links keep their spacing
This commit is contained in:
.CooCoo authored and GitHub committed 2026-11-28 14:27:47 -08:00
commit 2c84465fba
8 files changed
+194 -59

No files matched your search

+2
View File
@@ -1255,6 +1255,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;
+39 -31
View File
@@ -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,43 @@ 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 {
@@ -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);
}
}
+33 -24
View File
@@ -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");
+12 -2
View File
@@ -786,8 +786,18 @@ 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::<u64>::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;
// under a Show filter the document can still hold images that the filter hides.
if row_ids.is_empty() {
let (title, detail) = if o.show == "all" {
(tl!("No images"), tl!("File › Place… brings in an image, linked or embedded."))
} else {
(tl!("No matching images"), tl!("Nothing matches the Show filter."))
};
super::empty_state(ui, "link", title, detail);
return;
}
let mut list = List::<u64>::new(tl!("Links")).selection(Bind::bound(&mut selection)).row_menu();
if let Some(id) = reveal {
list = list.reveal(id);
}
+14
View File
@@ -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]
@@ -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<f32> = ["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.");
}
+10
View File
@@ -373,6 +373,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<Rect> {
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