mirror of
https://github.com/storytold/figcraft.git
synced 2026-12-03 15:31:21 -05:00
M2: align canvas padding bands with inside strokes
This commit is contained in:
+2
-1
File diff suppressed because one or more lines are too long
@@ -350,13 +350,17 @@ fn al_zones(app: &FigApp) -> Option<Zones> {
|
||||
app.to_screen(p.x, p.y)
|
||||
};
|
||||
let band = |x0: f64, y0: f64, x1: f64, y1: f64| Rect::from_two_pos(to(x0, y0), to(x1, y1));
|
||||
let [pt, pr, pb, pl] = al.padding;
|
||||
let [pt, pr, pb, pl] = al.padding.map(|v| if v.is_finite() { v.max(0.0) } else { 0.0 });
|
||||
let (it, ir, ib, il) = figcraft_layout::insets(n, al);
|
||||
let (fw, fh) = (n.width, n.height);
|
||||
// Padding starts at the inside edge of an included stroke, as the layout's content does.
|
||||
// The bands exclude the stroke itself so their labels and drags still edit only padding.
|
||||
let (left, top, right, bottom) = (il - pl, it - pt, fw - ir + pr, fh - ib + pb);
|
||||
let bands = vec![
|
||||
(0, band(0.0, 0.0, fw, pt.max(4.0)), pt),
|
||||
(1, band(fw - pr.max(4.0), 0.0, fw, fh), pr),
|
||||
(2, band(0.0, fh - pb.max(4.0), fw, fh), pb),
|
||||
(3, band(0.0, 0.0, pl.max(4.0), fh), pl),
|
||||
(0, band(left, top, right, top + pt.max(4.0)), pt),
|
||||
(1, band(right - pr.max(4.0), top, right, bottom), pr),
|
||||
(2, band(left, bottom - pb.max(4.0), right, bottom), pb),
|
||||
(3, band(left, top, left + pl.max(4.0), bottom), pl),
|
||||
];
|
||||
// An auto gap shows (and is dragged from) the distance the layout gives it; the drag makes it a
|
||||
// fixed gap again, as typing one does.
|
||||
@@ -369,8 +373,8 @@ fn al_zones(app: &FigApp) -> Option<Zones> {
|
||||
let mut tracks = Vec::new();
|
||||
if let Some(g) = figcraft_layout::grid_geometry(doc, id) {
|
||||
// Grid: bands between columns (column gap) and between rows (row gap), and the tracks.
|
||||
let (top, bottom) = (g.rows.first().map(|r| r.0).unwrap_or(pt), g.rows.last().map(|r| r.1).unwrap_or(fh - pb));
|
||||
let (left, right) = (g.columns.first().map(|c| c.0).unwrap_or(pl), g.columns.last().map(|c| c.1).unwrap_or(fw - pr));
|
||||
let (top, bottom) = (g.rows.first().map(|r| r.0).unwrap_or(it), g.rows.last().map(|r| r.1).unwrap_or(fh - ib));
|
||||
let (left, right) = (g.columns.first().map(|c| c.0).unwrap_or(il), g.columns.last().map(|c| c.1).unwrap_or(fw - ir));
|
||||
for pair in g.columns.windows(2) {
|
||||
if let [a, b] = pair {
|
||||
gaps.push(main(band(a.1, top, b.0, bottom), false, al.gap));
|
||||
@@ -396,7 +400,7 @@ fn al_zones(app: &FigApp) -> Option<Zones> {
|
||||
let flip = |r: figcraft_geom::Rect| if vertical { figcraft_geom::Rect::new(r.y0, r.x0, r.y1, r.x1) } else { r };
|
||||
let fband = |x0: f64, y0: f64, x1: f64, y1: f64| if vertical { band(y0, x0, y1, x1) } else { band(x0, y0, x1, y1) };
|
||||
// Main-axis length and padding, cross-axis length and padding.
|
||||
let (mw, mp0, mp1, cw, cp0, cp1) = if vertical { (fh, pt, pb, fw, pl, pr) } else { (fw, pl, pr, fh, pt, pb) };
|
||||
let (mw, mp0, mp1, cw, cp0, cp1) = if vertical { (fh, it, ib, fw, il, ir) } else { (fw, il, ir, fh, it, ib) };
|
||||
let boxes: Vec<figcraft_geom::Rect> = figcraft_layout::flow_children(doc, id)
|
||||
.into_iter()
|
||||
.filter_map(|c| doc.node(c))
|
||||
@@ -799,4 +803,6 @@ fn apply(app: &mut FigApp, drag: &Drag, pos: Pos2, shift: bool) {
|
||||
#[cfg(test)]
|
||||
mod character_fill_tests;
|
||||
#[cfg(test)]
|
||||
mod padding_tests;
|
||||
#[cfg(test)]
|
||||
mod region_tests;
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
//! Padding bands follow the content box, including the frame's inside stroke.
|
||||
|
||||
use egui::Rect;
|
||||
use figcraft_doc::NodeId;
|
||||
use figcraft_engine::{Session, params::id_of};
|
||||
use serde_json::json;
|
||||
|
||||
use super::al_zones;
|
||||
use crate::layers_drag_tests::Ui;
|
||||
|
||||
fn scene() -> (Ui, NodeId) {
|
||||
let mut s = Session::new();
|
||||
let f = id_of(
|
||||
&s.execute(
|
||||
"frame.create",
|
||||
&json!({"x": 100, "y": 100, "width": 300, "height": 200,
|
||||
"props": {"layout": "horizontal", "gap": 10, "padding": [10, 20, 30, 40], "stroke": "#000000", "strokeWeight": 4, "strokeAlign": "inside"}
|
||||
}),
|
||||
)
|
||||
.unwrap()["id"],
|
||||
)
|
||||
.unwrap();
|
||||
s.execute("select.set", &json!({"ids": [f]})).unwrap();
|
||||
(Ui::new(s), f)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn padding_bands_follow_uniform_and_individual_inside_strokes() {
|
||||
let (mut u, f) = scene();
|
||||
for (props, stroke) in [
|
||||
(json!({"strokeWeight": 4}), [4.0; 4]),
|
||||
(json!({"strokeWeight": 24}), [24.0; 4]),
|
||||
(json!({"strokeSides": [8, 12, 16, 24]}), [8.0, 12.0, 16.0, 24.0]),
|
||||
(json!({"strokesIncluded": false}), [0.0; 4]),
|
||||
(json!({"strokesIncluded": true, "strokeAlign": "center"}), [0.0; 4]),
|
||||
(json!({"strokeAlign": "outside"}), [0.0; 4]),
|
||||
] {
|
||||
u.app.run("node.set", json!({"ids": [f], "props": props}));
|
||||
let [t, r, b, l] = stroke;
|
||||
let expected = [
|
||||
(l, t, 300.0 - r, t + 10.0),
|
||||
(300.0 - r - 20.0, t, 300.0 - r, 200.0 - b),
|
||||
(l, 200.0 - b - 30.0, 300.0 - r, 200.0 - b),
|
||||
(l, t, l + 40.0, 200.0 - b),
|
||||
];
|
||||
let zones = al_zones(&u.app).unwrap();
|
||||
for ((side, band, value), (x0, y0, x1, y1)) in zones.bands.iter().zip(expected) {
|
||||
let expected = Rect::from_two_pos(u.app.to_screen(100.0 + x0, 100.0 + y0), u.app.to_screen(100.0 + x1, 100.0 + y1));
|
||||
assert_eq!(*band, expected, "side {side}, stroke {stroke:?}");
|
||||
assert_eq!(*value, [10.0, 20.0, 30.0, 40.0][*side]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn gap_bands_span_the_content_box_inside_stroke_and_padding() {
|
||||
let (mut u, f) = scene();
|
||||
for _ in 0..2 {
|
||||
u.app.run("shape.rectangle", json!({"parent": f, "width": 40, "height": 20}));
|
||||
}
|
||||
u.app.run("select.set", json!({"ids": [f]}));
|
||||
for (mode, expected) in [("horizontal", (184.0, 114.0, 194.0, 266.0)), ("vertical", (144.0, 134.0, 376.0, 144.0))] {
|
||||
u.app.run("node.set", json!({"ids": [f], "props": {"layout": mode}}));
|
||||
let zones = al_zones(&u.app).unwrap();
|
||||
assert_eq!(zones.gaps.len(), 1);
|
||||
let (x0, y0, x1, y1) = expected;
|
||||
assert_eq!(zones.gaps[0].rect, Rect::from_two_pos(u.app.to_screen(x0, y0), u.app.to_screen(x1, y1)));
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
# Auto layout and constraints parity
|
||||
|
||||
> **Last reviewed:** 2026-10-11 · **Last updated:** 2026-11-03 · **Change:** patch (a Cmd/Ctrl-click on a padding field sets all four sides with the value typed, as the Guide to auto layout's shortcut guide says; Suggest auto layout is its own command, as the help center says: it adds as many auto layout frames as needed, splitting a frame's layers into rows or columns by the gaps between them, and keeps the placement of the design where the gaps are even (#1823); baseline alignment puts a layer without text with its bottom on the line, as the help center's figure shows an icon next to text (#1825); fill children share the free space by their content area, border-box fashion, as the Flexbox article says (#1824); double-click an edge of an auto layout frame's box for Hug contents, Alt+double-click an edge of a child's box for Fill container, as the Guide to auto layout says (#1838); a child resized to the full available space of its auto layout frame becomes Fill container on that axis, as the Guide to auto layout says; a text keeps a max height or a number of max lines, not both, as the Guide to auto layout says: a max height sets max lines to Auto and max lines remove the max height; Remove all auto layout, as the help center's More layout options has it: `layout.removeAll` takes the auto layout off a frame and every frame nested in it in one undo step; grid auto-placement looks for free cells a 64-bit word at a time and skips what blocks it, with the same placements (#1083); Layout sidebar: Add auto layout (+) is available for groups and converts a single group to a frame in place, with mask order, flow-only inference and Fill sizing preserved; adding auto layout to an empty frame keeps its size (#369); `node.set` applies auto layout keys only to frames, with warnings (#603); core editor leftovers: auto gap handles, wrapped-line alignment; behaviour suite written from the public documentation, every rule's status; fixes and the missing settings it found) · **Target:** Figma Design (desktop app 126.10.7)
|
||||
> **Last reviewed:** 2026-10-11 · **Last updated:** 2026-11-09 · **Change:** patch (canvas padding bands follow included inside strokes; a Cmd/Ctrl-click on a padding field sets all four sides with the value typed, as the Guide to auto layout's shortcut guide says; Suggest auto layout is its own command, as the help center says: it adds as many auto layout frames as needed, splitting a frame's layers into rows or columns by the gaps between them, and keeps the placement of the design where the gaps are even (#1823); baseline alignment puts a layer without text with its bottom on the line, as the help center's figure shows an icon next to text (#1825); fill children share the free space by their content area, border-box fashion, as the Flexbox article says (#1824); double-click an edge of an auto layout frame's box for Hug contents, Alt+double-click an edge of a child's box for Fill container, as the Guide to auto layout says (#1838); a child resized to the full available space of its auto layout frame becomes Fill container on that axis, as the Guide to auto layout says; a text keeps a max height or a number of max lines, not both, as the Guide to auto layout says: a max height sets max lines to Auto and max lines remove the max height; Remove all auto layout, as the help center's More layout options has it: `layout.removeAll` takes the auto layout off a frame and every frame nested in it in one undo step; grid auto-placement looks for free cells a 64-bit word at a time and skips what blocks it, with the same placements (#1083); Layout sidebar: Add auto layout (+) is available for groups and converts a single group to a frame in place, with mask order, flow-only inference and Fill sizing preserved; adding auto layout to an empty frame keeps its size (#369); `node.set` applies auto layout keys only to frames, with warnings (#603); core editor leftovers: auto gap handles, wrapped-line alignment; behaviour suite written from the public documentation, every rule's status; fixes and the missing settings it found) · **Target:** Figma Design (desktop app 126.10.7)
|
||||
|
||||
Auto layout is the most used layout feature in Figma and the one where small differences (a
|
||||
hugging frame one pixel off, text wrapping at another width) break real files. **Breadth ~98%,
|
||||
@@ -52,6 +52,7 @@ Status: **pass** (a case in the suite holds), **fixed** (the suite found a diver
|
||||
| Padding per side (uniform, vertical/horizontal, individual) | pass | `padding_and_stroke_rules` |
|
||||
| A frame is never smaller than its padding (plus an included inside stroke), even when Fixed, hugging or given a smaller max | **fixed** | was free to shrink below its padding |
|
||||
| Strokes included: only the frame's own **inside** stroke takes up space; center and outside strokes never do | **fixed** | every stroke alignment counted before; per-side inside weights count per side (silent on individual weights) |
|
||||
| Canvas padding and gap bands follow the included inside stroke | **fixed** | Padding bands begin at the stroke's inner edge; flow gap bands span the available content box. Uniform and individual weights, excluded strokes and center/outside alignment are covered by `canvas::handles::padding_tests`. |
|
||||
| New auto layout includes inside strokes by default | **fixed** | the default was excluded |
|
||||
| Strokes included / excluded setting in the Design panel | **added** | `strokesIncluded` existed as a prop only |
|
||||
| Gap: fixed distance; negative gaps overlap | pass | `gap_rules` |
|
||||
@@ -101,6 +102,7 @@ Status: **pass** (a case in the suite holds), **fixed** (the suite found a diver
|
||||
|
||||
| Date | Change | Summary |
|
||||
|---|---|---|
|
||||
| 2026-11-09 | patch | M2: Canvas padding bands follow the inner edge of included inside strokes, including per-side weights; gap bands use the same content insets. Geometry regression tests cover stroke growth, exclusion and center/outside alignment. Dimensions and padding values are unchanged. |
|
||||
| 2026-11-05 | patch | M2, #1823: Suggest auto layout is no longer Add auto layout under another name: `layout.suggest` splits a frame's layers into rows (Vertical) or else columns (Horizontal) by the gaps between their boxes, wraps each band of several layers in a new frame without fill or clipping that hugs it, and repeats inside it (16 levels, 1,000 layers per frame at most). The frame keeps its size; gap and padding come from the bands, so layers keep their boxes where the gaps are even and the bands start at the same offset; instances and layers inside them are refused; uneven gaps (smallest used), bands that start at different offsets across the flow (lined up at the smallest) and layers that overlap along both axes come back as `warnings`. A band frame hugs only when its own split succeeds: a band whose layers overlap along both axes gets no auto layout and stays Fixed, so it cannot reflow those children. `direction` sets the top level only; one undo step; `layout.add` is unchanged. Tests in `layout_suggest_tests.rs` |
|
||||
| 2026-11-02 | patch | M2: a Cmd/Ctrl-click on a padding field (the horizontal or vertical pair, or a side with Individual padding open) makes the value typed go to all four sides in one undo step (Guide to auto layout, Keyboard shortcut guide); a plain click still edits that axis or side alone. The modifier was ignored before. Test: `padding_individual_tests` |
|
||||
| 2026-11-03 | patch | M2, #1825: baseline alignment of a layer without text (an icon next to a text) puts its bottom on the line's baseline, as the help center's figure shows ("the bottoms of the icon and the word home are aligned on the red line"); it kept to the top of the line. A layer reaching below the text's baseline moves the text down, and a line with no text lines the layers' bottoms up (the documentation is silent; CSS baseline alignment does the same). Tests: `alignment_rules` (three cases), engine `baseline_alignment_puts_an_icons_bottom_on_the_text_baseline`. Numbers unchanged. |
|
||||
|
||||
Reference in New Issue
Block a user