Fix Show and Hide Guides (#3219)

This commit is contained in:
Mirko Kerezovic
2026-10-21 15:42:35 +07:00
committed by bflatastic
parent 0782248cff
commit 2305ebb931
4 changed files with 52 additions and 5 deletions
+7 -3
View File
@@ -125,6 +125,9 @@ pub struct RenderOptions {
pub skip_templates: bool,
/// View › Hide Template: template layers left out of the screen view (guides stay).
pub hide_templates: bool,
/// View › Hide Guides: paths made into guides left out of the screen view. Exports use
/// `skip_templates`, which independently leaves both templates and guides out.
pub hide_guides: bool,
/// Pattern editing mode's tile edge and swatch bounds colour (Object → Pattern → Tile Edge
/// Color), RGB.
pub tile_edge: [u8; 3],
@@ -246,6 +249,7 @@ impl Default for RenderOptions {
trim: false,
skip_templates: false,
hide_templates: false,
hide_guides: false,
tile_edge: vectorcraft_doc::LAYER_COLORS[0].1,
guide: ([0x4a, 0xd8, 0xff], false),
mask_view: None,
@@ -1036,9 +1040,9 @@ impl Renderer {
/// Whether `a` is left out of this frame: hidden, a skipped template or guide, or culled.
fn skipped(&mut self, f: &Frame, a: &Arc<Node>) -> bool {
let skipped_template = (f.opts.skip_templates || f.opts.hide_templates) && matches!(a.kind, NodeKind::Layer { template: true, .. })
|| f.opts.skip_templates && matches!(a.kind, NodeKind::Path { guide: true, .. });
if !a.visible || skipped_template || f.opts.hidden.contains(&a.id) {
let skipped_view_item = (f.opts.skip_templates || f.opts.hide_templates) && matches!(a.kind, NodeKind::Layer { template: true, .. })
|| (f.opts.skip_templates || f.opts.hide_guides) && matches!(a.kind, NodeKind::Path { guide: true, .. });
if !a.visible || skipped_view_item || f.opts.hidden.contains(&a.id) {
return true;
}
match self.bounds_of(f.symbols, a) {
+20
View File
@@ -166,3 +166,23 @@ fn guides_draw_on_screen_only() {
assert!(drawn(false) > 0, "on screen the guide shows");
assert_eq!(drawn(true), 0, "exports leave it out");
}
/// #3219: View > Hide Guides hides paths made into guides without using the export/template
/// filtering switch; Show Guides (the default) draws them again.
#[test]
fn hide_guides_hides_guide_paths_on_screen() {
let mut d = Document::new(100.0, 100.0);
let l = d.layers[0].id;
let mut g = Node::path(d.alloc_id(), shapes::rectangle(Rect::new(70.0, 70.0, 90.0, 90.0)), Appearance::default());
if let NodeKind::Path { guide, .. } = &mut g.kind {
*guide = true;
}
d.insert(Some(l), 0, g).unwrap();
let pixels = |hide_guides: bool| {
let opts = RenderOptions { background: Some([255; 4]), hide_guides, ..Default::default() };
let r = Renderer::new().render(&d, 100, 100, Affine::IDENTITY, &opts);
(60..100).flat_map(|y| (60..100).map(move |x| (x, y))).filter(|&(x, y)| r.pixel(x, y) != [255; 4]).count()
};
assert!(pixels(false) > 0, "Show Guides draws the guide path");
assert_eq!(pixels(true), 0, "Hide Guides leaves the guide path out");
}