mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-27 16:59:43 +01:00
Document Info counts the selection when Selection Only is on.
The panel menu stores the toggle, and an empty selection says that nothing is selected. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
9fff48d88f
commit
bb66d9f5db
2 files changed
+114
-4
No files matched your search
@@ -32,6 +32,33 @@ pub(crate) fn row(ui: &mut Ui, label: &str, value: String) {
|
||||
});
|
||||
}
|
||||
|
||||
/// Panel memory for Selection Only. `docinfo-sel` is the earlier key; a value stored under
|
||||
/// `docinfo-selection-only` wins, and the menu writes both.
|
||||
const SELECTION_ONLY_KEY: &str = "docinfo-selection-only";
|
||||
const SELECTION_ONLY_LEGACY: &str = "docinfo-sel";
|
||||
|
||||
fn selection_only(ctx: &egui::Context) -> bool {
|
||||
ctx.data(|d| {
|
||||
let current = egui::Id::unique(("panel-state", SELECTION_ONLY_KEY));
|
||||
if let Some(on) = d.get_temp::<bool>(current) {
|
||||
return on;
|
||||
}
|
||||
d.get_temp::<bool>(egui::Id::unique(("panel-state", SELECTION_ONLY_LEGACY))).unwrap_or(false)
|
||||
})
|
||||
}
|
||||
|
||||
fn set_selection_only(ctx: &egui::Context, on: bool) {
|
||||
set_pstate(ctx, SELECTION_ONLY_KEY, on);
|
||||
set_pstate(ctx, SELECTION_ONLY_LEGACY, on);
|
||||
}
|
||||
|
||||
fn no_selection(app: &VectorcraftApp) -> bool {
|
||||
match app.session.active() {
|
||||
Some(st) => st.selection.objects.is_empty(),
|
||||
None => true,
|
||||
}
|
||||
}
|
||||
|
||||
/// `document.info` with its categories, fetched again only when the document, the scope or the
|
||||
/// artboards the Artboard tool has selected change.
|
||||
fn info(app: &mut VectorcraftApp, ctx: &egui::Context, sel_only: bool) -> Option<Value> {
|
||||
@@ -48,13 +75,16 @@ fn info(app: &mut VectorcraftApp, ctx: &egui::Context, sel_only: bool) -> Option
|
||||
}
|
||||
|
||||
pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) {
|
||||
let sel_only: bool = pstate(ui.ctx(), "docinfo-sel");
|
||||
let sel_only = selection_only(ui.ctx());
|
||||
let category: String = pstate(ui.ctx(), "docinfo-category");
|
||||
let Some(i) = info(app, ui.ctx(), sel_only) else {
|
||||
widgets::dim_label(ui, tl!("No document"));
|
||||
return;
|
||||
};
|
||||
egui::ScrollArea::vertical().max_height(420.0).show(ui, |ui| {
|
||||
if sel_only && no_selection(app) {
|
||||
widgets::dim_label(ui, tl!("(No selection)"));
|
||||
}
|
||||
let sections = i["sections"].as_array().map_or(&[][..], Vec::as_slice);
|
||||
let shown = sections.iter().filter(|s| category.is_empty() || s["id"] == category.as_str());
|
||||
for (n, s) in shown.enumerate() {
|
||||
@@ -310,9 +340,9 @@ pub(crate) fn save_report(app: &mut VectorcraftApp, p: &Value) -> Result<Value,
|
||||
}
|
||||
|
||||
pub fn menu(app: &mut VectorcraftApp, ui: &mut Ui) {
|
||||
let sel: bool = pstate(ui.ctx(), "docinfo-sel");
|
||||
let sel = selection_only(ui.ctx());
|
||||
if menu_item(ui, tl!("Selection Only"), true, sel) {
|
||||
set_pstate(ui.ctx(), "docinfo-sel", !sel);
|
||||
set_selection_only(ui.ctx(), !sel);
|
||||
}
|
||||
ui.separator();
|
||||
let category: String = pstate(ui.ctx(), "docinfo-category");
|
||||
@@ -732,4 +762,80 @@ mod tests {
|
||||
assert_eq!(in_lang("de", &json!({"type": "grid", "rows": 1, "cols": 3, "instances": 3})), "Rasterwiederholung, 1 Zeile × 3 Spalten");
|
||||
assert_eq!(repeat_value(&json!({"type": "spiral", "instances": 2})), None);
|
||||
}
|
||||
|
||||
/// Objects rows the panel paints with Selection Only `on`, the Objects category shown.
|
||||
fn objects_panel(app: &mut VectorcraftApp, on: bool) -> String {
|
||||
crate::tests_labels::painted_text(app, |app, ui| {
|
||||
set_selection_only(ui.ctx(), on);
|
||||
set_pstate(ui.ctx(), "docinfo-category", "objects".to_string());
|
||||
show(app, ui);
|
||||
})
|
||||
}
|
||||
|
||||
/// With Selection Only off, Objects counts every object in the document.
|
||||
#[test]
|
||||
fn test_doc_info_counts_entire_document() {
|
||||
let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), Default::default());
|
||||
app.session.execute("file.new", &json!({"width": 200, "height": 200})).unwrap();
|
||||
app.session.execute("shape.rectangle", &json!({"x": 10, "y": 10, "width": 40, "height": 20})).unwrap();
|
||||
app.session.execute("shape.rectangle", &json!({"x": 80, "y": 10, "width": 30, "height": 20})).unwrap();
|
||||
app.session.execute("text.create", &json!({"x": 10, "y": 80, "text": "Hi"})).unwrap();
|
||||
app.session.execute("select.none", &json!({})).unwrap();
|
||||
let text = objects_panel(&mut app, false);
|
||||
assert!(text.contains("Paths\n2\n") && text.contains("Text Objects\n1\n"), "{text}");
|
||||
assert!(!text.contains("(No selection)"), "{text}");
|
||||
}
|
||||
|
||||
/// Selection Only counts the selected object and what it holds, and an empty selection says so.
|
||||
#[test]
|
||||
fn test_doc_info_selection_only_toggles_and_filters_counts() {
|
||||
let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), Default::default());
|
||||
app.session.execute("file.new", &json!({"width": 200, "height": 200})).unwrap();
|
||||
let path = app.session.execute("shape.rectangle", &json!({"x": 10, "y": 10, "width": 40, "height": 20})).unwrap()["id"].clone();
|
||||
let text_id = app.session.execute("text.create", &json!({"x": 10, "y": 80, "text": "Hi"})).unwrap()["id"].clone();
|
||||
app.session.execute("select.set", &json!({"ids": [text_id]})).unwrap();
|
||||
let text = objects_panel(&mut app, true);
|
||||
assert!(text.contains("Text Objects\n1\n") && !text.contains("Paths\n"), "the selected type only: {text}");
|
||||
app.session.execute("select.set", &json!({"ids": [path]})).unwrap();
|
||||
let path_only = objects_panel(&mut app, true);
|
||||
assert!(path_only.contains("Paths\n1\n") && !path_only.contains("Text Objects\n"), "the selected path only: {path_only}");
|
||||
app.session.execute("select.none", &json!({})).unwrap();
|
||||
let empty = objects_panel(&mut app, true);
|
||||
assert!(empty.contains("(No selection)") && !empty.contains("Paths\n") && !empty.contains("Text Objects\n"), "{empty}");
|
||||
}
|
||||
|
||||
/// The panel menu's Selection Only item stores `docinfo-selection-only` and checks itself.
|
||||
#[test]
|
||||
fn test_doc_info_panel_menu_toggles_state() {
|
||||
let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), Default::default());
|
||||
app.session.execute("file.new", &json!({"width": 100, "height": 100})).unwrap();
|
||||
let ctx = egui::Context::default();
|
||||
crate::theme::install_fonts(&ctx);
|
||||
let click = |app: &mut VectorcraftApp| {
|
||||
let screen = egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(280.0, 800.0));
|
||||
let frame = |app: &mut VectorcraftApp, events: Vec<egui::Event>| {
|
||||
let mut out = ctx.run_ui(egui::RawInput { screen_rect: Some(screen), events, ..Default::default() }, |ui| menu(app, ui));
|
||||
out.textures_delta.clear();
|
||||
crate::tests_removeanchors::shapes_text(&out.shapes.iter().map(|c| c.shape.clone()).collect::<Vec<_>>())
|
||||
};
|
||||
let labels = frame(app, vec![]);
|
||||
let at = labels
|
||||
.iter()
|
||||
.find(|(t, _)| t.trim().trim_start_matches('✓').trim() == "Selection Only")
|
||||
.map(|(_, r)| r.center())
|
||||
.unwrap_or_else(|| panic!("no Selection Only in {labels:?}"));
|
||||
let button =
|
||||
|pressed| egui::Event::PointerButton { pos: at, button: egui::PointerButton::Primary, pressed, modifiers: egui::Modifiers::NONE };
|
||||
frame(app, vec![egui::Event::PointerMoved(at), button(true)]);
|
||||
frame(app, vec![button(false)]);
|
||||
};
|
||||
set_selection_only(&ctx, false);
|
||||
assert!(!selection_only(&ctx));
|
||||
click(&mut app);
|
||||
assert!(selection_only(&ctx));
|
||||
assert!(pstate::<bool>(&ctx, SELECTION_ONLY_KEY));
|
||||
click(&mut app);
|
||||
assert!(!selection_only(&ctx));
|
||||
assert!(!pstate::<bool>(&ctx, SELECTION_ONLY_KEY));
|
||||
}
|
||||
}
|
||||
+5
-1
@@ -1,6 +1,6 @@
|
||||
# Gaps
|
||||
|
||||
> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-11-20 · **Change:** minor (G12: Asset Export tile context menus; scores and estimates unchanged; previously: M14/G12: Appearance panel: right-click item context menus for rows (Duplicate, Delete, Hide/Show, Edit Effect, Clear Appearance, Reduce to Basic Appearance) with selection handling, #8809; previously: G12: Properties panel Quick Actions include contextual text actions (Create Outlines, Retype, Find and Replace…); scores and estimates unchanged; previously: G12: Actions panel item context menus for action sets (New Action…, New Set…, Duplicate Set, Delete Set, Set Options…) and actions (Play, Record, Duplicate, Delete, Action Options…, Batch…) with selection handling; clicking Duplicate on an action duplicates that action; headless tests in `crates/ui-egui/src/panels/actions.rs`; scores and estimates unchanged; previously: Scissors shows the actual proposed cut point while hovering, using its existing snapping and cut target (#8655); scores and estimates unchanged; previously: G12: Brushes panel: item right-click context menu (Brush Options, Duplicate Brush, Delete Brush) with selection handling; scores and estimates unchanged; previously: G12: Links panel row context menu (Relink…, Go To Link, Update Link, Edit Original, Show in Folder, Embed Image / Unembed…) with selection handling; scores and estimates unchanged; previously: Direct Selection: Space during an ordinary path's handle drag repositions its anchor and handles, including a Pen loan (#7237, request 3 only; scores and estimates unchanged); previously: SVG export preserves document units on root width/height for physical units, #864; G11 estimate 8–15 → 6–13 h; G4 and G13 Missing lists drop the shipped Touch Type, Snap to Glyph and Dimension tool, and G13's snapping entry keeps only what is still missing, the partial Snapping panel and the items not yet checked (#8387); G13 keeps one estimate (13–23 h); estimates unchanged; previously: Retype phase 1 (#4934): Type › Retype (`type.retype`) turns outlined text that exactly matches an available font back into point text; scores and estimates unchanged; previously: Production Preflight: output-aware fonts, text overflow, linked files and effective image resolution, clickable findings and automatic rechecking; scores and estimates unchanged; previously: PDF export writes the document language as the catalog's `/Lang`, #3644; Recolor Artwork follow-up (#8031, remaining #4028): native Lab input, picker swatch libraries and Assign-row menus; UI interaction regression coverage; scores and estimates unchanged; previously: Eraser review: hidden Rasterize and Along/Across stroke rows do not block preserving visible gradients; scores and estimates unchanged; previously: Eraser review: ordinary Group/Layer paints and reproducible evaluated gradient placements are preserved; other placements retain existing fitting; scores and estimates unchanged; previously: Eraser: shared fill-only area cutting for fixed and varied tips and the Alt-drag marquee, #6582; scores and estimates unchanged; previously: G4 type: modal Check Spelling dialog (Edit › Spelling › Check Spelling…), #4936; spell check complete; previously: Type: the Middle Eastern & South Asian composers are done as a per-paragraph choice with the Standard composers (#4935); G5: built-in Neon & Glow graphic style library (Cyan Neon, Magenta Laser, Amber Tube, Electric Lime, Pulse Violet, Cobalt Phosphor); estimate unchanged (3–13 h); previously: Tech Circuit brush library, G5; previously: G5: built-in Weather Icons symbol library (Sun, Moon, Cloud, Rain, Thunder, Snow); estimate 5–15 → 4–14 h; previously: 3D: the seams of white-light Extrude & Bevel, Inflate and Rotate, and the face seams of the 3D (Classic) effects, have round joins instead of miters; previously: PDF import: preserve Type 3 font text runs as named groups <g>, or as live text in TextAs::Text mode if ToUnicode exists on non-colour fonts (TextAs::Outlines produces grouped outlines), #6740; scores and estimates unchanged; previously: icon-strip flyouts also resize from the top edge and the canvas-side top corner, keeping the moved top in workspaces (storytold/craft-libs#1094); scores and estimates unchanged; previously: #6865: oversized editing artboard import; Glyphs panel: Alternates for Current Selection applies an OpenType feature value (`salt=2`) to the selected letter alone, so an Arabic word stays joined, and Entire Font lists the unencoded glyphs, #5514; #6404: transform-aware Eyedropper character copying; scores and estimates unchanged; previously: G5: built-in Energy Beams brush library; estimate 5–15 → 4–14 h; previously minor: G5: built-in Skill Icons symbol library; estimate 6–16 → 5–15 h; previously minor: ruler double-click adds a guide at the pointer, #5239; G5: built-in Status Effects graphic style library; estimate 7–17 → 6–16 h; MCP docs catch-up for UILine truncated
|
||||
> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-11-21 · **Change:** minor (G12: Document Info panel menu Selection Only (`docinfo-selection-only`) counts the selection, and an empty selection shows (No selection); scores and estimates unchanged; previously: G12: Asset Export tile context menus; scores and estimates unchanged; previously: M14/G12: Appearance panel: right-click item context menus for rows (Duplicate, Delete, Hide/Show, Edit Effect, Clear Appearance, Reduce to Basic Appearance) with selection handling, #8809; previously: G12: Properties panel Quick Actions include contextual text actions (Create Outlines, Retype, Find and Replace…); scores and estimates unchanged; previously: G12: Actions panel item context menus for action sets (New Action…, New Set…, Duplicate Set, Delete Set, Set Options…) and actions (Play, Record, Duplicate, Delete, Action Options…, Batch…) with selection handling; clicking Duplicate on an action duplicates that action; headless tests in `crates/ui-egui/src/panels/actions.rs`; scores and estimates unchanged; previously: Scissors shows the actual proposed cut point while hovering, using its existing snapping and cut target (#8655); scores and estimates unchanged; previously: G12: Brushes panel: item right-click context menu (Brush Options, Duplicate Brush, Delete Brush) with selection handling; scores and estimates unchanged; previously: G12: Links panel row context menu (Relink…, Go To Link, Update Link, Edit Original, Show in Folder, Embed Image / Unembed…) with selection handling; scores and estimates unchanged; previously: Direct Selection: Space during an ordinary path's handle drag repositions its anchor and handles, including a Pen loan (#7237, request 3 only; scores and estimates unchanged); previously: SVG export preserves document units on root width/height for physical units, #864; G11 estimate 8–15 → 6–13 h; G4 and G13 Missing lists drop the shipped Touch Type, Snap to Glyph and Dimension tool, and G13's snapping entry keeps only what is still missing, the partial Snapping panel and the items not yet checked (#8387); G13 keeps one estimate (13–23 h); estimates unchanged; previously: Retype phase 1 (#4934): Type › Retype (`type.retype`) turns outlined text that exactly matches an available font back into point text; scores and estimates unchanged; previously: Production Preflight: output-aware fonts, text overflow, linked files and effective image resolution, clickable findings and automatic rechecking; scores and estimates unchanged; previously: PDF export writes the document language as the catalog's `/Lang`, #3644; Recolor Artwork follow-up (#8031, remaining #4028): native Lab input, picker swatch libraries and Assign-row menus; UI interaction regression coverage; scores and estimates unchanged; previously: Eraser review: hidden Rasterize and Along/Across stroke rows do not block preserving visible gradients; scores and estimates unchanged; previously: Eraser review: ordinary Group/Layer paints and reproducible evaluated gradient placements are preserved; other placements retain existing fitting; scores and estimates unchanged; previously: Eraser: shared fill-only area cutting for fixed and varied tips and the Alt-drag marquee, #6582; scores and estimates unchanged; previously: G4 type: modal Check Spelling dialog (Edit › Spelling › Check Spelling…), #4936; spell check complete; previously: Type: the Middle Eastern & South Asian composers are done as a per-paragraph choice with the Standard composers (#4935); G5: built-in Neon & Glow graphic style library (Cyan Neon, Magenta Laser, Amber Tube, Electric Lime, Pulse Violet, Cobalt Phosphor); estimate unchanged (3–13 h); previously: Tech Circuit brush library, G5; previously: G5: built-in Weather Icons symbol library (Sun, Moon, Cloud, Rain, Thunder, Snow); estimate 5–15 → 4–14 h; previously: 3D: the seams of white-light Extrude & Bevel, Inflate and Rotate, and the face seams of the 3D (Classic) effects, have round joins instead of miters; previously: PDF import: preserve Type 3 font text runs as named groups <g>, or as live text in TextAs::Text mode if ToUnicode exists on non-colour fonts (TextAs::Outlines produces grouped outlines), #6740; scores and estimates unchanged; previously: icon-strip flyouts also resize from the top edge and the canvas-side top corner, keeping the moved top in workspaces (storytold/craft-libs#1094); scores and estimates unchanged; previously: #6865: oversized editing artboard import; Glyphs panel: Alternates for Current Selection applies an OpenType feature value (`salt=2`) to the selected letter alone, so an Arabic word stays joined, and Entire Font lists the unencoded glyphs, #5514; #6404: transform-aware Eyedropper character copying; scores and estimates unchanged; previously: G5: built-in Energy Beams brush library; estimate 5–15 → 4–14 h; previously minor: G5: built-in Skill Icons symbol library; estimate 6–16 → 5–1Line truncated
|
||||
|
||||
> Scissors snapping update (2026-11-11): with Alt released, hover and cuts use the Pen's path, alignment, intersection and anchor snaps (#6470). Scores and estimates unchanged.
|
||||
|
||||
@@ -58,6 +58,7 @@ Artboard Options forwards the active Artboard tool's Scale Artwork with Artboard
|
||||
|
||||
| Date | Change | Summary |
|
||||
|---|---|---|
|
||||
| 2026-11-21 | minor | G12: Document Info › Selection Only (`docinfo-selection-only`) counts objects in the selection through `document.info`; an empty selection shows (No selection). Headless regressions: `panels::doc_info::tests::test_doc_info_counts_entire_document`, `test_doc_info_selection_only_toggles_and_filters_counts`, `test_doc_info_panel_menu_toggles_state`. Scores and estimates unchanged. |
|
||||
| 2026-11-20 | minor | G12: Asset Export tiles have item context menus for Export, Remove, Rename, Select Artwork on Canvas and collecting selected artwork; right-click selects an unselected tile and preserves an existing multi-selection. Headless regressions: panels::tests_asset_export. Scores and estimates unchanged. |
|
||||
| 2026-11-20 | minor | G12: Properties panel Quick Actions include contextual text actions (Create Outlines, Retype, Find and Replace…); headless tests in crates/ui-egui/src/panels/properties/tests.rs; scores and estimates unchanged. |
|
||||
| 2026-11-20 | minor | G12: Actions panel item context menus for action sets (New Action…, New Set…, Duplicate Set, Delete Set, Set Options…) and actions (Play, Record, Duplicate, Delete, Action Options…, Batch…) with selection handling; clicking Duplicate on an action duplicates that action; headless tests in `crates/ui-egui/src/panels/actions.rs`; scores and estimates unchanged. |
|
||||
@@ -522,6 +523,8 @@ macOS cursor delivery (#2292) is narrowed to a native host adapter using the exi
|
||||
|
||||
## G12 Preferences and panels that don't act yet
|
||||
|
||||
- **Implemented and tested (2026-11-21):** Document Info's panel menu Selection Only (`docinfo-selection-only`, still written to the earlier `docinfo-sel` key) asks `document.info` for the selection: object counts cover the selected nodes and their descendants, and an empty selection shows `(No selection)` instead of the document's counts. With the item off, counts stay for the whole document. Headless regressions: `panels::doc_info::tests::test_doc_info_counts_entire_document`, `test_doc_info_selection_only_toggles_and_filters_counts` and `test_doc_info_panel_menu_toggles_state`. Scores and estimates unchanged.
|
||||
|
||||
- **Implemented (2026-11-20):** Asset Export tiles have item context menus: Export and Remove act on the asset selection (plural labels for multiple assets), Rename opens the clicked tile's inline field, Select Artwork on Canvas selects that tile's source nodes, and Add Selected Artwork as One Asset / Multiple Assets are enabled with canvas selection. A right-click selects an unselected tile, clearing the previous asset selection, and preserves a multi-selection when the tile is already selected. Export reuses the raster/3D export path; Remove is one undo step and keeps the artwork. Headless regression coverage: `crates/ui-egui/src/panels/tests_asset_export.rs`. Other G12 panel gaps remain; scores and estimates unchanged.
|
||||
|
||||
- **Implemented and tested (2026-11-20):** Appearance panel row context menus: right-clicking stroke and fill rows offers Duplicate Stroke / Duplicate Fill, Delete Stroke / Delete Fill, and Hide Stroke/Show Stroke / Hide Fill/Show Fill; effect rows offer Edit Effect…, Duplicate Effect, Delete Effect, and Hide Effect / Show Effect; the root object row offers Clear Appearance and Reduce to Basic Appearance. Right-clicking an unselected row targets that row before presenting the menu. Item actions run in one undo step. Headless regression coverage: `crates/ui-egui/src/panels/tests_appearance.rs`. Scores and estimates unchanged.
|
||||
@@ -984,6 +987,7 @@ trap, and the defaults (0.25 pt, 100%, 40%) are VectorCraft's own, the pages giv
|
||||
|
||||
| Date | Change | Summary |
|
||||
|---|---|---|
|
||||
| 2026-11-21 | minor | G12: Document Info › Selection Only (`docinfo-selection-only`) counts objects in the selection through `document.info`; an empty selection shows (No selection). Headless regressions: `panels::doc_info::tests::test_doc_info_counts_entire_document`, `test_doc_info_selection_only_toggles_and_filters_counts`, `test_doc_info_panel_menu_toggles_state`. Scores and estimates unchanged. |
|
||||
| 2026-11-20 | minor | G12: Asset Export tiles have item context menus for Export, Remove, Rename, Select Artwork on Canvas and collecting selected artwork; right-click selects an unselected tile and preserves an existing multi-selection. Headless regressions: panels::tests_asset_export. Scores and estimates unchanged. |
|
||||
| 2026-11-20 | minor | G12: Appearance panel: right-click item context menus for rows (Duplicate Stroke/Fill, Delete Stroke/Fill, Hide/Show Stroke/Fill, Edit Effect…, Duplicate Effect, Delete Effect, Hide/Show Effect, Clear Appearance, Reduce to Basic Appearance) with selection handling; headless tests in `crates/ui-egui/src/panels/tests_appearance.rs`; scores and estimates unchanged. |
|
||||
| 2026-11-19 | minor | Scissors previews its actual anchor or curve cut point with a native point marker while hovering, retaining existing snapping, Alt Add Anchor and cut behavior (#8655). Scores and estimates unchanged. |
|
||||
|
||||
Reference in new issue
Block a user