mirror of
https://github.com/storytold/figcraft.git
synced 2026-11-10 20:29:33 -06:00
Merge pull request #2020 from TrevorBrown-dev/feat/suggest-auto-layout-1823
M2: Suggest auto layout adds nested auto layout frames by rows and columns and keeps the placement (#1823)
This commit is contained in:
+2
-1
File diff suppressed because one or more lines are too long
@@ -10,6 +10,8 @@ use serde_json::{Value, json};
|
||||
|
||||
use super::edit::{roots, z_sorted};
|
||||
use super::{CommandSpec, ok};
|
||||
|
||||
mod suggest;
|
||||
use crate::params::{f64_of, get, id_of, num_or, req_id, req_index, req_num, req_targets, string, targets};
|
||||
use crate::{EngineError, Result, Session, bad, spec};
|
||||
|
||||
@@ -109,7 +111,13 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
Ok(json!({"removed": removed}))
|
||||
}
|
||||
),
|
||||
spec!("layout.suggest", "Suggest auto layout", "{ids?, direction? (horizontal|vertical|grid)}", true, layout_add),
|
||||
spec!(
|
||||
"layout.suggest",
|
||||
"Suggest auto layout",
|
||||
"{ids?, direction? (horizontal|vertical|grid)} splits each frame's layers into rows or columns by the gaps between them, wraps every band of several layers in a frame without fill that hugs it and does the same inside, so the layers keep their place where the gaps are even and the bands start at the same offset across the flow; the frame keeps its size, and the result carries `warnings` for gaps that differ, bands that start at different offsets (they line up at the smallest and some move) and layers that overlap. Instances and the layers inside them are refused. `direction` sets the top level's direction (nested frames follow the gaps); grid lays the layers out in one grid. A group is converted to a frame and several layers are wrapped in one, as Add auto layout does",
|
||||
true,
|
||||
suggest::layout_suggest
|
||||
),
|
||||
spec!("object.moveToPage", "Move to page", "{ids?, page}", true, move_to_page),
|
||||
spec!("object.setThumbnail", "Set as thumbnail", "{id?}", true, |s, p| {
|
||||
let id = targets(s, p).first().copied().ok_or_else(|| bad("object.setThumbnail", "select a frame"))?;
|
||||
|
||||
@@ -0,0 +1,278 @@
|
||||
//! Suggest auto layout (#1823): split a frame's layers into rows or columns by the gaps between
|
||||
//! them, wrap each band that holds several layers in a frame of its own and do the same inside
|
||||
//! it, so the design gets as many auto layout frames as it needs and keeps its placement.
|
||||
|
||||
use figcraft_doc::{AutoLayout, Document, LayoutMode, NodeId, NodeKind, Sizing};
|
||||
use figcraft_geom::Rect;
|
||||
use serde_json::{Value, json};
|
||||
|
||||
use super::{Wrap, convert, infer_layout, sort_layout_children, wrap};
|
||||
use crate::params::{id_of, req_targets, string};
|
||||
use crate::{EngineError, Result, Session, bad};
|
||||
|
||||
/// How deep nested band frames go before a frame is laid out as a single list.
|
||||
const MAX_DEPTH: usize = 16;
|
||||
/// The most layers analysed in one frame; past this the frame is laid out as a single list.
|
||||
const MAX_CHILDREN: usize = 1000;
|
||||
/// Gaps that differ by more than this are reported.
|
||||
const GAP_TOLERANCE: f64 = 0.5;
|
||||
/// Edges closer than this count as touching.
|
||||
const EDGE_EPS: f64 = 1e-6;
|
||||
|
||||
/// One row or column: the layers in it and the span it covers along both axes.
|
||||
struct Band {
|
||||
members: Vec<(NodeId, Rect)>,
|
||||
/// Start and end along the split axis.
|
||||
lo: f64,
|
||||
hi: f64,
|
||||
/// Start and end along the other axis.
|
||||
cross_lo: f64,
|
||||
cross_hi: f64,
|
||||
}
|
||||
|
||||
fn span(r: &Rect, vertical: bool) -> (f64, f64, f64, f64) {
|
||||
if vertical { (r.y0, r.y1, r.x0, r.x1) } else { (r.x0, r.x1, r.y0, r.y1) }
|
||||
}
|
||||
|
||||
/// Split the layers into bands along one axis: sorted by their start, a layer joins the current
|
||||
/// band while it starts before the band ends, and opens a new band when there is a gap or it
|
||||
/// only touches. Layers starting together always share a band.
|
||||
fn bands(boxes: &[(NodeId, Rect)], vertical: bool) -> Vec<Band> {
|
||||
let mut sorted = boxes.to_vec();
|
||||
sorted.sort_by(|a, b| span(&a.1, vertical).0.total_cmp(&span(&b.1, vertical).0));
|
||||
let mut out: Vec<Band> = Vec::new();
|
||||
for item in sorted {
|
||||
let (lo, hi, cross_lo, cross_hi) = span(&item.1, vertical);
|
||||
match out.last_mut() {
|
||||
Some(b) if lo < b.hi - EDGE_EPS || lo - b.lo < EDGE_EPS => {
|
||||
b.hi = b.hi.max(hi);
|
||||
b.cross_lo = b.cross_lo.min(cross_lo);
|
||||
b.cross_hi = b.cross_hi.max(cross_hi);
|
||||
b.members.push(item);
|
||||
}
|
||||
_ => out.push(Band { members: vec![item], lo, hi, cross_lo, cross_hi }),
|
||||
}
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
/// The layers a frame lays out, with their boxes in the frame's own space. `None` when a box
|
||||
/// isn't a finite number.
|
||||
fn flow_boxes(doc: &Document, frame: NodeId) -> Option<Vec<(NodeId, Rect)>> {
|
||||
let mut out = Vec::new();
|
||||
for c in figcraft_layout::flow_children(doc, frame) {
|
||||
let n = doc.node(c)?;
|
||||
let r = figcraft_geom::transform_rect_bbox(n.transform, n.local_rect());
|
||||
if ![r.x0, r.y0, r.x1, r.y1].iter().all(|v| v.is_finite()) {
|
||||
return None;
|
||||
}
|
||||
out.push((c, r));
|
||||
}
|
||||
Some(out)
|
||||
}
|
||||
|
||||
fn finite_or_zero(v: f64) -> f64 {
|
||||
if v.is_finite() { (v * 1000.0).round() / 1000.0 } else { 0.0 }
|
||||
}
|
||||
|
||||
fn mode_from(direction: &str) -> LayoutMode {
|
||||
match direction.to_ascii_lowercase().as_str() {
|
||||
"vertical" | "column" => LayoutMode::Vertical,
|
||||
"grid" => LayoutMode::Grid,
|
||||
_ => LayoutMode::Horizontal,
|
||||
}
|
||||
}
|
||||
|
||||
/// The auto layout that places `bands` where they are: the gap between them, the room before the
|
||||
/// first and after the last, and on the other axis the smallest offset from each edge.
|
||||
fn layout_for(bands: &[Band], vertical: bool, frame_w: f64, frame_h: f64, name: &str, warnings: &mut Vec<String>) -> AutoLayout {
|
||||
let gaps: Vec<f64> = bands.windows(2).filter_map(|w| Some((w.get(1)?.lo - w.first()?.hi).max(0.0))).collect();
|
||||
let smallest = gaps.iter().copied().fold(f64::INFINITY, f64::min);
|
||||
let largest = gaps.iter().copied().fold(0.0, f64::max);
|
||||
if largest - smallest > GAP_TOLERANCE {
|
||||
let what = if vertical { "rows" } else { "columns" };
|
||||
warnings.push(format!(
|
||||
"\"{name}\": the gaps between the {what} differ ({} to {}), so the smallest is used and later {what} move",
|
||||
finite_or_zero(smallest),
|
||||
finite_or_zero(largest)
|
||||
));
|
||||
}
|
||||
let (main_size, cross_size) = if vertical { (frame_h, frame_w) } else { (frame_w, frame_h) };
|
||||
let main_start = bands.first().map_or(0.0, |b| b.lo).max(0.0);
|
||||
let main_end = (main_size - bands.last().map_or(0.0, |b| b.hi)).max(0.0);
|
||||
let cross_start = bands.iter().map(|b| b.cross_lo).fold(f64::INFINITY, f64::min).max(0.0);
|
||||
let cross_end = bands.iter().map(|b| cross_size - b.cross_hi).fold(f64::INFINITY, f64::min).max(0.0);
|
||||
// Every band is lined up at the start across the flow, so one that starts further in (a
|
||||
// centred title above a card) moves to the smallest offset.
|
||||
let widest_start = bands.iter().map(|b| b.cross_lo).fold(f64::NEG_INFINITY, f64::max);
|
||||
let smallest_start = bands.iter().map(|b| b.cross_lo).fold(f64::INFINITY, f64::min);
|
||||
if widest_start - smallest_start > GAP_TOLERANCE {
|
||||
let what = if vertical { "rows" } else { "columns" };
|
||||
warnings.push(format!(
|
||||
"\"{name}\": the {what} start at different offsets ({} to {}), so they are lined up at the smallest and some move",
|
||||
finite_or_zero(smallest_start),
|
||||
finite_or_zero(widest_start)
|
||||
));
|
||||
}
|
||||
let [ms, me, cs, ce] = [main_start, main_end, cross_start, cross_end].map(finite_or_zero);
|
||||
AutoLayout {
|
||||
mode: if vertical { LayoutMode::Vertical } else { LayoutMode::Horizontal },
|
||||
gap: finite_or_zero(smallest),
|
||||
// Top, right, bottom, left.
|
||||
padding: if vertical { [ms, ce, me, cs] } else { [cs, me, ce, ms] },
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
|
||||
/// Lay a frame out as one list the way "Add auto layout" does: the direction is inferred, or
|
||||
/// `direction` forces it.
|
||||
fn flat_layout(s: &mut Session, frame: NodeId, direction: Option<&str>) -> Result<()> {
|
||||
let doc = s.doc_mut()?;
|
||||
let mut al = infer_layout(doc, frame);
|
||||
if let Some(d) = direction {
|
||||
al.mode = mode_from(d);
|
||||
}
|
||||
let mut kids = doc.get(frame)?.children.clone();
|
||||
sort_layout_children(doc, &mut kids, al.mode == LayoutMode::Vertical);
|
||||
let n = doc.get_mut(frame)?;
|
||||
n.children = kids;
|
||||
n.layout = Some(al);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Turn the frame's layers into bands and give the frame, and every band frame made on the way,
|
||||
/// the auto layout that keeps them where they are. Returns whether the frame got auto layout.
|
||||
fn split(s: &mut Session, frame: NodeId, depth: usize, direction: Option<&str>, warnings: &mut Vec<String>) -> Result<bool> {
|
||||
let doc = s.doc()?;
|
||||
let name = doc.get(frame)?.name.clone();
|
||||
let (frame_w, frame_h) = (doc.get(frame)?.width, doc.get(frame)?.height);
|
||||
let any_mask = doc.get(frame)?.children.iter().filter_map(|c| doc.node(*c)).any(|c| c.is_mask);
|
||||
let Some(boxes) = flow_boxes(doc, frame) else {
|
||||
warnings.push(format!("\"{name}\": a layer has no usable position, so no auto layout was added"));
|
||||
return Ok(false);
|
||||
};
|
||||
if boxes.len() < 2 {
|
||||
flat_layout(s, frame, direction)?;
|
||||
return Ok(true);
|
||||
}
|
||||
if depth >= MAX_DEPTH || boxes.len() > MAX_CHILDREN || any_mask {
|
||||
let why = if any_mask {
|
||||
"it has a mask"
|
||||
} else if depth >= MAX_DEPTH {
|
||||
"the frames are nested too deep"
|
||||
} else {
|
||||
"it has too many layers to analyse"
|
||||
};
|
||||
warnings.push(format!("\"{name}\": {why}, so its layers are laid out in one list"));
|
||||
flat_layout(s, frame, direction)?;
|
||||
return Ok(true);
|
||||
}
|
||||
// The direction asked for decides the axis of the top level; nested frames follow the gaps.
|
||||
let forced = direction.map(mode_from);
|
||||
let (vertical, found) = match forced {
|
||||
Some(LayoutMode::Vertical) => (true, bands(&boxes, true)),
|
||||
Some(LayoutMode::Horizontal) => (false, bands(&boxes, false)),
|
||||
Some(_) => (true, Vec::new()),
|
||||
None => {
|
||||
let rows = bands(&boxes, true);
|
||||
if rows.len() >= 2 { (true, rows) } else { (false, bands(&boxes, false)) }
|
||||
}
|
||||
};
|
||||
if found.len() < 2 {
|
||||
if forced.is_some() {
|
||||
if forced != Some(LayoutMode::Grid) {
|
||||
warnings.push(format!("\"{name}\": its layers don't separate along the direction asked for, so they are laid out in one list"));
|
||||
}
|
||||
flat_layout(s, frame, direction)?;
|
||||
return Ok(true);
|
||||
}
|
||||
warnings.push(format!("\"{name}\": its layers overlap along both axes, so no auto layout was added"));
|
||||
return Ok(false);
|
||||
}
|
||||
let al = layout_for(&found, vertical, frame_w, frame_h, &name, warnings);
|
||||
// Band frames first, while the layers are still where they were.
|
||||
let mut made = Vec::new();
|
||||
for band in &found {
|
||||
if band.members.len() < 2 {
|
||||
continue;
|
||||
}
|
||||
let ids: Vec<NodeId> = band.members.iter().map(|(id, _)| *id).collect();
|
||||
let r = wrap(s, &json!({"ids": ids}), "layout.suggest", Wrap::Frame)?;
|
||||
let fid = id_of(&r["id"]).ok_or_else(|| EngineError::Other("wrap failed".into()))?;
|
||||
let f = s.doc_mut()?.get_mut(fid)?;
|
||||
f.fills.clear();
|
||||
f.clip = false;
|
||||
made.push(fid);
|
||||
}
|
||||
let doc = s.doc_mut()?;
|
||||
let mut kids = doc.get(frame)?.children.clone();
|
||||
sort_layout_children(doc, &mut kids, vertical);
|
||||
let n = doc.get_mut(frame)?;
|
||||
n.children = kids;
|
||||
n.layout = Some(al);
|
||||
for fid in made {
|
||||
if split(s, fid, depth + 1, None, warnings)? {
|
||||
// A band frame that got auto layout is as big as what is in it (one that did not stays Fixed).
|
||||
let f = s.doc_mut()?.get_mut(fid)?;
|
||||
f.child_layout.sizing_h = Sizing::Hug;
|
||||
f.child_layout.sizing_v = Sizing::Hug;
|
||||
}
|
||||
}
|
||||
Ok(true)
|
||||
}
|
||||
|
||||
/// Add auto layout to the frames, group or layers asked for the way "Add auto layout" finds its
|
||||
/// targets, then split each into nested rows and columns by the gaps between its layers.
|
||||
pub(super) fn layout_suggest(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
let ids = req_targets("layout.suggest", s, p)?;
|
||||
let direction = string(p, "direction");
|
||||
let doc = s.doc()?;
|
||||
// An instance's layers come from its main component: nothing is added to them. Checked
|
||||
// before anything changes, with the words Convert to group uses.
|
||||
for i in &ids {
|
||||
let n = doc.get(*i)?;
|
||||
if matches!(n.kind, NodeKind::Instance { .. }) {
|
||||
return Err(bad("layout.suggest", format!("\"{}\" is an instance: its layers come from its main component (detach it first)", n.name)));
|
||||
}
|
||||
if crate::components::owning_instance(doc, *i).is_some() {
|
||||
return Err(bad("layout.suggest", format!("\"{}\" is inside an instance: edit its main component, or detach the instance", n.name)));
|
||||
}
|
||||
}
|
||||
let all_frames = ids.iter().all(|i| doc.node(*i).is_some_and(|n| n.kind.is_frame_like() && n.layout.is_none()));
|
||||
let single_group = ids.len() == 1 && ids.first().and_then(|i| doc.node(*i)).is_some_and(|n| matches!(n.kind, NodeKind::Group));
|
||||
// A frame with auto layout already is wrapped, like a layer, and so are several layers.
|
||||
let (targets, own_size) = if all_frames {
|
||||
(ids, true)
|
||||
} else if single_group {
|
||||
// The group's layers are laid out directly, not inside a wrapper.
|
||||
convert(s, &json!({"ids": ids}), "layout.suggest", true)?;
|
||||
(ids, false)
|
||||
} else {
|
||||
let r = wrap(s, &json!({"ids": ids}), "layout.suggest", Wrap::Frame)?;
|
||||
let fid = id_of(&r["id"]).ok_or_else(|| EngineError::Other("wrap failed".into()))?;
|
||||
let f = s.doc_mut()?.get_mut(fid)?;
|
||||
f.fills.clear();
|
||||
f.clip = false;
|
||||
(vec![fid], false)
|
||||
};
|
||||
let mut warnings = Vec::new();
|
||||
for f in &targets {
|
||||
// A frame keeps its size; a wrapper or a converted group has none of its own and hugs.
|
||||
let got_layout = split(s, *f, 0, direction.as_deref(), &mut warnings)?;
|
||||
if got_layout && !own_size {
|
||||
let n = s.doc_mut()?.get_mut(*f)?;
|
||||
if !single_group || n.child_layout.sizing_h != Sizing::Fill {
|
||||
n.child_layout.sizing_h = Sizing::Hug;
|
||||
}
|
||||
if !single_group || n.child_layout.sizing_v != Sizing::Fill {
|
||||
n.child_layout.sizing_v = Sizing::Hug;
|
||||
}
|
||||
}
|
||||
}
|
||||
s.set_selection(targets.clone());
|
||||
let mut out = json!({"ids": targets});
|
||||
if !warnings.is_empty() {
|
||||
out["warnings"] = json!(warnings);
|
||||
}
|
||||
Ok(out)
|
||||
}
|
||||
@@ -0,0 +1,325 @@
|
||||
//! Suggest auto layout (#1823): a frame's layers are split into rows or columns by the gaps between
|
||||
//! them, each band of several layers gets a frame of its own, and the design keeps its placement.
|
||||
|
||||
use serde_json::{Value, json};
|
||||
|
||||
use crate::Session;
|
||||
use crate::params::id_of;
|
||||
use figcraft_doc::{LayoutMode, NodeId, NodeKind, Sizing};
|
||||
|
||||
fn id(v: &Value) -> NodeId {
|
||||
id_of(&v["id"]).unwrap()
|
||||
}
|
||||
|
||||
fn ex(s: &mut Session, cmd: &str, p: Value) -> Value {
|
||||
s.execute(cmd, &p).unwrap_or_else(|e| panic!("{cmd} {p}: {e}"))
|
||||
}
|
||||
|
||||
fn frame(s: &mut Session, x: f64, y: f64, w: f64, h: f64) -> NodeId {
|
||||
id(&ex(s, "frame.create", json!({"x": x, "y": y, "width": w, "height": h})))
|
||||
}
|
||||
|
||||
fn rect(s: &mut Session, parent: NodeId, x: f64, y: f64, w: f64, h: f64) -> NodeId {
|
||||
id(&ex(s, "shape.rectangle", json!({"parent": parent, "x": x, "y": y, "width": w, "height": h})))
|
||||
}
|
||||
|
||||
/// A layer's box on the page: `[x0, y0, x1, y1]`, rounded.
|
||||
fn page_box(s: &Session, n: NodeId) -> [f64; 4] {
|
||||
let b = s.doc().unwrap().world_bounds(n).unwrap();
|
||||
[b.x0, b.y0, b.x1, b.y1].map(|v| (v * 1000.0).round() / 1000.0)
|
||||
}
|
||||
|
||||
fn boxes(s: &Session, ns: &[NodeId]) -> Vec<[f64; 4]> {
|
||||
ns.iter().map(|n| page_box(s, *n)).collect()
|
||||
}
|
||||
|
||||
fn kids(s: &Session, n: NodeId) -> Vec<NodeId> {
|
||||
s.doc().unwrap().node(n).unwrap().children.clone()
|
||||
}
|
||||
|
||||
fn mode(s: &Session, n: NodeId) -> Option<LayoutMode> {
|
||||
s.doc().unwrap().node(n).unwrap().layout.as_ref().map(|l| l.mode)
|
||||
}
|
||||
|
||||
/// A frame made by Suggest auto layout: no fill, no clipping, hugging what is in it.
|
||||
fn assert_band(s: &Session, n: NodeId, m: LayoutMode) {
|
||||
let node = s.doc().unwrap().node(n).unwrap();
|
||||
assert!(matches!(node.kind, NodeKind::Frame), "a band is a frame");
|
||||
assert!(node.fills.is_empty() && !node.clip, "a band has no fill and does not clip");
|
||||
assert_eq!(mode(s, n), Some(m));
|
||||
assert_eq!((node.child_layout.sizing_h, node.child_layout.sizing_v), (Sizing::Hug, Sizing::Hug));
|
||||
}
|
||||
|
||||
fn warnings(r: &Value) -> Vec<String> {
|
||||
r["warnings"].as_array().map(|a| a.iter().filter_map(|w| w.as_str().map(String::from)).collect()).unwrap_or_default()
|
||||
}
|
||||
|
||||
/// The issue's design: four 50 x 50 squares in a 200 x 200 frame, two rows of two.
|
||||
fn squares() -> (Session, NodeId, [NodeId; 4]) {
|
||||
let mut s = Session::new();
|
||||
let f = frame(&mut s, 100.0, 50.0, 200.0, 200.0);
|
||||
let sq = [(0.0, 0.0), (60.0, 0.0), (0.0, 60.0), (60.0, 60.0)].map(|(x, y)| rect(&mut s, f, x, y, 50.0, 50.0));
|
||||
(s, f, sq)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn two_rows_of_two_squares_become_a_vertical_frame_of_two_horizontal_rows() {
|
||||
let (mut s, f, sq) = squares();
|
||||
let before_frame = page_box(&s, f);
|
||||
let before = boxes(&s, &sq);
|
||||
let result = ex(&mut s, "layout.suggest", json!({"ids": [f]}));
|
||||
assert_eq!(result["ids"], json!([f]));
|
||||
assert!(warnings(&result).is_empty(), "{result}");
|
||||
assert_eq!(mode(&s, f), Some(LayoutMode::Vertical));
|
||||
let rows = kids(&s, f);
|
||||
assert_eq!(rows.len(), 2, "two rows");
|
||||
for (row, pair) in rows.iter().zip([[sq[0], sq[1]], [sq[2], sq[3]]]) {
|
||||
assert_band(&s, *row, LayoutMode::Horizontal);
|
||||
assert_eq!(kids(&s, *row), pair);
|
||||
}
|
||||
let node = s.doc().unwrap().node(f).unwrap();
|
||||
assert_eq!(node.child_layout.sizing_h, Sizing::Fixed, "the frame keeps its size");
|
||||
assert_eq!(node.child_layout.sizing_v, Sizing::Fixed);
|
||||
assert_eq!(page_box(&s, f), before_frame);
|
||||
assert_eq!(boxes(&s, &sq), before, "every square stays where it was");
|
||||
assert_eq!(s.selection(), vec![f]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn suggesting_auto_layout_is_one_undo_step() {
|
||||
let (mut s, f, sq) = squares();
|
||||
let rows_before = kids(&s, f);
|
||||
let steps = s.ds().unwrap().history.undo.len();
|
||||
ex(&mut s, "layout.suggest", json!({"ids": [f]}));
|
||||
assert_eq!(s.ds().unwrap().history.undo.len(), steps + 1);
|
||||
let rows = kids(&s, f);
|
||||
s.undo().unwrap();
|
||||
assert_eq!(kids(&s, f), rows_before);
|
||||
assert_eq!(mode(&s, f), None);
|
||||
assert!(rows.iter().all(|r| s.doc().unwrap().node(*r).is_none()), "the band frames are gone");
|
||||
assert_eq!(
|
||||
boxes(&s, &sq),
|
||||
[[100.0, 50.0, 150.0, 100.0], [160.0, 50.0, 210.0, 100.0], [100.0, 110.0, 150.0, 160.0], [160.0, 110.0, 210.0, 160.0]]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn three_squares_in_a_row_get_one_horizontal_layout_without_nesting() {
|
||||
let mut s = Session::new();
|
||||
let f = frame(&mut s, 20.0, 30.0, 200.0, 100.0);
|
||||
let sq = [0.0, 70.0, 140.0].map(|x| rect(&mut s, f, x, 25.0, 50.0, 50.0));
|
||||
let before = boxes(&s, &sq);
|
||||
let result = ex(&mut s, "layout.suggest", json!({"ids": [f]}));
|
||||
assert!(warnings(&result).is_empty(), "{result}");
|
||||
assert_eq!(mode(&s, f), Some(LayoutMode::Horizontal));
|
||||
assert_eq!(kids(&s, f), sq, "the squares are the frame's own layers");
|
||||
assert_eq!(boxes(&s, &sq), before);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn three_squares_in_a_column_get_one_vertical_layout_without_nesting() {
|
||||
let mut s = Session::new();
|
||||
let f = frame(&mut s, 20.0, 30.0, 100.0, 200.0);
|
||||
let sq = [0.0, 70.0, 140.0].map(|y| rect(&mut s, f, 25.0, y, 50.0, 50.0));
|
||||
let before = boxes(&s, &sq);
|
||||
let result = ex(&mut s, "layout.suggest", json!({"ids": [f]}));
|
||||
assert!(warnings(&result).is_empty(), "{result}");
|
||||
assert_eq!(mode(&s, f), Some(LayoutMode::Vertical));
|
||||
assert_eq!(kids(&s, f), sq);
|
||||
assert_eq!(boxes(&s, &sq), before);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_header_above_two_columns_of_squares_gives_a_row_per_line() {
|
||||
let mut s = Session::new();
|
||||
let f = frame(&mut s, 0.0, 0.0, 200.0, 200.0);
|
||||
let header = rect(&mut s, f, 0.0, 0.0, 200.0, 50.0);
|
||||
let sq = [(0.0, 60.0), (0.0, 120.0), (110.0, 60.0), (110.0, 120.0)].map(|(x, y)| rect(&mut s, f, x, y, 50.0, 50.0));
|
||||
let all = [vec![header], sq.to_vec()].concat();
|
||||
let before = boxes(&s, &all);
|
||||
let result = ex(&mut s, "layout.suggest", json!({"ids": [f]}));
|
||||
assert!(warnings(&result).is_empty(), "{result}");
|
||||
// The squares line up in two rows, so the gaps between rows win over the gap between columns.
|
||||
assert_eq!(mode(&s, f), Some(LayoutMode::Vertical));
|
||||
let top = kids(&s, f);
|
||||
assert_eq!(top.len(), 3);
|
||||
assert_eq!(top.first(), Some(&header));
|
||||
assert_band(&s, top[1], LayoutMode::Horizontal);
|
||||
assert_eq!(kids(&s, top[1]), vec![sq[0], sq[2]]);
|
||||
assert_band(&s, top[2], LayoutMode::Horizontal);
|
||||
assert_eq!(kids(&s, top[2]), vec![sq[1], sq[3]]);
|
||||
assert_eq!(boxes(&s, &all), before);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_header_above_a_tall_layer_beside_a_column_nests_three_levels() {
|
||||
let mut s = Session::new();
|
||||
let f = frame(&mut s, 40.0, 10.0, 200.0, 200.0);
|
||||
let header = rect(&mut s, f, 0.0, 0.0, 200.0, 40.0);
|
||||
let tall = rect(&mut s, f, 0.0, 60.0, 50.0, 110.0);
|
||||
let sq = [60.0, 120.0].map(|y| rect(&mut s, f, 110.0, y, 50.0, 50.0));
|
||||
let all = [header, tall, sq[0], sq[1]];
|
||||
let before = boxes(&s, &all);
|
||||
let result = ex(&mut s, "layout.suggest", json!({"ids": [f]}));
|
||||
assert!(warnings(&result).is_empty(), "{result}");
|
||||
assert_eq!(mode(&s, f), Some(LayoutMode::Vertical));
|
||||
let top = kids(&s, f);
|
||||
assert_eq!(top.len(), 2);
|
||||
assert_eq!(top.first(), Some(&header));
|
||||
let band = top[1];
|
||||
assert_band(&s, band, LayoutMode::Horizontal);
|
||||
let cols = kids(&s, band);
|
||||
assert_eq!(cols.len(), 2);
|
||||
assert_eq!(cols.first(), Some(&tall));
|
||||
assert_band(&s, cols[1], LayoutMode::Vertical);
|
||||
assert_eq!(kids(&s, cols[1]), sq);
|
||||
assert_eq!(boxes(&s, &all), before);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unequal_gaps_use_the_smallest_and_say_so() {
|
||||
let mut s = Session::new();
|
||||
let f = frame(&mut s, 0.0, 0.0, 300.0, 100.0);
|
||||
let sq = [0.0, 60.0, 130.0].map(|x| rect(&mut s, f, x, 10.0, 50.0, 50.0));
|
||||
let result = ex(&mut s, "layout.suggest", json!({"ids": [f]}));
|
||||
assert_eq!(mode(&s, f), Some(LayoutMode::Horizontal));
|
||||
let w = warnings(&result);
|
||||
assert_eq!(w.len(), 1, "{result}");
|
||||
assert!(w[0].contains("gaps"), "{}", w[0]);
|
||||
let b = boxes(&s, &sq);
|
||||
assert_eq!(b[0], [0.0, 10.0, 50.0, 60.0]);
|
||||
assert_eq!(b[1], [60.0, 10.0, 110.0, 60.0]);
|
||||
assert_eq!(b[2], [120.0, 10.0, 170.0, 60.0], "the last square moves along the row only");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn overlapping_layers_leave_the_frame_without_auto_layout_and_say_so() {
|
||||
let mut s = Session::new();
|
||||
let f = frame(&mut s, 0.0, 0.0, 200.0, 200.0);
|
||||
let a = rect(&mut s, f, 0.0, 0.0, 100.0, 100.0);
|
||||
let b = rect(&mut s, f, 50.0, 50.0, 100.0, 100.0);
|
||||
let result = ex(&mut s, "layout.suggest", json!({"ids": [f]}));
|
||||
assert_eq!(mode(&s, f), None);
|
||||
assert_eq!(kids(&s, f), vec![a, b]);
|
||||
assert_eq!(warnings(&result).len(), 1, "{result}");
|
||||
assert_eq!(boxes(&s, &[a, b]), vec![[0.0, 0.0, 100.0, 100.0], [50.0, 50.0, 150.0, 150.0]]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_group_becomes_a_frame_in_place_and_follows_the_rules() {
|
||||
let mut s = Session::new();
|
||||
let page = s.page().unwrap();
|
||||
let (a, b, c, d) = (
|
||||
rect(&mut s, page, 10.0, 20.0, 40.0, 40.0),
|
||||
rect(&mut s, page, 70.0, 20.0, 40.0, 40.0),
|
||||
rect(&mut s, page, 10.0, 80.0, 40.0, 40.0),
|
||||
rect(&mut s, page, 70.0, 80.0, 40.0, 40.0),
|
||||
);
|
||||
let group = id(&ex(&mut s, "object.group", json!({"ids": [a, b, c, d]})));
|
||||
let before = boxes(&s, &[group, a, b, c, d]);
|
||||
let result = ex(&mut s, "layout.suggest", json!({"ids": [group]}));
|
||||
assert_eq!(result["ids"], json!([group]), "the group keeps its identity");
|
||||
assert!(matches!(s.doc().unwrap().node(group).unwrap().kind, NodeKind::Frame));
|
||||
assert_eq!(mode(&s, group), Some(LayoutMode::Vertical));
|
||||
let rows = kids(&s, group);
|
||||
assert_eq!(rows.len(), 2);
|
||||
assert_band(&s, rows[0], LayoutMode::Horizontal);
|
||||
assert_eq!(kids(&s, rows[0]), vec![a, b]);
|
||||
assert_eq!(kids(&s, rows[1]), vec![c, d]);
|
||||
assert_eq!(boxes(&s, &[group, a, b, c, d]), before);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn several_layers_are_wrapped_in_a_frame_that_is_then_split() {
|
||||
let mut s = Session::new();
|
||||
let page = s.page().unwrap();
|
||||
let sq = [(0.0, 0.0), (80.0, 0.0), (0.0, 80.0), (80.0, 80.0)].map(|(x, y)| rect(&mut s, page, x, y, 50.0, 50.0));
|
||||
let before = boxes(&s, &sq);
|
||||
let result = ex(&mut s, "layout.suggest", json!({"ids": sq}));
|
||||
let wrapper = id_of(&result["ids"][0]).unwrap();
|
||||
assert!(s.doc().unwrap().node(wrapper).unwrap().fills.is_empty());
|
||||
assert_eq!(mode(&s, wrapper), Some(LayoutMode::Vertical));
|
||||
assert_eq!(kids(&s, wrapper).len(), 2);
|
||||
assert_eq!(boxes(&s, &sq), before);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_direction_forces_the_top_level_and_nested_frames_follow_the_gaps() {
|
||||
let (mut s, f, sq) = squares();
|
||||
let before = boxes(&s, &sq);
|
||||
let result = ex(&mut s, "layout.suggest", json!({"ids": [f], "direction": "horizontal"}));
|
||||
assert!(warnings(&result).is_empty(), "{result}");
|
||||
assert_eq!(mode(&s, f), Some(LayoutMode::Horizontal));
|
||||
let cols = kids(&s, f);
|
||||
assert_eq!(cols.len(), 2, "two columns");
|
||||
assert_band(&s, cols[0], LayoutMode::Vertical);
|
||||
assert_eq!(kids(&s, cols[0]), vec![sq[0], sq[2]]);
|
||||
assert_band(&s, cols[1], LayoutMode::Vertical);
|
||||
assert_eq!(kids(&s, cols[1]), vec![sq[1], sq[3]]);
|
||||
assert_eq!(boxes(&s, &sq), before);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_frame_with_one_layer_is_laid_out_like_add_auto_layout() {
|
||||
let mut s = Session::new();
|
||||
let f = frame(&mut s, 0.0, 0.0, 200.0, 100.0);
|
||||
let a = rect(&mut s, f, 20.0, 20.0, 60.0, 40.0);
|
||||
let result = ex(&mut s, "layout.suggest", json!({"ids": [f]}));
|
||||
assert!(warnings(&result).is_empty(), "{result}");
|
||||
assert_eq!(mode(&s, f), Some(LayoutMode::Horizontal));
|
||||
assert_eq!(kids(&s, f), vec![a]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn add_auto_layout_still_makes_a_single_row() {
|
||||
let (mut s, f, sq) = squares();
|
||||
ex(&mut s, "layout.add", json!({"ids": [f]}));
|
||||
let mut got = kids(&s, f);
|
||||
got.sort();
|
||||
assert_eq!(got, sq.to_vec(), "no nested frames");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_centred_title_above_a_card_is_lined_up_at_the_card_edge_with_a_warning() {
|
||||
let mut s = Session::new();
|
||||
let f = frame(&mut s, 0.0, 0.0, 200.0, 200.0);
|
||||
let title = rect(&mut s, f, 60.0, 0.0, 80.0, 30.0);
|
||||
let card = rect(&mut s, f, 0.0, 40.0, 200.0, 100.0);
|
||||
let result = ex(&mut s, "layout.suggest", json!({"ids": [f]}));
|
||||
assert_eq!(mode(&s, f), Some(LayoutMode::Vertical));
|
||||
assert_eq!(kids(&s, f), vec![title, card]);
|
||||
let w = warnings(&result);
|
||||
assert_eq!(w.len(), 1, "{result}");
|
||||
assert!(w[0].contains("different offsets"), "{}", w[0]);
|
||||
assert_eq!(page_box(&s, title), [0.0, 0.0, 80.0, 30.0], "the title's left edge is the card's now");
|
||||
assert_eq!(page_box(&s, card), [0.0, 40.0, 200.0, 140.0], "the rest stays");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn instances_and_layers_inside_them_are_refused_and_a_main_component_works() {
|
||||
let mut s = Session::new();
|
||||
let f = frame(&mut s, 0.0, 0.0, 200.0, 200.0);
|
||||
rect(&mut s, f, 0.0, 0.0, 50.0, 50.0);
|
||||
rect(&mut s, f, 0.0, 60.0, 50.0, 30.0);
|
||||
let nested = id(&ex(&mut s, "frame.create", json!({"parent": f, "x": 0, "y": 100, "width": 100, "height": 50})));
|
||||
rect(&mut s, nested, 0.0, 0.0, 20.0, 20.0);
|
||||
rect(&mut s, nested, 40.0, 0.0, 20.0, 20.0);
|
||||
let comp = id(&ex(&mut s, "component.create", json!({"ids": [f]})));
|
||||
let inst = id(&ex(&mut s, "instance.create", json!({"component": comp, "x": 400, "y": 0})));
|
||||
let inside: Vec<NodeId> = kids(&s, inst).into_iter().filter(|k| matches!(s.doc().unwrap().node(*k).unwrap().kind, NodeKind::Frame)).collect();
|
||||
assert!(!inside.is_empty(), "the instance has a frame of its own");
|
||||
let page = s.page().unwrap();
|
||||
let snapshot = |s: &Session| (kids(s, page), kids(s, inst), kids(s, inside[0]));
|
||||
let before = snapshot(&s);
|
||||
let steps = s.ds().unwrap().history.undo.len();
|
||||
for target in [inst, inside[0]] {
|
||||
let e = s.execute("layout.suggest", &json!({"ids": [target]})).unwrap_err().to_string();
|
||||
assert!(e.contains("instance"), "{e}");
|
||||
}
|
||||
assert_eq!(snapshot(&s), before, "nothing changed");
|
||||
assert_eq!(s.ds().unwrap().history.undo.len(), steps, "no history step");
|
||||
assert!(s.doc().unwrap().node(inst).unwrap().layout.is_none());
|
||||
// The main component is a frame and works.
|
||||
let result = ex(&mut s, "layout.suggest", json!({"ids": [comp]}));
|
||||
assert_eq!(result["ids"], json!([comp]));
|
||||
}
|
||||
@@ -393,6 +393,8 @@ mod jpg_export_tests;
|
||||
#[cfg(test)]
|
||||
mod keymap_tests;
|
||||
#[cfg(test)]
|
||||
mod layout_suggest_tests;
|
||||
#[cfg(test)]
|
||||
mod library_beacon_tests;
|
||||
#[cfg(test)]
|
||||
mod library_path_tests;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# Auto layout and constraints parity
|
||||
|
||||
> **Last reviewed:** 2026-10-11 · **Last updated:** 2026-11-03 · **Change:** patch (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-03 · **Change:** patch (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%,
|
||||
@@ -92,7 +92,8 @@ Status: **pass** (a case in the suite holds), **fixed** (the suite found a diver
|
||||
| Arrow keys move children one place (flows, rows, columns, grid cells, into neighbours) | done | `al_keys_tests.rs` |
|
||||
| Constraints: left, right, left and right, centre, scale; top/bottom likewise | done | |
|
||||
| Layout grids: columns, rows, grid; stretch/left/centre/right; variables bound | done | |
|
||||
| Suggest auto layout / "Add auto layout" on a selection | done | the Layout sidebar exposes Add auto layout (+) for groups and frames using the same `layout.add` command as the context menu; a single group becomes a frame in place, keeping its id, name and direct children; adding auto layout to an empty frame keeps its size, Fixed (it collapsed to 20×20); a frame with content still hugs it, as does a new frame wrapped around a selection (#369). `node.set` with auto layout keys on a mix of layers applies them to the frames and warns about the rest instead of failing the whole call (#603) |
|
||||
| Suggest auto layout | done | The target works out which layers belong together and adds as many auto layout frames as the design needs, in one step, keeping the placement. `layout.suggest` used to run `layout.add` and made one row of everything (#1823). Now it splits a frame's layers, by their boxes in the frame, along the vertical axis first: sorted by top edge, a layer joins the current row while it starts above the row's bottom (or together with it), and a gap, even a zero one, between the row and the next layer starts a new row. With two or more rows the frame becomes a Vertical auto layout whose items are the rows; otherwise the same split by columns gives a Horizontal one; if the layers overlap along both axes the frame gets no auto layout and the result carries a warning. A row or column of several layers goes into a new frame without fill or clipping, sized to it and inserted in its place (it hugs its content once the split gives it auto layout; a band whose own layers overlap along both axes gets none, with a warning, and stays a Fixed frame that cannot reflow those layers), and the split repeats inside it, to a depth of 16 and for up to 1,000 layers per frame (past that, or when a mask is among the layers, the layers are laid out in one list as Add auto layout does, with a warning). The frame keeps its size, Fixed: the gap is the distance between the bands, the padding along the flow is the first band's offset and the room left after the last, across the flow the smallest offset (alignment start), so with equal gaps and bands that start at the same offset every layer keeps its box exactly. When the gaps differ by more than 0.5 px the smallest is used and `warnings` says the later bands move; when the bands start at different offsets across the flow (a centred title above a card) they line up at the smallest, which moves the others, and `warnings` says so. Instances and layers inside them are refused with the error Convert to group gives, before anything changes; a main component works. `direction` sets the top level only. A single group becomes a frame in place and several layers are wrapped in a frame (both hug), as Add auto layout does; a frame with fewer than two layers is laid out as Add auto layout does. One undo step. Tests in `crates/engine/src/layout_suggest_tests.rs`: `two_rows_of_two_squares_become_a_vertical_frame_of_two_horizontal_rows`, `suggesting_auto_layout_is_one_undo_step`, `three_squares_in_a_row_get_one_horizontal_layout_without_nesting`, `three_squares_in_a_column_get_one_vertical_layout_without_nesting`, `a_header_above_two_columns_of_squares_gives_a_row_per_line`, `a_header_above_a_tall_layer_beside_a_column_nests_three_levels`, `unequal_gaps_use_the_smallest_and_say_so`, `overlapping_layers_leave_the_frame_without_auto_layout_and_say_so`, `a_group_becomes_a_frame_in_place_and_follows_the_rules`, `several_layers_are_wrapped_in_a_frame_that_is_then_split`, `a_direction_forces_the_top_level_and_nested_frames_follow_the_gaps`, `a_frame_with_one_layer_is_laid_out_like_add_auto_layout`, `add_auto_layout_still_makes_a_single_row`, `a_centred_title_above_a_card_is_lined_up_at_the_card_edge_with_a_warning`, `instances_and_layers_inside_them_are_refused_and_a_main_component_works`. Not attempted: overlapping layers, keeping uneven offsets across the flow (they line up at the smallest, with a warning), grids |
|
||||
| "Add auto layout" on a selection | done | the Layout sidebar exposes Add auto layout (+) for groups and frames using the same `layout.add` command as the context menu; a single group becomes a frame in place, keeping its id, name and direct children; adding auto layout to an empty frame keeps its size, Fixed (it collapsed to 20×20); a frame with content still hugs it, as does a new frame wrapped around a selection (#369). `node.set` with auto layout keys on a mix of layers applies them to the frames and warns about the rest instead of failing the whole call (#603) |
|
||||
| Real Figma files laid out identically | **not checked** | needs `.fig` or REST import of real files ([gaps](gaps.md) #1, #3) |
|
||||
| Performance: re-flow only where sizes or places changed | done | measured in `cargo xtask bench` (components at scale) |
|
||||
|
||||
@@ -100,6 +101,7 @@ Status: **pass** (a case in the suite holds), **fixed** (the suite found a diver
|
||||
|
||||
| Date | Change | Summary |
|
||||
|---|---|---|
|
||||
| 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-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. |
|
||||
| 2026-11-02 | patch | M2, #1824: fill container children share the free space by their content area: each one's own insets (padding and an included inside stroke, from the same `insets` the frame uses) come off the free space before the equal split and go back on its share, so a child with more padding or a thicker inside stroke takes a little more and the content areas match ("Figma distributes space amongst fill container children by the children's content area instead of by their size, matching the CSS border-box model", Use auto layout with CSS Flexbox in mind). Min and max still clamp the outer sizes and the frozen-share loop is as it was; children without insets split as before. Test: `nested_tests::fill_children_share_by_content_area` |
|
||||
| 2026-11-02 | patch | M2, #1838: a double-click on an edge of an auto layout frame's bounding box sets Hug contents on that axis, Alt+double-click on an edge of a child's Fill container ("Double-click the vertical or horizontal edge of an auto layout object's bounding box to set it to Hug contents", "Hold ⌥ Option or Alt and double-click ... to set it to Fill container", Guide to auto layout); a vertical edge sizes the width, a horizontal one the height; the Keyboard shortcuts panel lists both gestures. Test: `double_click_tests::a_double_click_on_an_auto_layout_edge_hugs_and_with_alt_fills`. Numbers unchanged. |
|
||||
|
||||
Reference in New Issue
Block a user