mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-24 18:32:23 +00:00
View: Trim View hides the guides and the grid while it is on (#8363)
Trim View only clipped the art to the artboards: ruler guides, paths made into guides and the grid still drew across the pasteboard. Public forum threads describe Trim View hiding them, with Show Guides and Show Grid unavailable until it is off. ViewFlags::guides_shown() and grid_shown() now say whether they draw, and the canvas, the tiled panes, the art raster, hit testing and the tools' snapping read them. Show/Hide Guides and Show/Hide Grid are greyed out while Trim View is on (menu bar, canvas context menu, Properties) and refuse to run; the stored choices are kept, so they come back as they were. A selected guide path is deselected when Trim View hides it, as Hide Guides does. The rulers stay. Fixes #8363
This commit is contained in:
@@ -122,7 +122,7 @@ impl VectorcraftApp {
|
||||
zoom: self.view().map_or(1.0, |v| v.screen_zoom(self.canvas_ui_zoom)),
|
||||
outline: self.outline_view(),
|
||||
smart_guides: self.ui.view.smart_guides,
|
||||
guides: self.ui.view.guides,
|
||||
guides: self.ui.view.guides_shown(),
|
||||
snap_to_grid: self.ui.view.snap_to_grid,
|
||||
pixel_preview: self.ui.view.pixel_preview,
|
||||
snap_to_pixel: self.ui.view.snap_to_pixel,
|
||||
|
||||
@@ -322,7 +322,7 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) {
|
||||
|
||||
paint_paper(app, st, ui, &painter, &xf, rect, (&t, app.outline_view()));
|
||||
// The grid behind the art (Guides & Grid › Grids In Back), else over it below.
|
||||
let grid_look = (app.ui.view.grid && !presenting).then(|| LineLook::grid(&app.session.prefs));
|
||||
let grid_look = (app.ui.view.grid_shown() && !presenting).then(|| LineLook::grid(&app.session.prefs));
|
||||
let grids_in_back = app.session.prefs.grids_in_back;
|
||||
if let Some(look) = grid_look.filter(|_| grids_in_back) {
|
||||
grid(&painter, &xf, doc.grid.spacing, doc.grid.subdivisions, look);
|
||||
@@ -410,7 +410,7 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) {
|
||||
grid(&painter, &xf, 1.0, 1, LineLook { color: PIXEL_GRID, dots: false });
|
||||
}
|
||||
artboard_outlines(app, ui, &painter, &xf, &t);
|
||||
if app.ui.view.guides {
|
||||
if app.ui.view.guides_shown() {
|
||||
guide_lines(app, &painter, &xf, rect, &t);
|
||||
}
|
||||
nine_slice_overlay(app, &painter, &xf);
|
||||
@@ -627,7 +627,7 @@ fn cache_key(
|
||||
outline: app.outline_view(),
|
||||
trim: app.ui.view.trim_view,
|
||||
templates: app.ui.view.templates,
|
||||
guides: app.ui.view.guides,
|
||||
guides: app.ui.view.guides_shown(),
|
||||
ppp,
|
||||
hidden: vec![],
|
||||
rot: v.rotation,
|
||||
@@ -827,7 +827,7 @@ fn frame_options(
|
||||
overprint_preview: vectorcraft_render::proof::overprint_preview_on(),
|
||||
trim: app.ui.view.trim_view,
|
||||
hide_templates: !app.ui.view.templates,
|
||||
hide_guides: !app.ui.view.guides,
|
||||
hide_guides: !app.ui.view.guides_shown(),
|
||||
tile_edge: vectorcraft_color::Color::from_hex(&app.session.prefs.pattern_tile_edge_color).map_or(opts.tile_edge, |c| {
|
||||
let [r, g, b, _] = c.to_rgba8(1.0);
|
||||
[r, g, b]
|
||||
|
||||
@@ -188,7 +188,7 @@ pub(super) fn hit_with<T>(
|
||||
path_only: prefs.object_selection_by_path_only,
|
||||
type_path_only: prefs.type_selection_by_path_only,
|
||||
scope: app.session.active().and_then(|st| st.isolation),
|
||||
skip_guides: !app.ui.view.guides,
|
||||
skip_guides: !app.ui.view.guides_shown(),
|
||||
..Default::default()
|
||||
};
|
||||
test(&app.session.active()?.doc, p, opt)
|
||||
|
||||
@@ -554,7 +554,7 @@ fn draw_pane(app: &mut VectorcraftApp, ui: &Ui, w: Win, cell: egui::Rect) -> boo
|
||||
let xf = Xf::at(rect, &v, ui_zoom);
|
||||
let painter = ui.painter_at(rect);
|
||||
paint_paper(app, st, ui, &painter, &xf, rect, (&t, v.outline));
|
||||
let grid_look = app.ui.view.grid.then(|| LineLook::grid(&app.session.prefs));
|
||||
let grid_look = app.ui.view.grid_shown().then(|| LineLook::grid(&app.session.prefs));
|
||||
let grids_in_back = app.session.prefs.grids_in_back;
|
||||
if let Some(look) = grid_look.filter(|_| grids_in_back) {
|
||||
grid(&painter, &xf, st.doc.grid.spacing, st.doc.grid.subdivisions, look);
|
||||
@@ -587,7 +587,7 @@ fn draw_pane(app: &mut VectorcraftApp, ui: &Ui, w: Win, cell: egui::Rect) -> boo
|
||||
if shows_artboards(app) {
|
||||
artboard_edges(app, &st.doc, (&painter, &xf, &t), (v.artboard, dim_on_canvas(&t, v.outline)), |_| false);
|
||||
}
|
||||
if app.ui.view.guides {
|
||||
if app.ui.view.guides_shown() {
|
||||
guides_of(app, st, (&painter, &xf, &t), rect);
|
||||
}
|
||||
if app.ui.view.edges {
|
||||
|
||||
@@ -15290,3 +15290,57 @@ fn auto_spell_check_is_a_toggle_of_the_canvas_lines() {
|
||||
assert_eq!(count(&mut app), 0, "off");
|
||||
assert!(app.canvas.spelling.lines.is_empty(), "no node is kept");
|
||||
}
|
||||
|
||||
/// #8363: Trim View hides the ruler guides, the guide paths and the grid while it is on, and they
|
||||
/// are neither snapped to nor picked, as hidden guides are; turned off, they come back as they
|
||||
/// were. The rulers stay.
|
||||
#[test]
|
||||
fn trim_view_hides_the_guides_and_the_grid() {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.canvas.worker_started = true; // render on this thread
|
||||
app.session.execute("file.new", &json!({"width": 400, "height": 300})).unwrap();
|
||||
app.session.execute("guide.add", &json!({"vertical": true, "pos": 100})).unwrap();
|
||||
app.run("shape.rectangle", json!({"x": 150, "y": 100, "width": 100, "height": 100})).unwrap();
|
||||
app.run("view.guides.make", json!({})).unwrap();
|
||||
app.run("select.none", json!({})).unwrap();
|
||||
(app.ui.view.grid, app.ui.view.guides, app.ui.view.rulers) = (true, true, true);
|
||||
let (red, green) = (Color32::from_rgb(255, 0, 0), Color32::from_rgb(0, 255, 0));
|
||||
app.session.execute("prefs.set", &json!({"values": {"gridColor": "#ff0000", "guideColor": "#00ff00"}})).unwrap();
|
||||
let ctx = egui::Context::default();
|
||||
// → (a gridline, a ruler guide, guide paths in the art, guides snapped to and picked).
|
||||
let drawn = |app: &mut VectorcraftApp| {
|
||||
let s = shapes(app, &ctx);
|
||||
let line = |c: Color32| s.iter().any(|s| matches!(s, Shape::LineSegment { stroke, .. } if stroke.color == c));
|
||||
let guide_paths = !app.canvas.shown.as_ref().unwrap().1.hide_guides;
|
||||
(line(red), line(green), guide_paths, app.view_info().guides)
|
||||
};
|
||||
assert_eq!(drawn(&mut app), (true, true, true, true), "Trim View off: all of them");
|
||||
|
||||
app.run("view.trimView", json!({})).unwrap();
|
||||
assert_eq!(drawn(&mut app), (false, false, false, false), "Trim View on: none of them");
|
||||
assert!(app.ui.view.grid && app.ui.view.guides && app.ui.view.rulers, "the choices stay, and so do the rulers");
|
||||
|
||||
app.run("view.trimView", json!({})).unwrap();
|
||||
assert_eq!(drawn(&mut app), (true, true, true, true), "Trim View off: back as they were");
|
||||
|
||||
// Hidden before, they stay hidden after.
|
||||
app.run("view.guides", json!({})).unwrap();
|
||||
app.run("view.trimView", json!({})).unwrap();
|
||||
app.run("view.trimView", json!({})).unwrap();
|
||||
assert_eq!(drawn(&mut app), (true, false, false, false), "guides hidden before Trim View stay hidden");
|
||||
}
|
||||
|
||||
/// #8363: a selected guide path is deselected when Trim View hides it, as Hide Guides does (#3219).
|
||||
#[test]
|
||||
fn trim_view_deselects_selected_guide_paths() {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.run("file.new", json!({"width": 400, "height": 300})).unwrap();
|
||||
let id = app.run("shape.rectangle", json!({"x": 100, "y": 100, "width": 100, "height": 100})).unwrap()["id"].as_u64().unwrap();
|
||||
app.run("view.guides.make", json!({})).unwrap();
|
||||
app.run("select.set", json!({"ids": [id]})).unwrap();
|
||||
assert_eq!(app.session.active().unwrap().selection.objects, vec![vectorcraft_doc::NodeId(id)]);
|
||||
|
||||
app.run("view.trimView", json!({})).unwrap();
|
||||
|
||||
assert!(app.session.active().unwrap().selection.objects.is_empty());
|
||||
}
|
||||
|
||||
@@ -268,8 +268,9 @@ fn isolatable(app: &VectorcraftApp, doc: &vectorcraft_doc::Document, n: &vectorc
|
||||
&& doc.symbol_edit.as_ref().is_none_or(|e| doc.ancestry(target).is_some_and(|a| a.contains(&e.layer)))
|
||||
}
|
||||
|
||||
/// `items` without the commands that can't run now (Undo and Redo stay, greyed out), submenus
|
||||
/// left empty, and separators that no longer separate anything.
|
||||
/// `items` without the commands that can't run now (Undo and Redo stay, greyed out, and so do Show
|
||||
/// Grid and Hide Guides while Trim View holds them off: #8363), submenus left empty, and separators
|
||||
/// that no longer separate anything.
|
||||
fn prune(app: &VectorcraftApp, items: Vec<Item>) -> Vec<Item> {
|
||||
let mut out: Vec<Item> = Vec::with_capacity(items.len());
|
||||
for it in items {
|
||||
@@ -278,7 +279,7 @@ fn prune(app: &VectorcraftApp, items: Vec<Item>) -> Vec<Item> {
|
||||
it => it,
|
||||
};
|
||||
let keep = match &it {
|
||||
Item::Cmd(_, id, _) => matches!(*id, "edit.undo" | "edit.redo") || enabled(app, id),
|
||||
Item::Cmd(_, id, _) => matches!(*id, "edit.undo" | "edit.redo" | "view.guides" | "view.grid") || enabled(app, id),
|
||||
Item::Sub(_, children) => !children.is_empty(),
|
||||
Item::Sep => out.last().is_some_and(|l| !matches!(l, Item::Sep)),
|
||||
_ => true,
|
||||
|
||||
@@ -135,6 +135,26 @@ pub fn run_ui_command(app: &mut VectorcraftApp, id: &str, p: &Value) -> Option<R
|
||||
.or_else(|| run_ui_part13(app, id, p))
|
||||
}
|
||||
|
||||
/// Why Show/Hide Guides and Show/Hide Grid refuse to run while Trim View is on.
|
||||
const TRIM_VIEW_HIDES: &str = "Trim View hides the guides and the grid; turn it off first";
|
||||
|
||||
/// Drops the selection when it holds ruler guides or guide paths that no longer draw (Hide Guides,
|
||||
/// Trim View): their selection overlay would otherwise reveal the geometry just hidden.
|
||||
fn deselect_hidden_guides(app: &mut VectorcraftApp) {
|
||||
let hidden_selection = !app.ui.view.guides_shown()
|
||||
&& app.session.active().is_some_and(|d| {
|
||||
!d.selection.guides.is_empty()
|
||||
|| d.selection
|
||||
.objects
|
||||
.iter()
|
||||
.any(|id| matches!(d.doc.node(*id).map(|n| &n.kind), Some(vectorcraft_doc::NodeKind::Path { guide: true, .. })))
|
||||
});
|
||||
if hidden_selection {
|
||||
// Deselecting a document that is open cannot fail.
|
||||
let _ = app.run("select.none", json!({}));
|
||||
}
|
||||
}
|
||||
|
||||
/// UI commands, part 1.
|
||||
fn run_ui_part1(app: &mut VectorcraftApp, id: &str, p: &Value) -> Option<Result<Value, String>> {
|
||||
let s = |k: &str| p.get(k).and_then(Value::as_str).map(str::to_string);
|
||||
@@ -292,7 +312,12 @@ fn run_ui_part3(app: &mut VectorcraftApp, id: &str, p: &Value) -> Option<Result<
|
||||
};
|
||||
let r = match id {
|
||||
"view.pixelPreview" => flag(&mut app.ui.view.pixel_preview),
|
||||
"view.trimView" => flag(&mut app.ui.view.trim_view),
|
||||
// Trim View hides the guides while it is on (#8363), and hidden guides cannot stay selected.
|
||||
"view.trimView" => {
|
||||
let r = flag(&mut app.ui.view.trim_view);
|
||||
deselect_hidden_guides(app);
|
||||
r
|
||||
}
|
||||
"view.cornerWidget" => flag(&mut app.ui.view.corner_widgets),
|
||||
// Hide/Show Shape Widgets: `on` sets the state, and without it the state flips.
|
||||
"view.shapeWidgets" => opt_bool(p, "on").map(|on| {
|
||||
@@ -403,22 +428,12 @@ fn run_ui_part4(app: &mut VectorcraftApp, id: &str, _p: &Value) -> Option<Result
|
||||
Ok(json!(show))
|
||||
}
|
||||
"view.boundingBox" => flag(&mut app.ui.view.bounding_box),
|
||||
// Trim View hides the guides and the grid while it is on, and their Show/Hide items wait
|
||||
// until it is off (#8363).
|
||||
"view.guides" | "view.grid" if app.ui.view.trim_view => Err(TRIM_VIEW_HIDES.into()),
|
||||
"view.guides" => {
|
||||
let r = flag(&mut app.ui.view.guides);
|
||||
// Hidden ruler guides and guide paths cannot stay selected: their selection overlay
|
||||
// would otherwise reveal geometry that Hide Guides just hid.
|
||||
let hidden_selection = !app.ui.view.guides
|
||||
&& app.session.active().is_some_and(|d| {
|
||||
!d.selection.guides.is_empty()
|
||||
|| d.selection
|
||||
.objects
|
||||
.iter()
|
||||
.any(|id| matches!(d.doc.node(*id).map(|n| &n.kind), Some(vectorcraft_doc::NodeKind::Path { guide: true, .. })))
|
||||
});
|
||||
if hidden_selection {
|
||||
// Deselecting a document that is open cannot fail.
|
||||
let _ = app.run("select.none", json!({}));
|
||||
}
|
||||
deselect_hidden_guides(app);
|
||||
r
|
||||
}
|
||||
"view.smartGuides" => flag(&mut app.ui.view.smart_guides),
|
||||
|
||||
@@ -338,6 +338,9 @@ pub fn enabled(app: &VectorcraftApp, id: &str) -> bool {
|
||||
"file.exportSelection" => app.session.active().is_some_and(|d| !d.selection.is_empty()),
|
||||
"css.copy" | "css.exportFile" => app.session.active().is_some(),
|
||||
"print.printerSetup" => app.services.print.as_ref().is_some_and(|s| s.has_setup()),
|
||||
// Trim View hides the guides and the grid while it is on, so their Show/Hide items wait
|
||||
// until it is off (#8363).
|
||||
"view.guides" | "view.grid" => !app.ui.view.trim_view,
|
||||
"view.refreshMonitorProfile" => app.session.prefs.monitor_profile_display && app.display_profile.has_reader(),
|
||||
"plugin.dialog" => app.session.active().is_some(),
|
||||
"ui.perspectiveGridDialog" | "ui.savePerspectivePreset" => app.session.active().is_some(),
|
||||
|
||||
@@ -1745,3 +1745,43 @@ fn selection_tools_toggle_propagates_a_failed_valid_choice() {
|
||||
}
|
||||
assert_eq!(failures, vec![Err(failure.to_string()), Err(failure.to_string())], "both failed valid choices must reach the command caller");
|
||||
}
|
||||
|
||||
/// #8363: while Trim View is on, View › Guides › Show/Hide Guides and View › Show/Hide Grid are
|
||||
/// greyed out (in the menu bar, on their keys and in the canvas context menu, where they stay
|
||||
/// listed), refuse to run and leave the choices they keep alone; turning it off brings them back.
|
||||
#[test]
|
||||
fn trim_view_greys_out_show_guides_and_show_grid() {
|
||||
let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), crate::Services::default());
|
||||
app.run("file.new", json!({"width": 400, "height": 300})).unwrap();
|
||||
app.ui.view.grid = true;
|
||||
let listed = |app: &VectorcraftApp, id: &str| {
|
||||
fn find(items: &[Item], id: &str) -> bool {
|
||||
items.iter().any(|it| match it {
|
||||
Item::Cmd(_, c, _) => *c == id,
|
||||
Item::Sub(_, children) => find(children, id),
|
||||
_ => false,
|
||||
})
|
||||
}
|
||||
find(&context_items(app), id)
|
||||
};
|
||||
for id in ["view.guides", "view.grid"] {
|
||||
assert!(enabled(&app, id), "{id} runs with Trim View off");
|
||||
assert!(listed(&app, id), "{id} is in the canvas context menu");
|
||||
}
|
||||
|
||||
app.run("view.trimView", json!({})).unwrap();
|
||||
for id in ["view.guides", "view.grid"] {
|
||||
assert!(!enabled(&app, id), "{id} is greyed out while Trim View is on");
|
||||
assert!(listed(&app, id), "{id} stays in the canvas context menu, greyed out");
|
||||
assert!(app.run(id, json!({})).is_err(), "{id} does not run while Trim View is on");
|
||||
}
|
||||
assert!(app.ui.view.guides && app.ui.view.grid, "the choices stay as they were");
|
||||
assert_eq!((checked(&app, "view.grid", &Value::Null), dynamic_label(&app, "view.guides", "Show Guides").as_str()), (Some(true), "Hide Guides"));
|
||||
|
||||
app.run("view.trimView", json!({})).unwrap();
|
||||
for id in ["view.guides", "view.grid"] {
|
||||
assert!(enabled(&app, id), "{id} runs again with Trim View off");
|
||||
}
|
||||
app.run("view.guides", json!({})).unwrap();
|
||||
assert!(!app.ui.view.guides);
|
||||
}
|
||||
|
||||
@@ -767,7 +767,9 @@ fn document_sections(app: &mut VectorcraftApp, ui: &mut Ui) {
|
||||
if widgets::icon_button(ui, "ruler", tl!("Show Rulers (⌘R)"), v.rulers, 26.0).clicked() {
|
||||
app.run("view.rulers", json!({})).ok();
|
||||
}
|
||||
if widgets::icon_button(ui, "grid-3x3", tl!("Show Grid (⌘')"), v.grid, 26.0).clicked() {
|
||||
// Trim View holds the grid and the guides off while it is on (#8363).
|
||||
let shows = crate::menus::enabled(app, "view.grid");
|
||||
if widgets::icon_button_enabled(ui, "grid-3x3", tl!("Show Grid (⌘')"), v.grid, shows, 26.0).clicked() {
|
||||
app.run("view.grid", json!({})).ok();
|
||||
}
|
||||
let transparency_grid = app.session.active().is_some_and(|d| d.transparency_grid);
|
||||
@@ -779,7 +781,8 @@ fn document_sections(app: &mut VectorcraftApp, ui: &mut Ui) {
|
||||
section_header(ui, tl!("Guides"));
|
||||
ui.horizontal(|ui| {
|
||||
let v = app.ui.view.clone();
|
||||
if widgets::icon_button(ui, "layout-grid", tl!("Show Guides"), v.guides, 26.0).clicked() {
|
||||
let shows = crate::menus::enabled(app, "view.guides");
|
||||
if widgets::icon_button_enabled(ui, "layout-grid", tl!("Show Guides"), v.guides, shows, 26.0).clicked() {
|
||||
app.run("view.guides", json!({})).ok();
|
||||
}
|
||||
if widgets::icon_button(ui, "sparkles", tl!("Smart Guides (⌘U)"), v.smart_guides, 26.0).clicked() {
|
||||
|
||||
@@ -340,6 +340,19 @@ impl Default for ViewFlags {
|
||||
}
|
||||
}
|
||||
|
||||
impl ViewFlags {
|
||||
/// Whether the ruler guides and guide paths draw: View › Show Guides, unless Trim View hides
|
||||
/// them while it is on (#8363). `guides` keeps the choice, so they come back as they were.
|
||||
pub fn guides_shown(&self) -> bool {
|
||||
self.guides && !self.trim_view
|
||||
}
|
||||
|
||||
/// Whether the grid draws: View › Show Grid, unless Trim View hides it while it is on (#8363).
|
||||
pub fn grid_shown(&self) -> bool {
|
||||
self.grid && !self.trim_view
|
||||
}
|
||||
}
|
||||
|
||||
/// An open modal dialog. `fields` are string-valued so agents can set them uniformly.
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
pub struct Dialog {
|
||||
|
||||
+3
-2
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+3
-1
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user