From 5f58acdb35afb46dec868ec7519f81ac8c0051dc Mon Sep 17 00:00:00 2001 From: bflatastic Date: Thu, 29 Oct 2026 09:17:25 +0700 Subject: [PATCH] #1406: guides for an absolute child of an auto layout frame, and a test --- crates/ui-egui/src/canvas/overlays.rs | 7 ++++--- crates/ui-egui/src/canvas_fixes_tests.rs | 24 ++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/crates/ui-egui/src/canvas/overlays.rs b/crates/ui-egui/src/canvas/overlays.rs index 3d57659bf..15af030e0 100644 --- a/crates/ui-egui/src/canvas/overlays.rs +++ b/crates/ui-egui/src/canvas/overlays.rs @@ -419,7 +419,7 @@ fn transform_box( /// bottom likewise (the line is perpendicular to the edge it leaves). A centre constraint draws a /// short bar through the layer's middle — a horizontal one, a vertical one, or both (a cross when /// the layer is centred on both axes). Auto-layout frames ignore constraints, so no guides are -/// drawn there. +/// drawn there, except for a layer that ignores the auto layout (absolute position). fn constraint_lines(app: &FigApp, painter: &egui::Painter, doc: &Document, sel: &[NodeId]) { let s = stroke(accent(painter), 1.0); let line = |a: Pos2, b: Pos2| { @@ -438,8 +438,9 @@ fn constraint_lines(app: &FigApp, painter: &egui::Painter, doc: &Document, sel: let Some(n) = doc.node(id) else { continue }; let Some(parent_id) = n.parent else { continue }; let Some(parent) = doc.node(parent_id) else { continue }; - // Constraints bind a layer only to a non-auto-layout frame it sits inside. - if !parent.kind.is_frame_like() || parent.layout.is_some() { + // Constraints bind a layer only to a frame it sits inside: one without auto layout, or one + // whose auto layout the layer ignores (absolute position). + if !parent.kind.is_frame_like() || (parent.layout.is_some() && !n.child_layout.absolute) { continue; } let nw = doc.world_transform(id); diff --git a/crates/ui-egui/src/canvas_fixes_tests.rs b/crates/ui-egui/src/canvas_fixes_tests.rs index dc3f7e94c..59b2b0d6f 100644 --- a/crates/ui-egui/src/canvas_fixes_tests.rs +++ b/crates/ui-egui/src/canvas_fixes_tests.rs @@ -162,3 +162,27 @@ fn the_pencil_previews_its_stroke_in_its_colour_and_weight() { let w = preview(&flat(&u.frame_output(vec![egui::Event::PointerMoved(p)]).shapes)).expect("still previewing"); assert!((w - 1.0).abs() < 0.01, "at least a point: {w}"); } + +#[test] +fn a_selected_layer_shows_its_constraint_guides_in_its_frame() { + // A child pinned left (the default) in a frame without auto layout: a dashed guide runs from its + // left-edge midpoint to the frame's left edge. An auto layout frame places its children itself, + // so only a child that ignores the auto layout (absolute) shows one there. + let mut s = Session::new(); + let f = id(&s.execute("frame.create", &json!({"x": 0, "y": 0, "width": 200, "height": 120})).unwrap()); + let c = id(&s.execute("node.create", &json!({"type": "rectangle", "x": 80, "y": 40, "width": 40, "height": 40, "parent": f})).unwrap()); + s.execute("select.set", &json!({"ids": [c]})).unwrap(); + let mut u = Ui::new(s); + let guide = |u: &mut Ui| { + let shapes = flat(&u.frame_output(vec![]).shapes); + let doc = u.app.session.doc().unwrap(); + let (fb, cb) = (doc.world_bounds(f).unwrap(), doc.world_bounds(c).unwrap()); + let y = cb.center().y; + dashes_along(&shapes, u.app.to_screen(fb.x0, y), u.app.to_screen(cb.x0, y)) + }; + assert!(guide(&mut u) > 0, "a left constraint draws a dashed guide to the frame's left edge"); + u.app.run("node.set", json!({"id": f, "props": {"layout": "horizontal", "padding": 40}})); + assert_eq!(guide(&mut u), 0, "auto layout places the child: no constraint guide"); + u.app.run("node.set", json!({"id": c, "props": {"absolute": true}})); + assert!(guide(&mut u) > 0, "an absolute child is pinned by its constraints again"); +}