diff --git a/crates/engine/src/al_behaviour_tests.rs b/crates/engine/src/al_behaviour_tests.rs index 49950de6d..2e1f01b4e 100644 --- a/crates/engine/src/al_behaviour_tests.rs +++ b/crates/engine/src/al_behaviour_tests.rs @@ -72,6 +72,127 @@ fn fill_on_a_child_turns_the_hugging_parent_fixed() { assert_eq!(sizing(&s, f), (Sizing::Hug, Sizing::Hug)); } +fn name_of(s: &Session, node: NodeId) -> String { + s.doc().unwrap().node(node).unwrap().name.clone() +} + +/// Measured in Figma web (2026-11-08): across the flow a Fill child +/// leaves its hugging parent hugging and takes the line's cross size; the parent turns Fixed (with +/// a notice) only when no non-Fill child is left on that axis. +#[test] +fn fill_across_a_hugging_parent_keeps_it_hugging_and_takes_the_line() { + let mut s = Session::new(); + let f = al_frame(&mut s, json!({"sizingH": "hug", "sizingV": "hug"})); + let a = rect(&mut s, f, 4.0, 20.0, "#FF0000"); + let b = rect(&mut s, f, 50.0, 40.0, "#0000FF"); + assert_eq!(size(&s, f), (54.0, 40.0)); + s.message = None; + set(&mut s, a, json!({"sizingV": "fill"})); + assert_eq!(sizing(&s, f), (Sizing::Hug, Sizing::Hug), "a non-Fill sibling is left: the parent keeps hugging"); + assert_eq!(sizing(&s, a), (Sizing::Fixed, Sizing::Fill)); + assert_eq!((size(&s, a), size(&s, f)), ((4.0, 40.0), (54.0, 40.0))); + assert_eq!(s.message, None, "no notice"); + // The sibling grows: the bar and the parent follow. + set(&mut s, b, json!({"height": 60})); + assert_eq!((size(&s, a), size(&s, f)), ((4.0, 60.0), (54.0, 60.0))); + // The last non-Fill child fills too: the parent turns Fixed at its current height, with a notice. + set(&mut s, b, json!({"sizingV": "fill"})); + assert_eq!(sizing(&s, f), (Sizing::Hug, Sizing::Fixed)); + assert_eq!(s.message, Some(format!("Height set to Fixed for {}", name_of(&s, f)))); + assert_eq!((size(&s, a), size(&s, b), size(&s, f)), ((4.0, 60.0), (50.0, 60.0), (54.0, 60.0))); + set(&mut s, f, json!({"height": 80})); + assert_eq!((size(&s, a), size(&s, b)), ((4.0, 80.0), (50.0, 80.0))); + // One undo step puts the sizing back. + s.undo().unwrap(); + s.undo().unwrap(); + assert_eq!(sizing(&s, f), (Sizing::Hug, Sizing::Hug)); + assert_eq!(sizing(&s, b), (Sizing::Fixed, Sizing::Fixed)); +} + +#[test] +fn fill_along_a_hugging_parent_notes_that_the_width_is_fixed() { + let mut s = Session::new(); + let f = al_frame(&mut s, json!({"sizingH": "hug", "sizingV": "hug"})); + let a = rect(&mut s, f, 50.0, 20.0, "#FF0000"); + rect(&mut s, f, 30.0, 40.0, "#0000FF"); + s.message = None; + set(&mut s, a, json!({"sizingH": "fill"})); + assert_eq!(sizing(&s, f), (Sizing::Fixed, Sizing::Hug)); + assert_eq!(s.message, Some(format!("Width set to Fixed for {}", name_of(&s, f)))); + // A Fill that changes nothing about the parent has no notice. + s.message = None; + set(&mut s, a, json!({"sizingV": "fill"})); + assert_eq!(s.message, None); +} + +#[test] +fn hugging_a_row_notes_the_child_that_filled_its_width_turned_fixed() { + let mut s = Session::new(); + let f = al_frame(&mut s, json!({"sizingH": "fixed", "sizingV": "fixed"})); + let a = rect(&mut s, f, 50.0, 20.0, "#FF0000"); + rect(&mut s, f, 30.0, 40.0, "#0000FF"); + set(&mut s, a, json!({"sizingH": "fill"})); + assert_eq!(sizing(&s, a).0, Sizing::Fill); + s.message = None; + set(&mut s, f, json!({"sizingH": "hug"})); + assert_eq!(sizing(&s, a).0, Sizing::Fixed); + assert_eq!(s.message, Some(format!("Width set to Fixed for {}", name_of(&s, a)))); +} + +#[test] +fn hugging_a_row_keeps_and_does_not_note_the_child_that_fills_across_it() { + let mut s = Session::new(); + let f = al_frame(&mut s, json!({"sizingH": "fixed", "sizingV": "fixed"})); + let a = rect(&mut s, f, 50.0, 20.0, "#FF0000"); + rect(&mut s, f, 30.0, 40.0, "#0000FF"); + set(&mut s, a, json!({"sizingV": "fill"})); + s.message = None; + set(&mut s, f, json!({"sizingV": "hug"})); + assert_eq!(sizing(&s, a).1, Sizing::Fill); + assert_eq!(s.message, None); +} + +#[test] +fn a_fill_childs_min_counts_toward_the_hugging_size() { + let mut s = Session::new(); + let f = al_frame(&mut s, json!({"sizingH": "hug", "sizingV": "hug"})); + let a = rect(&mut s, f, 4.0, 20.0, "#FF0000"); + let b = rect(&mut s, f, 50.0, 40.0, "#0000FF"); + set(&mut s, a, json!({"sizingV": "fill"})); + set(&mut s, a, json!({"minHeight": 50})); + assert_eq!(sizing(&s, f), (Sizing::Hug, Sizing::Hug)); + assert_eq!((size(&s, a), size(&s, b), size(&s, f)), ((4.0, 50.0), (50.0, 40.0), (54.0, 50.0))); +} + +#[test] +fn a_parent_set_back_to_hug_keeps_the_child_that_fills_across_it() { + let mut s = Session::new(); + let f = al_frame(&mut s, json!({"sizingH": "hug", "sizingV": "fixed", "height": 100})); + let a = rect(&mut s, f, 4.0, 20.0, "#FF0000"); + rect(&mut s, f, 50.0, 40.0, "#0000FF"); + set(&mut s, a, json!({"sizingV": "fill"})); + assert_eq!(size(&s, a), (4.0, 100.0)); + set(&mut s, f, json!({"sizingV": "hug"})); + assert_eq!(sizing(&s, a), (Sizing::Fixed, Sizing::Fill), "a non-Fill sibling is left on that axis"); + assert_eq!((size(&s, a), size(&s, f)), ((4.0, 40.0), (54.0, 40.0))); +} + +#[test] +fn fill_across_a_wrapping_row_that_hugs_that_axis_is_not_offered() { + let mut s = Session::new(); + let f = al_frame(&mut s, json!({"wrap": true, "sizingH": "fixed", "sizingV": "hug", "width": 120})); + let a = rect(&mut s, f, 40.0, 20.0, "#FF0000"); + let r = s.execute("node.set", &json!({"id": a, "props": {"sizingV": "fill"}})); + assert!(r.is_err(), "Fill height in a wrapping row that hugs its height"); + assert_eq!(sizing(&s, a), (Sizing::Fixed, Sizing::Fixed)); + assert_eq!(sizing(&s, f), (Sizing::Fixed, Sizing::Hug)); + // Along the flow a wrapping row still takes Fill width, and with a fixed height Fill height. + set(&mut s, a, json!({"sizingH": "fill"})); + set(&mut s, f, json!({"sizingV": "fixed"})); + set(&mut s, a, json!({"sizingV": "fill"})); + assert_eq!(sizing(&s, a), (Sizing::Fill, Sizing::Fill)); +} + #[test] fn a_child_resized_to_the_full_available_space_becomes_fill() { // Documented: "Child objects of an auto layout frame will also be set to Fill container if diff --git a/crates/engine/src/assets/components/sync.rs b/crates/engine/src/assets/components/sync.rs index 513f4f7c8..b8c9bdf8d 100644 --- a/crates/engine/src/assets/components/sync.rs +++ b/crates/engine/src/assets/components/sync.rs @@ -336,6 +336,28 @@ fn index_old_layers(doc: &Document, inst: NodeId, spare: BTreeMap figcraft_doc::ChildLayout { + let mut cl = root.child_layout.clone(); + // One "size" override covers both axes, as in Figma ("Reset size"): it keeps both. + if root.overrides.contains("size") || root.overrides.contains("resizing") { + return cl; + } + let in_flow = root.parent.and_then(|p| doc.node(p)).is_some_and(|p| p.layout.is_some()); + let take = |own: &mut figcraft_doc::Sizing, main: figcraft_doc::Sizing| { + if !(in_flow && *own == figcraft_doc::Sizing::Fill) && main != figcraft_doc::Sizing::Fill { + *own = main; + } + }; + take(&mut cl.sizing_h, comp.child_layout.sizing_h); + take(&mut cl.sizing_v, comp.child_layout.sizing_v); + cl +} + /// The rebuilt root of instance `inst` of `comp`. fn fresh_root(doc: &Document, root: &mut Node, comp: &Node, inst: NodeId, component: NodeId, map: &BTreeMap) -> Node { // Root: follows the main except its own placement, name, size and overrides. @@ -351,7 +373,7 @@ fn fresh_root(doc: &Document, root: &mut Node, comp: &Node, inst: NodeId, compon let nested_copy = inside_instance(doc, inst); fresh.source = if nested_copy { root.source } else { Some(component) }; fresh.constraints = root.constraints; - fresh.child_layout = root.child_layout.clone(); + fresh.child_layout = instance_child_layout(doc, root, comp); fresh.interactions = root.interactions.clone(); fresh.exports = root.exports.clone(); fresh.prop_refs = root.prop_refs.clone(); diff --git a/crates/engine/src/cmd/edit/props.rs b/crates/engine/src/cmd/edit/props.rs index c39f8abe2..5bd6710af 100644 --- a/crates/engine/src/cmd/edit/props.rs +++ b/crates/engine/src/cmd/edit/props.rs @@ -163,6 +163,9 @@ pub(super) fn set(s: &mut Session, p: &Value) -> Result { names.join(", ") )); } + let mut hugging = crate::cmd::props::hugging_parents(&s.ds()?.doc, &ids, &props); + let filling = crate::cmd::props::filling_children(&s.ds()?.doc, &ids, &props); + let targets = ids.clone(); let doc = s.doc_mut()?; let before = crate::cmd::styles::bound_before(doc, &ids); let mut ids = ids; @@ -182,6 +185,20 @@ pub(super) fn set(s: &mut Session, p: &Value) -> Result { } } } + // A child that filled a hugging parent along its flow turned the parent Fixed: say so. + // A frame set to Hug turns the children that filled it along its flow Fixed. That is the + // coherence pass `normalize` runs once the command returns; run it here for those frames + // (idempotent) so the notice sees the demotion. + if !filling.is_empty() { + let doc = s.doc_mut()?; + for f in &targets { + figcraft_layout::coherent_sizing(doc, *f); + } + hugging.extend(filling); + } + if let Some(notice) = crate::cmd::props::fixed_notice(&s.ds()?.doc, &hugging) { + s.message = Some(notice); + } if warnings.is_empty() { ok() } else { Ok(json!({"ok": true, "warnings": warnings})) } } diff --git a/crates/engine/src/cmd/props.rs b/crates/engine/src/cmd/props.rs index 75889bb53..94b681381 100644 --- a/crates/engine/src/cmd/props.rs +++ b/crates/engine/src/cmd/props.rs @@ -1234,14 +1234,16 @@ pub fn apply(cmd: &str, doc: &mut Document, id: NodeId, props: &Map {} } - // A child can't fill an axis its parent hugs: the parent becomes fixed at its current size. - // (The other way round, a parent that starts to hug fixes the children that filled it: see - // `figcraft_layout::coherent_sizing`, applied after every edit.) + // A child can't fill the axis its parent hugs along the flow: the parent becomes fixed at its + // current size. Across the flow the parent keeps hugging and the child takes the line's size + // (the largest sibling that doesn't fill); the parent becomes fixed only when no such sibling + // is left. (The other way round, a parent that starts to hug fixes the children that filled it + // along the flow: see `figcraft_layout::coherent_sizing`, applied after every edit.) if s == Sizing::Fill && let Some(p) = parent { - let cl = &mut doc.get_mut(p)?.child_layout; - let ps = if horizontal { &mut cl.sizing_h } else { &mut cl.sizing_v }; - if *ps == Sizing::Hug { - *ps = Sizing::Fixed; + let pn = doc.get(p)?; + if figcraft_layout::wrapping_row_hugs_across(pn, horizontal) { + return Err(bad(cmd, "Fill container across a wrapping row is not offered")); + } + let along = match pn.layout.as_ref().map(|al| al.mode) { + Some(LayoutMode::Horizontal) => horizontal, + Some(LayoutMode::Vertical) => !horizontal, + _ => true, + }; + let others_fill = figcraft_layout::flow_children(doc, p) + .into_iter() + .filter(|c| *c != id) + .all(|c| doc.node(c).is_some_and(|c| (if horizontal { c.child_layout.sizing_h } else { c.child_layout.sizing_v }) == Sizing::Fill)); + if along || others_fill { + let cl = &mut doc.get_mut(p)?.child_layout; + let ps = if horizontal { &mut cl.sizing_h } else { &mut cl.sizing_v }; + if *ps == Sizing::Hug { + *ps = Sizing::Fixed; + // An instance's own root, or a layer inside one, turned Fixed by this edit: that + // is its resizing now, an override, or the next rebuild from the main would take + // the main's Hug back and the child would stop filling. + if doc.get(p)?.source.is_some() { + doc.get_mut(p)?.overrides.insert("resizing".to_string()); + } + } } } // Start from the sizing the layer has in effect (an auto-width text hugs both axes), so the @@ -1517,6 +1542,60 @@ fn set_sizing(cmd: &str, doc: &mut Document, id: NodeId, s: Sizing, horizontal: Ok(()) } +/// The hugging parents that `props` setting Fill on `ids` may turn Fixed, as (parent, horizontal): +/// taken before the edit, for [`fixed_notice`]. +pub(crate) fn hugging_parents(doc: &Document, ids: &[NodeId], props: &Map) -> Vec<(NodeId, bool)> { + let mut out = Vec::new(); + for (horizontal, keys) in [(true, ["sizingH", "layoutSizingHorizontal"]), (false, ["sizingV", "layoutSizingVertical"])] { + if !keys.iter().any(|k| props.get(*k).and_then(sizing) == Some(Sizing::Fill)) { + continue; + } + for p in ids.iter().filter_map(|i| doc.node(*i)).filter_map(|n| n.parent) { + let hugs = doc + .node(p) + .is_some_and(|p| p.layout.is_some() && (if horizontal { p.child_layout.sizing_h } else { p.child_layout.sizing_v }) == Sizing::Hug); + if hugs && !out.contains(&(p, horizontal)) { + out.push((p, horizontal)); + } + } + } + out +} + +/// The children, as (child, horizontal), that fill an axis of a frame in `ids` which `props` sets +/// to Hug: taken before the edit, for [`fixed_notice`] (the coherence pass turns them Fixed). +pub(crate) fn filling_children(doc: &Document, ids: &[NodeId], props: &Map) -> Vec<(NodeId, bool)> { + let mut out = Vec::new(); + for (horizontal, keys) in [(true, ["sizingH", "layoutSizingHorizontal"]), (false, ["sizingV", "layoutSizingVertical"])] { + if !keys.iter().any(|k| props.get(*k).and_then(sizing) == Some(Sizing::Hug)) { + continue; + } + for f in ids.iter().filter_map(|i| doc.node(*i)).filter(|n| n.layout.is_some() && n.kind.is_frame_like()) { + for c in f.children.iter().filter_map(|c| doc.node(*c)) { + let fills = (if horizontal { c.child_layout.sizing_h } else { c.child_layout.sizing_v }) == Sizing::Fill; + if fills && !out.contains(&(c.id, horizontal)) { + out.push((c.id, horizontal)); + } + } + } + } + out +} + +/// The notice for the layers of [`hugging_parents`] or [`filling_children`] that the edit turned +/// Fixed ("Height set to Fixed for Frame 1"), `None` when every one kept its sizing. +pub(crate) fn fixed_notice(doc: &Document, before: &[(NodeId, bool)]) -> Option { + let notes: Vec = before + .iter() + .filter_map(|(p, horizontal)| { + let p = doc.node(*p)?; + let now = if *horizontal { p.child_layout.sizing_h } else { p.child_layout.sizing_v }; + (now == Sizing::Fixed).then(|| format!("{} set to Fixed for {}", if *horizontal { "Width" } else { "Height" }, p.name)) + }) + .collect(); + (!notes.is_empty()).then(|| notes.join("; ")) +} + /// Resize a node's box from its top-left, applying constraints / group scaling to children. /// The page transforms of `id`'s children, to put back with [`restore_worlds`] once a container /// whose contents stay where they are on the page (a section; a frame resized with Cmd/Ctrl held) diff --git a/crates/engine/src/components_behaviour_tests.rs b/crates/engine/src/components_behaviour_tests.rs index 3565a3165..e8dda9e95 100644 --- a/crates/engine/src/components_behaviour_tests.rs +++ b/crates/engine/src/components_behaviour_tests.rs @@ -1002,6 +1002,180 @@ fn deleting_a_layer_inside_an_instance_hides_it_instead() { assert!(s.doc().unwrap().node(k.inst).is_none()); } +/// Issue 2090 item 2: after a main's child is set to fill, the instance's copy must match the main's +/// child (sizing, size) and the copy's parent must match the main's parent sizing. Relative, not +/// absolute, so it holds whatever the cross-axis rule is. +fn fill_matches_main(horizontal: bool, axis: &str) { + let hug_axis = if horizontal { "sizingV" } else { "sizingH" }; + fill_matches_main_hugging(horizontal, axis, hug_axis); +} + +/// As `fill_matches_main`, with the axis the main root hugs given explicitly. +fn fill_matches_main_hugging(horizontal: bool, axis: &str, hug_axis: &str) { + let mut s = Session::new(); + let mode = if horizontal { "horizontal" } else { "vertical" }; + let comp = idv(&ex(&mut s, "frame.create", json!({"x": 0, "y": 0, "width": 200, "height": 60, "name": "Note"}))); + let bar = idv(&ex(&mut s, "shape.rectangle", json!({"x": 0, "y": 0, "width": 3, "height": 20, "parent": comp, "props": {"name": "Bar"}}))); + ex(&mut s, "shape.rectangle", json!({"x": 0, "y": 0, "width": 50, "height": 40, "parent": comp, "props": {"name": "Body"}})); + ex(&mut s, "node.set", json!({"id": comp, "props": {"layout": mode, "gap": 12, "padding": 10, hug_axis: "hug"}})); + let comp = idv(&ex(&mut s, "component.create", json!({"ids": [comp]}))); + let inst = idv(&ex(&mut s, "instance.create", json!({"component": comp, "x": 400, "y": 0}))); + let bar = if node(&s, bar).parent.is_some() { bar } else { kids(&s, comp)[0] }; + ex(&mut s, "node.set", json!({"id": bar, "props": {axis: "fill"}})); + let ibar = copy_of(&s, inst, bar); + let (m, c) = (node(&s, bar), node(&s, ibar)); + let (mp, cp) = (node(&s, comp), node(&s, inst)); + eprintln!( + "{axis}: main bar {}x{} sizing {:?}/{:?}; copy {}x{} sizing {:?}/{:?}; main parent {}x{} {:?}/{:?}; inst {}x{} {:?}/{:?}", + m.width, + m.height, + m.child_layout.sizing_h, + m.child_layout.sizing_v, + c.width, + c.height, + c.child_layout.sizing_h, + c.child_layout.sizing_v, + mp.width, + mp.height, + mp.child_layout.sizing_h, + mp.child_layout.sizing_v, + cp.width, + cp.height, + cp.child_layout.sizing_h, + cp.child_layout.sizing_v + ); + assert_eq!((c.child_layout.sizing_h, c.child_layout.sizing_v), (m.child_layout.sizing_h, m.child_layout.sizing_v), "copy sizing"); + assert_eq!((c.width, c.height), (m.width, m.height), "copy size matches main child"); + assert_eq!( + (cp.child_layout.sizing_h, cp.child_layout.sizing_v), + (mp.child_layout.sizing_h, mp.child_layout.sizing_v), + "parent sizing matches main parent" + ); +} + +#[test] +fn instance_follows_main_child_fill_on_the_cross_axis() { + fill_matches_main(true, "sizingV"); +} + +#[test] +fn instance_follows_main_child_fill_on_the_main_axis() { + fill_matches_main(true, "sizingH"); +} + +#[test] +fn instance_follows_main_child_fill_along_a_hugging_main_axis() { + fill_matches_main_hugging(true, "sizingH", "sizingH"); +} + +/// A horizontal auto layout main hugging its width, with a "Bar" and a "Body" child, and an instance. +fn hugging_note(s: &mut Session) -> (NodeId, NodeId, NodeId) { + let comp = idv(&ex(s, "frame.create", json!({"x": 0, "y": 0, "width": 200, "height": 60, "name": "Note"}))); + let bar = idv(&ex(s, "shape.rectangle", json!({"x": 0, "y": 0, "width": 3, "height": 20, "parent": comp, "props": {"name": "Bar"}}))); + ex(s, "shape.rectangle", json!({"x": 0, "y": 0, "width": 50, "height": 40, "parent": comp, "props": {"name": "Body"}})); + ex(s, "node.set", json!({"id": comp, "props": {"layout": "horizontal", "gap": 12, "padding": 10, "sizingH": "hug"}})); + let comp = idv(&ex(s, "component.create", json!({"ids": [comp]}))); + let inst = idv(&ex(s, "instance.create", json!({"component": comp, "x": 400, "y": 0}))); + let bar = if node(s, bar).parent.is_some() { bar } else { kids(s, comp)[0] }; + (comp, inst, bar) +} + +fn sizing_h(s: &Session, id: NodeId) -> Sizing { + node(s, id).child_layout.sizing_h +} + +/// Measured in Figma: the main's root turning Fixed (set directly) reaches a plain instance, and +/// the main going back to Hug brings it back. +#[test] +fn a_plain_instances_resizing_follows_the_mains_root_both_ways() { + let mut s = Session::new(); + let (comp, inst, _) = hugging_note(&mut s); + assert_eq!(sizing_h(&s, inst), Sizing::Hug); + ex(&mut s, "node.set", json!({"id": comp, "props": {"sizingH": "fixed"}})); + assert_eq!(sizing_h(&s, comp), Sizing::Fixed); + assert_eq!(sizing_h(&s, inst), Sizing::Fixed, "the instance turns Fixed with its main"); + ex(&mut s, "node.set", json!({"id": comp, "props": {"sizingH": "hug"}})); + assert_eq!(sizing_h(&s, inst), Sizing::Hug, "and back to Hug with it"); +} + +/// Measured in Figma: a child set to Fill along the hugging axis turns the main Fixed; the plain +/// instance follows it, and follows it back to Hug. +#[test] +fn a_plain_instance_goes_fixed_and_back_to_hug_with_its_main() { + let mut s = Session::new(); + let (comp, inst, bar) = hugging_note(&mut s); + ex(&mut s, "node.set", json!({"id": bar, "props": {"sizingH": "fill"}})); + assert_eq!(sizing_h(&s, comp), Sizing::Fixed); + assert_eq!(sizing_h(&s, inst), Sizing::Fixed); + ex(&mut s, "node.set", json!({"id": comp, "props": {"sizingH": "hug"}})); + assert_eq!(sizing_h(&s, inst), Sizing::Hug); +} + +/// Measured in Figma: an instance whose width was typed keeps that Fixed width through both +/// changes, while its height kept hugging its content. Figma keeps one size override for both +/// axes, as FigCraft does: with the width typed, a change to a fixed main's height does not reach +/// the instance, and the only size reset is "Reset size" (measured 2026-11-09). +#[test] +fn an_instance_with_a_typed_width_keeps_it_when_the_main_turns_fixed_and_back() { + let mut s = Session::new(); + let (comp, inst, bar) = hugging_note(&mut s); + ex(&mut s, "node.set", json!({"id": inst, "props": {"width": 200}})); + assert_eq!(sizing_h(&s, inst), Sizing::Fixed); + assert_eq!(node(&s, inst).width, 200.0); + ex(&mut s, "node.set", json!({"id": bar, "props": {"sizingH": "fill"}})); + assert_eq!(sizing_h(&s, inst), Sizing::Fixed); + assert_eq!(node(&s, inst).width, 200.0, "the typed width stays"); + ex(&mut s, "node.set", json!({"id": comp, "props": {"sizingH": "hug"}})); + assert_eq!(sizing_h(&s, inst), Sizing::Fixed, "still Fixed after the main hugs again"); + assert_eq!(node(&s, inst).width, 200.0); +} + +/// An instance placed in an auto layout frame and set to Fill there keeps Fill when its main changes. +#[test] +fn an_instance_filling_its_auto_layout_parent_keeps_fill_when_the_main_changes() { + let mut s = Session::new(); + let (comp, inst, bar) = hugging_note(&mut s); + let row = idv(&ex(&mut s, "frame.create", json!({"x": 0, "y": 200, "width": 500, "height": 100, "name": "Row"}))); + ex(&mut s, "node.set", json!({"id": row, "props": {"layout": "horizontal"}})); + ex(&mut s, "node.reparent", json!({"ids": [inst], "parent": row})); + ex(&mut s, "node.set", json!({"id": inst, "props": {"sizingH": "fill"}})); + assert_eq!(sizing_h(&s, inst), Sizing::Fill); + ex(&mut s, "node.set", json!({"id": bar, "props": {"sizingH": "fill"}})); + assert_eq!(sizing_h(&s, comp), Sizing::Fixed); + assert_eq!(sizing_h(&s, inst), Sizing::Fill, "its own Fill in the row is kept"); + ex(&mut s, "node.set", json!({"id": comp, "props": {"sizingH": "hug"}})); + assert_eq!(sizing_h(&s, inst), Sizing::Fill); +} + +/// Inferred (Figma was measured only with a typed width): a Fixed set directly on an instance's +/// root, with no width typed, is an override the sync keeps when the main's root turns Hug, Fixed +/// and Hug again. +#[test] +fn an_instance_root_set_to_fixed_keeps_it_through_the_mains_resizing_changes() { + let mut s = Session::new(); + let (comp, inst, _) = hugging_note(&mut s); + ex(&mut s, "node.set", json!({"id": inst, "props": {"sizingH": "fixed"}})); + assert_eq!(sizing_h(&s, inst), Sizing::Fixed); + assert!(node(&s, inst).overrides.contains("resizing"), "{:?}", node(&s, inst).overrides); + ex(&mut s, "node.set", json!({"id": comp, "props": {"sizingH": "fixed"}})); + assert_eq!(sizing_h(&s, inst), Sizing::Fixed); + ex(&mut s, "node.set", json!({"id": comp, "props": {"sizingH": "hug"}})); + assert_eq!(sizing_h(&s, comp), Sizing::Hug); + assert_eq!(sizing_h(&s, inst), Sizing::Fixed, "its own Fixed stays after the main hugs again"); +} + +/// Resetting that instance brings its resizing back to the main's. +#[test] +fn resetting_an_instance_brings_its_own_resizing_back_to_the_mains() { + let mut s = Session::new(); + let (_, inst, _) = hugging_note(&mut s); + ex(&mut s, "node.set", json!({"id": inst, "props": {"sizingH": "fixed"}})); + assert_eq!(sizing_h(&s, inst), Sizing::Fixed); + ex(&mut s, "component.resetInstance", json!({"ids": [inst]})); + assert!(!node(&s, inst).overrides.contains("resizing")); + assert_eq!(sizing_h(&s, inst), Sizing::Hug, "the main hugs"); +} + /// Create multiple components (#2088): each selected layer becomes its own component in place, /// keeping its name and position; all stay selected and one undo reverts them all. #[test] diff --git a/crates/engine/src/instance_resizing_tests.rs b/crates/engine/src/instance_resizing_tests.rs index 43386af96..489fcbb1b 100644 --- a/crates/engine/src/instance_resizing_tests.rs +++ b/crates/engine/src/instance_resizing_tests.rs @@ -77,6 +77,34 @@ fn a_layer_in_an_instance_fills_and_keeps_it_through_main_edits() { healthy(&s); } +/// A child set to Fill along a hugging instance root turns the root Fixed: that is the root's own +/// resizing now, recorded as an override, so a later rebuild from the main (an edit of the main's +/// resizing or structure) keeps it Fixed and the child keeps filling. +#[test] +fn a_child_filling_a_hugging_instance_root_keeps_the_root_fixed_through_a_rebuild() { + let mut s = Session::new(); + let f = idv(&ex(&mut s, "frame.create", json!({"x": 0, "y": 0, "width": 120, "height": 40, "name": "Row"}))); + ex(&mut s, "node.set", json!({"id": f, "props": {"layout": "horizontal", "padding": 0, "gap": 0, "sizingH": "hug", "sizingV": "hug"}})); + let atom = idv(&ex(&mut s, "frame.create", json!({"x": 0, "y": 0, "width": 50, "height": 20, "parent": f, "name": "Atom"}))); + ex(&mut s, "node.set", json!({"id": atom, "props": {"layout": "horizontal", "padding": 0, "gap": 0, "sizingH": "hug", "sizingV": "hug"}})); + ex(&mut s, "shape.rectangle", json!({"x": 0, "y": 0, "width": 50, "height": 20, "parent": atom, "props": {"name": "Dot"}})); + let c = idv(&ex(&mut s, "component.create", json!({"ids": [f]}))); + let i = idv(&ex(&mut s, "instance.create", json!({"component": c, "x": 0, "y": 100}))); + let ia = copy_of(&s, i, atom); + assert_eq!((sizing_h(&s, i), sizing_h(&s, ia), node(&s, i).width), (Sizing::Hug, Sizing::Hug, 50.0)); + ex(&mut s, "node.set", json!({"id": ia, "props": {"sizingH": "fill"}})); + assert_eq!((sizing_h(&s, i), sizing_h(&s, ia)), (Sizing::Fixed, Sizing::Fill), "the root turned Fixed, the child fills"); + // The main's resizing changes, and its structure: both rebuild the instance. + ex(&mut s, "node.set", json!({"id": c, "props": {"minWidth": 60}})); + ex(&mut s, "shape.rectangle", json!({"x": 0, "y": 0, "width": 5, "height": 5, "parent": c})); + assert_eq!((sizing_h(&s, i), sizing_h(&s, ia)), (Sizing::Fixed, Sizing::Fill), "the root stays Fixed through the rebuild"); + assert!(node(&s, i).overrides.contains("resizing"), "{:?}", node(&s, i).overrides); + // Reset instance gives the main's Hug back. + ex(&mut s, "component.resetInstance", json!({"ids": [i]})); + assert_eq!(sizing_h(&s, i), Sizing::Hug); + healthy(&s); +} + #[test] fn size_and_resizing_overrides_undo_reset_and_detach() { let mut s = Session::new(); @@ -123,8 +151,10 @@ fn layers_in_instances_resize_but_keep_their_place() { for props in [json!({"x": 50}), json!({"rotation": 15}), json!({"constraints": {"horizontal": "right"}})] { assert!(s.execute("node.set", &json!({"id": it, "props": props})).is_err(), "{props} is refused"); } - // The instance's own resizing is its own, not an override. + // The instance's own resizing is recorded as an override (inferred), which Reset instance clears. ex(&mut s, "node.set", json!({"id": i, "props": {"minWidth": 100}})); + assert!(node(&s, i).overrides.contains("resizing")); + ex(&mut s, "component.resetInstance", json!({"ids": [i]})); assert!(!node(&s, i).overrides.contains("resizing")); healthy(&s); } diff --git a/crates/format/src/fig/auto_layout_sizing_tests.rs b/crates/format/src/fig/auto_layout_sizing_tests.rs index 29580afb9..4e04ebafa 100644 --- a/crates/format/src/fig/auto_layout_sizing_tests.rs +++ b/crates/format/src/fig/auto_layout_sizing_tests.rs @@ -8,18 +8,20 @@ use serde_json::{Value, json}; use super::kiwi::{Kv, Schema}; const SCHEMA: &str = " -enum NodeType NONE DOCUMENT CANVAS FRAME TEXT SYMBOL INSTANCE +enum NodeType NONE DOCUMENT CANVAS FRAME TEXT SYMBOL INSTANCE ROUNDED_RECTANGLE enum StackMode NONE HORIZONTAL VERTICAL enum StackSize FIXED RESIZE_TO_FIT RESIZE_TO_FIT_WITH_IMPLICIT_SIZE enum StackJustify MIN CENTER MAX SPACE_EVENLY SPACE_BETWEEN SPACE_AROUND SPACE_EVENLY_CSS +enum StackCounterAlign MIN CENTER MAX STRETCH AUTO BASELINE enum TextAutoResize NONE WIDTH_AND_HEIGHT HEIGHT struct GUID uint sessionID, uint localID struct Vector float x, float y struct Matrix float m00, float m01, float m02, float m10, float m11, float m12 message ParentIndex GUID guid, string position +message GUIDPath GUID[] guids message TextData string characters message SymbolData GUID symbolID -message NodeChange GUID guid, ParentIndex parentIndex, NodeType type, string name, Vector size, Matrix transform, StackMode stackMode, StackSize stackPrimarySizing, StackSize stackCounterSizing, StackJustify stackPrimaryAlignItems, TextAutoResize textAutoResize, float fontSize, TextData textData, SymbolData symbolData +message NodeChange GUID guid, ParentIndex parentIndex, NodeType type, string name, Vector size, Matrix transform, StackMode stackMode, StackSize stackPrimarySizing, StackSize stackCounterSizing, StackJustify stackPrimaryAlignItems, TextAutoResize textAutoResize, float fontSize, TextData textData, SymbolData symbolData, StackCounterAlign stackChildAlignSelf, NodeChange[] derivedSymbolData, GUIDPath guidPath message Message NodeChange[] nodeChanges "; @@ -216,3 +218,120 @@ fn distributed_alignment_reads_the_older_evenly_name_as_space_between() { assert_eq!(n.layout.as_ref().map(|l| l.main_align), Some(want), "{name}"); } } + +/// Issue 2091 item 3: a child with `stackChildAlignSelf: STRETCH` fills the cross axis. +#[test] +fn stretch_children_import_as_fill_on_the_cross_axis() { + use Sizing::Fill; + let stretch = || vec![("stackChildAlignSelf", Kv::Enum("STRETCH"))]; + let mut nodes = Vec::new(); + // (a) plain frame / (b) component, fixed and hug cross axis (d) + for (k, (ty, counter)) in + [("FRAME", "FIXED"), ("SYMBOL", "FIXED"), ("FRAME", "RESIZE_TO_FIT"), ("SYMBOL", "RESIZE_TO_FIT")].into_iter().enumerate() + { + let id = 100 * (k as u64 + 1); + let mut f = vec![("size", xy(100.0, 40.0)), ("transform", at(0.0, 60.0 * k as f64))]; + f.extend(stack("HORIZONTAL", Some("FIXED"), Some(counter))); + nodes.push(node(id, 1, &format!("{id}"), ty, &format!("Row{k}"), f)); + // (e) a rectangle and a text + nodes.push(node( + id + 1, + id, + "!", + "ROUNDED_RECTANGLE", + &format!("Bar{k}"), + [vec![("size", xy(3.0, 20.0)), ("transform", at(0.0, 0.0))], stretch()].concat(), + )); + let mut t = label(id + 2, id, &format!("Msg{k}"), Some("WIDTH_AND_HEIGHT")); + if let Kv::Object(fields) = &mut t { + fields.extend(stretch()); + } + nodes.push(t); + } + // (c) an instance of Row1 (a component) and its copy of the bar + nodes.push(node( + 900, + 1, + "~", + "INSTANCE", + "Inst", + vec![("size", xy(100.0, 40.0)), ("transform", at(200.0, 0.0)), ("symbolData", o(vec![("symbolID", g(200))]))], + )); + // (c2) same-size instance whose derived data gives the bar Figma's stretched 40 px; (c3) a taller + // instance (60) whose derived data gives 60. + for (id, name, h, bar_h) in [(901, "InstDerived", 40.0, 40.0), (902, "InstTall", 60.0, 60.0)] { + let row = o(vec![("guidPath", o(vec![("guids", Kv::Array(vec![g(201)]))])), ("size", xy(3.0, bar_h))]); + nodes.push(node( + id, + 1, + &format!("~{id}"), + "INSTANCE", + name, + vec![ + ("size", xy(100.0, h)), + ("transform", at(300.0, 0.0)), + ("symbolData", o(vec![("symbolID", g(200))])), + ("derivedSymbolData", Kv::Array(vec![row])), + ], + )); + } + let doc = import(nodes); + let get = |n: &str| doc.nodes().find(|x| x.name == n).unwrap_or_else(|| panic!("no layer {n}")); + let mut bad = Vec::new(); + for k in 0..4 { + for what in ["Bar", "Msg text"] { + let n = get(&if what == "Bar" { format!("Bar{k}") } else { format!("Msg{k} text") }); + if n.child_layout.sizing_v != Fill { + bad.push(format!("{what}{k} (row {k}): sizing_v {:?}, h {}", n.child_layout.sizing_v, n.size().1)); + } + } + } + let inst = get("Inst"); + let copy = inst.children.first().and_then(|c| doc.node(*c)).unwrap(); + if copy.child_layout.sizing_v != Fill { + bad.push(format!("instance copy of the bar: sizing_v {:?}, h {}", copy.child_layout.sizing_v, copy.size().1)); + } + for (name, want_h) in [("InstDerived", 40.0), ("InstTall", 60.0)] { + let inst = get(name); + let bar = inst.children.first().and_then(|c| doc.node(*c)).unwrap(); + if bar.child_layout.sizing_v != Fill || (bar.size().1 - want_h).abs() > 1e-6 { + bad.push(format!("{name} copy of the bar: sizing_v {:?}, h {} (want Fill, {want_h})", bar.child_layout.sizing_v, bar.size().1)); + } + } + assert!(bad.is_empty(), "{bad:#?}"); +} + +/// Issue 2091 item 3, after a layout pass: the stretched bar takes the row's cross size, also +/// when the row hugs (the bar next to a two-line text, whose height makes the row's). +#[test] +fn stretch_children_take_the_row_height_after_a_layout_pass() { + let mut nodes = Vec::new(); + // (name, counter sizing, row height, expected bar height after layout) + let rows = [("Fixed row", "FIXED", 40.0, 40.0), ("Hug row", "RESIZE_TO_FIT", 16.0, 16.0)]; + for (k, (name, counter, h, _)) in rows.iter().enumerate() { + let id = 100 * (k as u64 + 1); + let mut f = vec![("size", xy(100.0, *h)), ("transform", at(0.0, 60.0 * k as f64))]; + f.extend(stack("HORIZONTAL", Some("FIXED"), Some(counter))); + nodes.push(node(id, 1, &format!("{id}"), "FRAME", name, f)); + let bar = vec![("size", xy(3.0, 10.0)), ("transform", at(0.0, 0.0)), ("stackChildAlignSelf", Kv::Enum("STRETCH"))]; + nodes.push(node(id + 1, id, "!", "ROUNDED_RECTANGLE", &format!("Bar {name}"), bar)); + // The text sets the row's height: 16 px tall, fixed box. + let mut t = label(id + 2, id, name, Some("NONE")); + if let Kv::Object(fields) = &mut t { + fields.push(("transform", at(10.0, 0.0))); + } + nodes.push(t); + } + let mut doc = import(nodes); + let page = doc.first_page().unwrap(); + figcraft_layout::layout_page(&mut doc, page, &figcraft_layout::NoMeasure); + let mut bad = Vec::new(); + for (name, _, _, want) in rows { + let bar = doc.nodes().find(|n| n.name == format!("Bar {name}")).unwrap(); + let got = bar.size().1; + if (got - want).abs() > 1e-6 { + bad.push(format!("{name}: bar sizing_v {:?}, height {got}, want {want}", bar.child_layout.sizing_v)); + } + } + assert!(bad.is_empty(), "{bad:#?}"); +} diff --git a/crates/layout/src/behaviour_tests.rs b/crates/layout/src/behaviour_tests.rs index c0b9b983b..a17a563df 100644 --- a/crates/layout/src/behaviour_tests.rs +++ b/crates/layout/src/behaviour_tests.rs @@ -234,12 +234,13 @@ fn sizing_rules() { rects: &[(10.0, 10.0, 20.0, 80.0)], }, Case { - rule: "fill on an axis the frame hugs has nothing to fill: the child keeps its size", - // A hugging frame has no free space; it hugs 50 + 30. + rule: "fill along an axis the frame hugs has nothing to fill (the child keeps its size); across it the child takes the line", + // A hugging frame has no free space along the flow: it hugs 50 + 30. Across the flow the + // frame keeps hugging and the child takes the line's 20, the other child's height. frame: Frame { sizing: (Hug, Hug), ..FRAME }, kids: &[kid(50.0, 20.0), Kid { size: (30.0, 40.0), sizing: (Fill, Fill), ..KID }], - want: (80.0, 40.0), - rects: &[(0.0, 0.0, 50.0, 20.0), (50.0, 0.0, 30.0, 40.0)], + want: (80.0, 20.0), + rects: &[(0.0, 0.0, 50.0, 20.0), (50.0, 0.0, 30.0, 20.0)], }, Case { rule: "min width: a fixed child is never narrower than its minimum", @@ -290,6 +291,119 @@ fn sizing_rules() { ]); } +/// Measured in Figma web (2026-11-08): along the flow a Fill child turns +/// a hugging parent Fixed, but across the flow the parent keeps hugging and the Fill child takes +/// the line's cross size (the largest non-Fill sibling, its min counted, padding outside). +#[test] +fn fill_across_a_hugging_axis_rules() { + let bar = |w: f64, h: f64| Kid { size: (w, h), sizing: (Fixed, Fill), ..KID }; + let hug = Frame { sizing: (Hug, Hug), ..FRAME }; + check(&[ + Case { + rule: "round 1: a bar filling the height beside a taller sibling stretches to it, the row keeps hugging", + frame: hug, + kids: &[bar(4.0, 20.0), kid(50.0, 40.0)], + want: (54.0, 40.0), + rects: &[(0.0, 0.0, 4.0, 40.0), (4.0, 0.0, 50.0, 40.0)], + }, + Case { + rule: "round 1: the sibling grows to 60, the bar and the row follow", + frame: hug, + kids: &[bar(4.0, 20.0), kid(50.0, 60.0)], + want: (54.0, 60.0), + rects: &[(0.0, 0.0, 4.0, 60.0), (4.0, 0.0, 50.0, 60.0)], + }, + Case { + rule: "round 2 case 2: in a vertical stack hugging its width a Fill width takes the widest sibling", + frame: Frame { mode: V, ..hug }, + kids: &[Kid { size: (20.0, 10.0), sizing: (Fill, Fixed), ..KID }, kid(100.0, 30.0)], + want: (100.0, 40.0), + rects: &[(0.0, 0.0, 100.0, 10.0), (0.0, 10.0, 100.0, 30.0)], + }, + Case { + rule: "round 2 case 2: the sibling widens to 150, the Fill child follows", + frame: Frame { mode: V, ..hug }, + kids: &[Kid { size: (20.0, 10.0), sizing: (Fill, Fixed), ..KID }, kid(150.0, 30.0)], + want: (150.0, 40.0), + rects: &[(0.0, 0.0, 150.0, 10.0), (0.0, 10.0, 150.0, 30.0)], + }, + Case { + rule: "round 2 case 3: padding is outside the line: the bar gets the content box", + // 10 + 40 + 10. + frame: Frame { pad: [10.0, 0.0, 10.0, 0.0], ..hug }, + kids: &[bar(4.0, 20.0), kid(50.0, 40.0)], + want: (54.0, 60.0), + rects: &[(0.0, 10.0, 4.0, 40.0), (4.0, 10.0, 50.0, 40.0)], + }, + Case { + rule: "round 2 case 5: a Fill child's min counts toward the hug size", + frame: hug, + kids: &[Kid { min: (None, Some(50.0)), ..bar(4.0, 20.0) }, kid(50.0, 40.0)], + want: (54.0, 50.0), + rects: &[(0.0, 0.0, 4.0, 50.0), (4.0, 0.0, 50.0, 40.0)], + }, + Case { + rule: "round 2 case 6: beside a text the bar is as tall as the text (two lines)", + frame: hug, + kids: &[bar(3.0, 20.0), Kid { text: Some((80.0, 64.0, 24.0)), ..KID }], + want: (83.0, 64.0), + rects: &[(0.0, 0.0, 3.0, 64.0), (3.0, 0.0, 80.0, 64.0)], + }, + Case { + rule: "round 2 case 6: a third line and the bar and the row follow the text", + frame: hug, + kids: &[bar(3.0, 20.0), Kid { text: Some((80.0, 96.0, 24.0)), ..KID }], + want: (83.0, 96.0), + rects: &[(0.0, 0.0, 3.0, 96.0), (3.0, 0.0, 80.0, 96.0)], + }, + Case { + rule: "shrinking is real: a Fill child taller than the tallest non-Fill sibling comes down to it", + frame: hug, + kids: &[bar(4.0, 90.0), kid(50.0, 40.0)], + want: (54.0, 40.0), + rects: &[(0.0, 0.0, 4.0, 40.0), (4.0, 0.0, 50.0, 40.0)], + }, + Case { + rule: "round 2 case 1 (import-only state): nothing but Fill children across a hugging axis keep their own sizes", + frame: hug, + kids: &[bar(4.0, 20.0), bar(50.0, 40.0)], + want: (54.0, 40.0), + rects: &[(0.0, 0.0, 4.0, 20.0), (4.0, 0.0, 50.0, 40.0)], + }, + Case { + rule: "a text stretched to the line's width reflows taller: the Fill-height sibling takes what is left, not what it got before", + // The stack is 100 tall and hugs its width: the wider sibling makes the line 100, the text + // (200 wide) is 2 lines (40) at that width, so the Fill-height bar gets 100 - 40 - 10 = 50. + frame: Frame { mode: V, size: (100.0, 100.0), sizing: (Hug, Fixed), ..FRAME }, + kids: &[ + Kid { text: Some((200.0, 20.0, 15.0)), sizing: (Fill, Hug), ..KID }, + Kid { size: (30.0, 20.0), sizing: (Fixed, Fill), ..KID }, + kid(100.0, 10.0), + ], + want: (100.0, 100.0), + rects: &[(0.0, 0.0, 100.0, 40.0), (0.0, 40.0, 30.0, 50.0), (0.0, 90.0, 100.0, 10.0)], + }, + Case { + rule: "the same with a child that fills both axes: it takes the line's width and the left-over height", + frame: Frame { mode: V, size: (100.0, 100.0), sizing: (Hug, Fixed), ..FRAME }, + kids: &[ + Kid { text: Some((200.0, 20.0, 15.0)), sizing: (Fill, Hug), ..KID }, + Kid { size: (30.0, 20.0), sizing: (Fill, Fill), ..KID }, + kid(100.0, 10.0), + ], + want: (100.0, 100.0), + rects: &[(0.0, 0.0, 100.0, 40.0), (0.0, 40.0, 100.0, 50.0), (0.0, 90.0, 100.0, 10.0)], + }, + Case { + rule: "round 2 case 4: in a wrapping row hugging its height a Fill height still reads as fixed", + frame: Frame { size: (120.0, 100.0), sizing: (Fixed, Hug), wrap: true, ..FRAME }, + kids: &[bar(40.0, 30.0), kid(40.0, 10.0)], + want: (120.0, 30.0), + rects: &[(0.0, 0.0, 40.0, 30.0), (40.0, 0.0, 40.0, 10.0)], + }, + ]); +} + #[test] fn padding_and_stroke_rules() { let inside = Some((4.0, StrokeAlign::Inside, None)); diff --git a/crates/layout/src/lib.rs b/crates/layout/src/lib.rs index 443cc9310..38141584a 100644 --- a/crates/layout/src/lib.rs +++ b/crates/layout/src/lib.rs @@ -6,8 +6,9 @@ //! gap, padding and alignment; each child is Fixed, Hug (its own content) or Fill (shares the //! free space), within its min/max size. A Hug container sizes to its children. Absolute //! children (ignoring auto layout) are not placed; they follow their constraints instead. -//! - [`coherent_sizing`]: Fill and Hug only where they can apply (Fill in an auto layout flow on an -//! axis the parent doesn't hug; Hug on auto layout frames and text), else Fixed. +//! - [`coherent_sizing`]: Fill and Hug only where they can apply (Fill in an auto layout flow, except +//! along an axis the parent hugs and across a wrapping row that hugs that axis; Hug on auto layout +//! frames and text), else Fixed. //! - [`apply_constraints`]: children of a regular frame follow their constraints when it resizes. //! - [`grid_lines`]: the column/row rectangles of a layout grid, for drawing and snapping. //! @@ -167,9 +168,29 @@ pub fn flow_children(doc: &Document, frame: NodeId) -> Vec { f.children.iter().copied().filter(|c| doc.node(*c).is_some_and(|n| n.visible && !n.child_layout.absolute)).collect() } +/// Whether the parent frame `p` wraps and hugs `horizontal`'s axis, which is the cross axis of its +/// flow: Fill container is not offered there (Figma greys it out; a grid has no flow to wrap). +pub fn wrapping_row_hugs_across(p: &figcraft_doc::Node, horizontal: bool) -> bool { + let Some(al) = &p.layout else { return false }; + let hugs = if horizontal { p.child_layout.sizing_h } else { p.child_layout.sizing_v } == Sizing::Hug; + al.wrap && hugs && axis_is_main(al.mode, horizontal) == Some(false) +} + +/// Whether the horizontal (or vertical) axis is the main axis of a flow; `None` for a grid. +fn axis_is_main(mode: LayoutMode, horizontal: bool) -> Option { + match mode { + LayoutMode::Horizontal => Some(horizontal), + LayoutMode::Vertical => Some(!horizontal), + LayoutMode::Grid => None, + } +} + /// Make a layer's sizing coherent with where it sits (after an edit). Fill needs room to fill: a /// layer that isn't in an auto layout flow (no auto layout parent, or ignoring auto layout), or -/// whose parent hugs that axis, gets Fixed at its current size instead. Hug needs auto layout or +/// whose parent hugs the axis it is laid out along (a grid: either axis), gets Fixed at its +/// current size instead. Across the flow of a hugging parent Fill stays: the child takes the +/// line's cross size (the largest sibling that doesn't fill), except in a wrapping row, where +/// Fill across a hugging axis is not offered and reads as Fixed. Hug needs auto layout or /// text; otherwise it is Fixed too. A text hugs what its resize mode grows. The same applies to the /// layer's own children, so a frame that starts to hug (or loses auto layout) fixes the children /// that filled it. Returns whether anything changed. @@ -188,8 +209,18 @@ fn coherent_own_sizing(doc: &mut Document, id: NodeId) -> bool { let parent_hugs = |horizontal: bool| flow_parent.map(|p| if horizontal { p.child_layout.sizing_h } else { p.child_layout.sizing_v } == Sizing::Hug); let can_hug = (n.layout.is_some() && n.kind.is_frame_like()) || matches!(n.kind, NodeKind::Text(_)); + // Fill has nothing to fill without a flow parent, along an axis the parent hugs (it hugs the + // children), or across a wrapping row that hugs that axis. Across a hugging flow it stays. + let no_fill = |horizontal: bool| match (flow_parent, parent_hugs(horizontal)) { + (None, _) => true, + (Some(p), Some(true)) => { + let main = p.layout.as_ref().and_then(|al| axis_is_main(al.mode, horizontal)); + main != Some(false) || wrapping_row_hugs_across(p, horizontal) + } + _ => false, + }; let coherent = |s: Sizing, horizontal: bool| match s { - Sizing::Fill if parent_hugs(horizontal) != Some(false) => Sizing::Fixed, + Sizing::Fill if no_fill(horizontal) => Sizing::Fixed, Sizing::Hug if !can_hug => Sizing::Fixed, s => s, }; @@ -378,7 +409,11 @@ fn flow_line_extents(items: &mut [Item], lines: &[Vec], gap: f64) -> Vec< let in_line = || line.iter().filter_map(|i| items.get(*i)); let main_used = in_line().map(|item| item.main).sum::() + gaps; let all_fill = in_line().all(|item| item.fill_cross); - let cross = in_line().filter(|item| all_fill || !item.fill_cross).map(|item| item.base_off + item.cross).fold(0.0, f64::max); + // A child filling the cross axis takes the line's size, so it only counts with its min + // (nothing but fill children keep their own sizes). + let cross = in_line() + .map(|item| if !item.fill_cross || all_fill { item.base_off + item.cross } else { item.min_cross.unwrap_or(0.0) }) + .fold(0.0, f64::max); extents.push((main_used, cross)); } extents @@ -411,7 +446,7 @@ fn align_flow_lines(items: &[Item], extents: &mut [(f64, f64)], al: &AutoLayout, } /// Collect the size and sizing constraints of the children in flow order. -fn flow_items(doc: &Document, kids: &[NodeId], horizontal: bool, hug_main: bool, hug_cross: bool) -> Vec { +fn flow_items(doc: &Document, kids: &[NodeId], horizontal: bool, hug_main: bool, cross_fill_off: bool) -> Vec { let mut items = Vec::with_capacity(kids.len()); for child in kids { let Some(node) = doc.node(*child) else { continue }; @@ -428,9 +463,12 @@ fn flow_items(doc: &Document, kids: &[NodeId], horizontal: bool, hug_main: bool, id: *child, main: if horizontal { w } else { h }, cross: if horizontal { h } else { w }, - // Fill needs room to fill: on an axis the frame hugs it reads as fixed. + // Along an axis the frame hugs, Fill has nothing to fill and reads as fixed. Across the + // flow of a hugging frame the child takes the line's size (the largest sibling that + // doesn't fill: `stretch_fill_across_hug_line`), except in a wrapping row, where Fill + // across a hugging axis is not offered and reads as fixed too. fill_main: sm == Sizing::Fill && !hug_main, - fill_cross: sc == Sizing::Fill && !hug_cross, + fill_cross: sc == Sizing::Fill && !cross_fill_off, min_main, max_main, min_cross, @@ -443,6 +481,89 @@ fn flow_items(doc: &Document, kids: &[NodeId], horizontal: bool, hug_main: bool, items } +/// Size the children that fill the cross axis of a hugging frame's single line, whose children +/// that don't fill make it `line` across, to that size (the frame's own min/max, its `cross_pads` +/// outside the line, applied; the children's own min/max too), laying out a nested auto layout at +/// its new size. Nothing happens unless some children fill and some don't (a line of nothing but +/// fill children keeps their own sizes). Returns whether a child's main size changed (a text +/// filling the width of a vertical stack reflows to a new height), so the caller measures the line +/// again. +fn stretch_fill_across_hug_line( + doc: &mut Document, + items: &mut [Item], + line: f64, + (frame, cross_pads): (&figcraft_doc::ChildLayout, f64), + horizontal: bool, + m: &dyn Measure, +) -> bool { + if !items.iter().any(|it| it.fill_cross) || items.iter().all(|it| it.fill_cross) { + return false; + } + let (lo, hi) = if horizontal { (frame.min_h, frame.max_h) } else { (frame.min_w, frame.max_w) }; + let line_cross = clamp_size(line + cross_pads, lo, hi).max(cross_pads) - cross_pads; + let mut main_changed = false; + for it in items.iter_mut().filter(|it| it.fill_cross) { + let cross = clamp_size(line_cross, it.min_cross, it.max_cross); + let (w, h) = if horizontal { (it.main, cross) } else { (cross, it.main) }; + resize_child(doc, it.id, w, h, m); + let (w, h) = outer_size(doc, it.id); + let (main, cross) = if horizontal { (w, h) } else { (h, w) }; + main_changed |= (main - it.main).abs() > 1e-9; + (it.main, it.cross) = (main, cross); + } + main_changed +} + +/// Resize a child that fills the main axis to its distributed main size and the given cross size, +/// and take the size it ends up with across (wrapped text, a hugging frame). +fn resize_fill_main_item(doc: &mut Document, it: &mut Item, cross: f64, horizontal: bool, m: &dyn Measure) { + let (w, h) = if horizontal { (it.main, cross) } else { (cross, it.main) }; + resize_child(doc, it.id, w, h, m); + let (w, h) = outer_size(doc, it.id); + it.cross = if horizontal { h } else { w }; +} + +/// What `stretch_hug_line` needs to know about the frame: its limits and the padding across, the +/// flow direction, and the main-axis inner size, gap and auto gap the lines are distributed with. +struct HugStretch<'a> { + frame: (&'a figcraft_doc::ChildLayout, f64), + horizontal: bool, + flow: (f64, f64, bool), +} + +/// Stretch the cross-Fill children to a hugging frame's line (`stretch_fill_across_hug_line`). When +/// a main size changed (a text reflowed), the space the main-Fill children were given is stale: +/// share it again, resize them (a child filling both axes keeps the line's size across), measure +/// again, and follow the line if their cross sizes moved it. One extra pass. +fn stretch_hug_line( + doc: &mut Document, + items: &mut [Item], + lines: &[Vec], + line_extents: &mut Vec<(f64, f64)>, + st: &HugStretch<'_>, + m: &dyn Measure, +) { + let (frame, cross_pads) = st.frame; + let (inner_main, gap, auto_gap) = st.flow; + let line = line_extents.first().map_or(0.0, |l| l.1); + if !stretch_fill_across_hug_line(doc, items, line, (frame, cross_pads), st.horizontal, m) { + return; + } + *line_extents = flow_line_extents(items, lines, gap); + if !items.iter().any(|it| it.fill_main) { + return; + } + distribute_flow_lines(items, lines, inner_main, gap, auto_gap); + for it in items.iter_mut().filter(|it| it.fill_main) { + resize_fill_main_item(doc, it, it.cross, st.horizontal, m); + } + *line_extents = flow_line_extents(items, lines, gap); + let line = line_extents.first().map_or(0.0, |l| l.1); + if stretch_fill_across_hug_line(doc, items, line, (frame, cross_pads), st.horizontal, m) { + *line_extents = flow_line_extents(items, lines, gap); + } +} + /// Position one resolved flow line, resizing wrapped fill children across the line. fn place_flow_line(doc: &mut Document, items: &[Item], line: &[usize], al: &AutoLayout, m: &dyn Measure, geometry: FlowLineGeometry) { let FlowLineGeometry { horizontal, wraps, main_start, inner_main, cross_pos, line_cross, used, gap } = geometry; @@ -523,15 +644,16 @@ pub fn layout_frame(doc: &mut Document, frame: NodeId, m: &dyn Measure) { let hug_cross = if horizontal { hug_h } else { hug_w }; let baseline = horizontal && al.cross_align == CrossAlign::Baseline; - let mut items = flow_items(doc, &kids, horizontal, hug_main, hug_cross); - let gap = finite_or_zero(al.gap); let auto_gap = al.main_align.is_auto_gap(); let wraps = al.wrap && !hug_main; + let mut items = flow_items(doc, &kids, horizontal, hug_main, hug_cross && wraps); - // Fill across a single line: the size is the frame's inner cross size, known up front. Resize - // those children first, so text that wraps (or a frame hugging it) reports its final main size. - if !wraps { + // Fill across a single line of a frame that doesn't hug that axis: the size is the frame's + // inner cross size, known up front. Resize those children first, so text that wraps (or a + // frame hugging it) reports its final main size. A hugging frame's line is only known once + // the other children are measured (`stretch_fill_across_hug_line`). + if !wraps && !hug_cross { for it in items.iter_mut().filter(|it| it.fill_cross && !it.fill_main) { let cross = clamp_size(inner_cross_fixed, it.min_cross, it.max_cross); let (w, h) = if horizontal { (it.main, cross) } else { (cross, it.main) }; @@ -549,11 +671,8 @@ pub fn layout_frame(doc: &mut Document, frame: NodeId, m: &dyn Measure) { // Fill children take their main size now, so their cross size (wrapped text, a hugging frame) // is final before the lines and the frame are sized. for it in items.iter_mut().filter(|it| it.fill_main) { - let cross = if it.fill_cross && !wraps { clamp_size(inner_cross_fixed, it.min_cross, it.max_cross) } else { it.cross }; - let (w, h) = if horizontal { (it.main, cross) } else { (cross, it.main) }; - resize_child(doc, it.id, w, h, m); - let (w, h) = outer_size(doc, it.id); - it.cross = if horizontal { h } else { w }; + let cross = if it.fill_cross && !wraps && !hug_cross { clamp_size(inner_cross_fixed, it.min_cross, it.max_cross) } else { it.cross }; + resize_fill_main_item(doc, it, cross, horizontal, m); } if baseline { // A layer without a text baseline (an icon, a shape, a frame holding no text) sits on the @@ -566,6 +685,14 @@ pub fn layout_frame(doc: &mut Document, frame: NodeId, m: &dyn Measure) { // Line extents: (main used, cross size). let mut line_extents = flow_line_extents(&mut items, &lines, gap); + // A hugging frame's single line: children filling the cross axis take its size now (the + // largest child that doesn't fill, a fill child's min counted, the frame's own min/max + // applied). A text that reflows at its new width changes the main sizes, so measure again. + let cross_pads = if horizontal { pt + pb } else { pl + pr }; + if hug_cross && !wraps { + let stretch = HugStretch { frame: (&fcl, cross_pads), horizontal, flow: (inner_main_fixed, gap, auto_gap) }; + stretch_hug_line(doc, &mut items, &lines, &mut line_extents, &stretch, m); + } // Container size (on a hugging axis fill children can't fill: they count with their own size). let content_main = line_extents.iter().map(|l| l.0).fold(0.0, f64::max); @@ -581,7 +708,7 @@ pub fn layout_frame(doc: &mut Document, frame: NodeId, m: &dyn Measure) { } } if hug_cross { - let v = content_cross + if horizontal { pt + pb } else { pl + pr }; + let v = content_cross + cross_pads; if horizontal { nh = v; } else { diff --git a/crates/layout/src/nested_tests.rs b/crates/layout/src/nested_tests.rs index 2a51e282e..5eea12e88 100644 --- a/crates/layout/src/nested_tests.rs +++ b/crates/layout/src/nested_tests.rs @@ -48,7 +48,7 @@ fn fill_text(d: &mut Document, parent: NodeId) -> NodeId { } #[test] -fn hug_parent_treats_fill_children_as_fixed() { +fn hug_parent_treats_fill_along_the_flow_as_fixed_and_takes_the_line_across() { let mut d = Document::new("t"); let p = page(&d); let f = al(&mut d, p, LayoutMode::Horizontal, (10.0, 10.0), (Sizing::Hug, Sizing::Hug)); @@ -56,17 +56,18 @@ fn hug_parent_treats_fill_children_as_fixed() { let b = rect(&mut d, f, 30.0, 40.0); sizing(&mut d, b, Sizing::Fill, Sizing::Fill); layout_frame(&mut d, f, &NoMeasure); - // Nothing to fill: the fill child keeps its size and the frame gets the content size. - assert_eq!(size(&d, f), (90.0, 40.0)); - assert_eq!(pos(&d, b), (60.0, 0.0, 30.0, 40.0)); - // Vertical, fill on the cross axis. + // Nothing to fill along the flow: the fill child keeps its width. Across it the frame keeps + // hugging and the child takes the line, the 20 of the sibling. + assert_eq!(size(&d, f), (90.0, 20.0)); + assert_eq!(pos(&d, b), (60.0, 0.0, 30.0, 20.0)); + // Vertical, fill on the cross axis: the child is as wide as the widest sibling. let g = al(&mut d, p, LayoutMode::Vertical, (10.0, 10.0), (Sizing::Hug, Sizing::Hug)); let c = rect(&mut d, g, 60.0, 20.0); sizing(&mut d, c, Sizing::Fill, Sizing::Fixed); rect(&mut d, g, 40.0, 30.0); layout_frame(&mut d, g, &NoMeasure); - assert_eq!(size(&d, g), (60.0, 60.0)); - assert_eq!(size(&d, c), (60.0, 20.0)); + assert_eq!(size(&d, g), (40.0, 60.0)); + assert_eq!(size(&d, c), (40.0, 20.0)); } #[test] @@ -377,6 +378,89 @@ fn fill_in_a_plain_frame_behaves_as_fixed() { assert_eq!((cl.sizing_h, cl.sizing_v), (Sizing::Fixed, Sizing::Fixed)); } +/// Fill is kept across a hugging flow (the child takes the line), turned Fixed along it, and +/// turned Fixed across a wrapping row that hugs that axis (Fill height is not offered there). +#[test] +fn coherent_sizing_keeps_fill_across_a_hugging_flow() { + let mut d = Document::new("t"); + let p = page(&d); + let cl = |d: &Document, id: NodeId| { + let c = &d.node(id).unwrap().child_layout; + (c.sizing_h, c.sizing_v) + }; + // Vertical stack hugging its width: the main axis is the height, so Fill width (across) stays. + let v = al(&mut d, p, LayoutMode::Vertical, (100.0, 100.0), (Sizing::Hug, Sizing::Fixed)); + let a = rect(&mut d, v, 10.0, 10.0); + sizing(&mut d, a, Sizing::Fill, Sizing::Fill); + assert!(!coherent_sizing(&mut d, v)); + assert_eq!(cl(&d, a), (Sizing::Fill, Sizing::Fill)); + // Both axes hugged: along the flow (height) Fill is fixed, across it (width) it stays. + sizing(&mut d, v, Sizing::Hug, Sizing::Hug); + assert!(coherent_sizing(&mut d, v)); + assert_eq!(cl(&d, a), (Sizing::Fill, Sizing::Fixed)); + // Horizontal row hugging both: the width (main) is fixed, the height (across) stays Fill. + let h = al(&mut d, p, LayoutMode::Horizontal, (100.0, 100.0), (Sizing::Hug, Sizing::Hug)); + let b = rect(&mut d, h, 10.0, 10.0); + sizing(&mut d, b, Sizing::Fill, Sizing::Fill); + assert!(coherent_sizing(&mut d, h)); + assert_eq!(cl(&d, b), (Sizing::Fixed, Sizing::Fill)); + // A wrapping row hugging its height: Fill height is not offered, so it is fixed. + let w = al(&mut d, p, LayoutMode::Horizontal, (120.0, 100.0), (Sizing::Fixed, Sizing::Hug)); + layout_mut(&mut d, w).wrap = true; + let c = rect(&mut d, w, 10.0, 10.0); + sizing(&mut d, c, Sizing::Fixed, Sizing::Fill); + assert!(coherent_sizing(&mut d, w)); + assert_eq!(cl(&d, c), (Sizing::Fixed, Sizing::Fixed)); + // The same wrapping row with a fixed height keeps Fill height. + sizing(&mut d, w, Sizing::Fixed, Sizing::Fixed); + sizing(&mut d, c, Sizing::Fixed, Sizing::Fill); + assert!(!coherent_sizing(&mut d, w)); + assert_eq!(cl(&d, c), (Sizing::Fixed, Sizing::Fill)); + // A grid keeps the old rule on both axes. + let g = al(&mut d, p, LayoutMode::Grid, (100.0, 100.0), (Sizing::Hug, Sizing::Hug)); + let e = rect(&mut d, g, 10.0, 10.0); + sizing(&mut d, e, Sizing::Fill, Sizing::Fill); + assert!(coherent_sizing(&mut d, g)); + assert_eq!(cl(&d, e), (Sizing::Fixed, Sizing::Fixed)); + // No flow parent: Fixed, as before. + let r = rect(&mut d, p, 10.0, 10.0); + sizing(&mut d, r, Sizing::Fill, Sizing::Fill); + assert!(coherent_sizing(&mut d, r)); + assert_eq!(cl(&d, r), (Sizing::Fixed, Sizing::Fixed)); +} + +/// Fill across the flow of a hugging frame, with nesting: a hugging frame child fills the line, +/// a nested layout is laid out at the new size, and a text that fills the width of a hugging +/// stack reflows to its new height before the stack hugs. +#[test] +fn fill_across_a_hugging_line_lays_out_nested_children_and_reflowing_text() { + let mut d = Document::new("t"); + let p = page(&d); + // Row hugging both: a nested frame filling the height takes the 40 px of its tall sibling and + // its own children keep their places (they are laid out again at the new size). + let row = al(&mut d, p, LayoutMode::Horizontal, (10.0, 10.0), (Sizing::Hug, Sizing::Hug)); + layout_mut(&mut d, row).gap = 0.0; + let inner = al(&mut d, row, LayoutMode::Horizontal, (30.0, 20.0), (Sizing::Fixed, Sizing::Fill)); + layout_mut(&mut d, inner).cross_align = CrossAlign::Max; + let dot = rect(&mut d, inner, 10.0, 10.0); + rect(&mut d, row, 50.0, 40.0); + layout_frame(&mut d, row, &NoMeasure); + assert_eq!(size(&d, row), (80.0, 40.0)); + assert_eq!(size(&d, inner), (30.0, 40.0)); + assert_eq!(pos(&d, dot), (0.0, 30.0, 10.0, 10.0), "laid out again at 40 high, bottom aligned"); + // Vertical stack hugging both: a text filling the width beside a 60 wide rectangle wraps to + // the line (60), and the stack hugs the height of the wrapped text. + let col = al(&mut d, p, LayoutMode::Vertical, (10.0, 10.0), (Sizing::Hug, Sizing::Hug)); + layout_mut(&mut d, col).gap = 0.0; + let t = fill_text(&mut d, col); + rect(&mut d, col, 60.0, 30.0); + // 150 wide natural, 20 high lines: at 60 wide it needs 3 lines. + let m = FakeMeasure([(t, (150.0, 20.0, 15.0))].into_iter().collect()); + layout_frame(&mut d, col, &m); + assert_eq!(size(&d, t), (60.0, 60.0)); + assert_eq!(size(&d, col), (60.0, 90.0)); +} + #[test] fn coherent_sizing_rules() { let mut d = Document::new("t"); diff --git a/crates/ui-egui/src/panels/layout_panel.rs b/crates/ui-egui/src/panels/layout_panel.rs index 2629e97f4..e77d5a1f1 100644 --- a/crates/ui-egui/src/panels/layout_panel.rs +++ b/crates/ui-egui/src/panels/layout_panel.rs @@ -219,7 +219,10 @@ fn dimensions(app: &mut FigApp, ui: &mut Ui, doc: &Document, sel: &[NodeId], has if has_al || is_text { opts.push((tr("Hug contents"), "hug")); } - if can_fill { + // Across a wrapping row that hugs this axis Fill is not offered, as Hug is not + // offered on a layer that can't hug. + let wrapped = sel.iter().any(|i| parent_of(doc, *i).is_some_and(|p| figcraft_layout::wrapping_row_hugs_across(p, horizontal))); + if can_fill && !wrapped { opts.push((tr("Fill container"), "fill")); } for (l, v) in opts { diff --git a/docs/auto-layout-parity.md b/docs/auto-layout-parity.md index 691936b65..a18894efc 100644 --- a/docs/auto-layout-parity.md +++ b/docs/auto-layout-parity.md @@ -1,6 +1,6 @@ # Auto layout and constraints parity -> **Last reviewed:** 2026-10-11 · **Last updated:** 2026-11-13 · **Change:** patch (padding grip fills and outlines follow theme tokens; padding grips preserve canvas hover and right-click menus; padding grips stay reachable on tiny frames and at reduced zoom; grid Fill (`fr`) tracks share the space of a fixed-size axis by their fractions and let a fixed-size child overflow, as measured in Figma (300 x 200, two rows, 100 x 150 and 100 x 20 children: rows 100 / 100, second child at y 100; with a row gap of 10, rows 95 / 95 and y 105; on Hug the rows fit their content, 150 / 20) -- this replaces the 2026-10-11 rule from the documentation; a child dragged within its own auto layout row or column passes a sibling when its leading edge reaches the sibling's middle, as measured in Figma's web app, wherever it is grabbed; 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-13 · **Change:** patch (Fill on a child turns its hugging parent Fixed along the flow only; across the flow the parent keeps hugging and the child takes the line's cross size, as measured in Figma (#2091, #2034); padding grip fills and outlines follow theme tokens; padding grips preserve canvas hover and right-click menus; padding grips stay reachable on tiny frames and at reduced zoom; grid Fill (`fr`) tracks share the space of a fixed-size axis by their fractions and let a fixed-size child overflow, as measured in Figma (300 x 200, two rows, 100 x 150 and 100 x 20 children: rows 100 / 100, second child at y 100; with a row gap of 10, rows 95 / 95 and y 105; on Hug the rows fit their content, 150 / 20) -- this replaces the 2026-10-11 rule from the documentation; a child dragged within its own auto layout row or column passes a sibling when its leading edge reaches the sibling's middle, as measured in Figma's web app, wherever it is grabbed; 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%, @@ -53,7 +53,7 @@ Status: **pass** (a case in the suite holds), **fixed** (the suite found a diver | Fixed: the frame keeps its size whatever its children need | pass | `sizing_rules` | | Fill: children share the space left after padding, gaps and fixed siblings; across the flow they stretch | pass | `sizing_rules` | | Fill children share by their content area (border-box): a child with more padding or a thicker included inside stroke takes a little more, so the content areas come out the same | **fixed** | "Figma distributes space amongst fill container children by the children's content area instead of by their size, matching the CSS border-box model. A layer with a thicker stroke will take up slightly more of the available width or height, so that its inner content area matches its sibling's" (Use auto layout with CSS Flexbox in mind); the split went by outer size before. Min and max still clamp the outer size; a child's own insets are its padding and its included inside stroke (`nested_tests::fill_children_share_by_content_area`; #1824) | -| Fill on a child turns its hugging parent Fixed on that axis | pass | `al_behaviour_tests::fill_on_a_child_turns_the_hugging_parent_fixed` | +| Fill on a child turns its hugging parent Fixed along the flow only; across the flow the parent keeps hugging and the child takes the line's cross size (the largest non-Fill sibling, a Fill child's min counted, padding outside); the parent turns Fixed when no non-Fill child is left (toast); Fill across a wrapping row that hugs that axis is not offered | **fixed** | Measured in Figma web (2026-11-08): A 4×20 Fill height beside B 50×40 in a hugging row: A 40, parent height 40 Hug, no notice; B 60: A 60, parent 60 Hug; min height 50 on A: A 50, parent 50 Hug, B 40; both Fill: parent Fixed 40 with the notice "Height set to Fixed for Frame 1"; along the flow (A's width Fill): parent Fixed, "Width set to Fixed for Frame 1"; in a wrapping row hugging its height Fill height is greyed out. FigCraft turned the parent Fixed on both axes, so a `.fig` STRETCH bar beside a two-line text kept its own height (#2091) and a Fill bar froze its row at the text's height of that moment (#2034). `al_behaviour_tests::fill_on_a_child_turns_the_hugging_parent_fixed`, `fill_across_a_hugging_parent_keeps_it_hugging_and_takes_the_line`, `fill_along_a_hugging_parent_notes_that_the_width_is_fixed`, `a_fill_childs_min_counts_toward_the_hugging_size`, `a_parent_set_back_to_hug_keeps_the_child_that_fills_across_it`, `fill_across_a_wrapping_row_that_hugs_that_axis_is_not_offered`; `behaviour_tests::fill_across_a_hugging_axis_rules`; `nested_tests::coherent_sizing_keeps_fill_across_a_hugging_flow`; `auto_layout_sizing_tests::stretch_children_take_the_row_height_after_a_layout_pass`. Unmeasured: a grid keeps the old rule on both axes; deleting or hiding the last non-Fill child changes no sizing (the children keep their own sizes and the parent hugs the largest) | | A child resized to the full available space becomes Fill container on that axis | **fixed** | "Child objects of an auto layout frame will also be set to Fill container if they are manually resized to the full available space of the parent frame": a width or height given by a resize, the W/H fields or a canvas handle that equals the frame's size less its padding sets Fill there: across the flow for any child, along the flow for a lone child (beside siblings what is left depends on the gaps, the alignment and overflow, so it is left alone); not in a hugging or wrapping frame or a grid. It stayed Fixed before (`al_behaviour_tests::a_child_resized_to_the_full_available_space_becomes_fill`) | | Hug only on auto layout frames (and text); Fill only in an auto layout flow, never on a top-level frame | pass | `al_behaviour_tests::hug_and_fill_only_where_they_apply` | | Double-click an edge of an auto layout frame's box: Hug contents on that axis; Alt+double-click an edge of a child's box: Fill container | **fixed** | "Tip: 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 the vertical or horizontal edge of an auto layout object's bounding box to set it to Fill container." A vertical edge sizes the width, a horizontal one the height; any other layer keeps the double-click's old meaning (#1838). `double_click_tests::a_double_click_on_an_auto_layout_edge_hugs_and_with_alt_fills` | @@ -97,7 +97,7 @@ Status: **pass** (a case in the suite holds), **fixed** (the suite found a diver | Grid auto layout: fixed / hug / `fr` tracks, cells, spans, gaps, cell alignment | done | `fr` as measured | | Gap, auto gap (between / evenly / around), padding (per side), alignment 3×3 | done | a Cmd/Ctrl-click on a padding field (the pair or a side) makes the value typed go to all four sides in one undo step (Guide to auto layout, Keyboard shortcut guide; `padding_individual_tests`) | | Text baseline alignment | done | | -| Hug / Fill / Fixed sizing with coherent rules (Fill turns a hugging parent Fixed) | done | `al_nesting_tests.rs`, `al_behaviour_tests.rs` | +| Hug / Fill / Fixed sizing with coherent rules (Fill along a hugging axis turns the parent Fixed; across it the child takes the line) | done | `al_nesting_tests.rs`, `al_behaviour_tests.rs` | | Min/max width and height, redistribution | done | hugging text wraps at its max | | Nested hug/fill settling in one pass (three levels, wrapping fill text, grid rows) | done | | | Absolute position (ignore auto layout) with constraints | done | | @@ -118,6 +118,7 @@ Status: **pass** (a case in the suite holds), **fixed** (the suite found a diver |---|---|---| | 2026-11-13 | patch | M2, #2152: Padding grip fills and outlines come from dedicated theme tokens, preserving linked-state emphasis and border widths. A rendering regression checks custom light and dark palettes. | | 2026-11-13 | patch | M2, #2152: Padding grips preserve canvas hover and secondary-click context menus while retaining their resize cursor. Only primary presses and active handle drags capture input. Regressions reproduce both stale layer hover and blocked right-click menus. | +| 2026-11-08 | patch | M2, #2091, #2034: Fill on a child of a hugging auto layout frame turns the frame Fixed only along the flow, as measured in Figma; across the flow the frame keeps hugging and the child takes the line's cross size (the largest child that doesn't fill, a Fill child's min counted, padding outside, the frame's own min/max applied), re-laid out at that size, and a text filling the width of a hugging stack reflows before the stack hugs it. The frame turns Fixed (notice "Height set to Fixed for ", also "Width ..." along the flow) only when no non-Fill child is left; in a wrapping row that hugs the axis Fill is refused (`node.set`), not offered (Layout panel) and read as Fixed by `coherent_sizing`. A `.fig` STRETCH bar beside a two-line text now takes the text's height. | | 2026-11-11 | patch | M2.1: grid Fill (`fr`) tracks share the space of a fixed-size axis by their fractions and let a fixed-size child overflow, as measured in Figma (300 x 200, two rows, 100 x 150 and 100 x 20 children: rows 100 / 100, second child at y 100; with a row gap of 10, rows 95 / 95 and y 105; on Hug the rows fit their content, 150 / 20) (this replaces the 2026-10-11 rule from the documentation). Layout behaviour suite: three cases flipped, three added | | 2026-11-10 | patch | M2: Opposite padding grips separate to at least 20 screen pixels on tiny frames or at reduced zoom. Overlapping targets select the nearest visible grip, shared by hover, highlighting and drag. Regression tests click every painted grip, drag and undo on thin, narrow and tiny frames, including an inside stroke and 25% zoom. | | 2026-11-09 | patch | M2: Canvas padding bands have a central grip on each side; only pressing and dragging that grip edits padding. Hover still highlights the band and shows its value beside the grip. Each grip keeps its vertical or horizontal resize cursor on hover. Alt links the opposite side, Alt+Shift links all four, and affected bands and grips highlight as modifiers change, before and during dragging. Headless tests cover cursors, all sides, modifier previews, dragging and one-step undo. | diff --git a/docs/components-parity.md b/docs/components-parity.md index 61598ab9a..ab7b4547a 100644 --- a/docs/components-parity.md +++ b/docs/components-parity.md @@ -15,7 +15,7 @@ accounts). | 2026-11-11 | minor | M3, #2022: an instance lists only the properties its variant's layers use (its variant properties, slots, and the boolean, text and instance swap properties a layer of its current variant reads), as measured in Figma's web app: an instance of variant A lists `State` and `A label`, never `B label` or a property no layer reads. The set and its variants still list every definition, so unused ones can be deleted there. A long property name in the panel is cut to one line with an ellipsis, the full name on hover, instead of wrapping over the rows around it. Tests: `prop_order_tests::an_instance_lists_only_the_properties_its_variant_uses`, `component_props_reorder_tests::a_long_property_name_stays_on_one_line`, `prop_value_tests::a_set_keeps_each_named_text_definition_and_layers_read_their_own`. Grade unchanged. | | Create component, instances, detach, reset, go to main, restore main, push changes | done | push from a nested layer goes to the outer main; with two or more layers selected the Design panel header's component button opens a menu with Create component, Create multiple components (each layer its own component in place, one undo step) and Create component set (each layer a component, wrapped in place in a set 20 px around: variants `Property 1=` left to right, `prop=value` names kept, layers that all share a name give a set of that name with `Property 1=Default` variants; measured in Figma), one layer keeps the plain click (#2088) | | Per-layer overrides with reset; kept across main edits, nested swaps, copy/paste | done | main edits match a full rebuild exactly at 2,000 instances | -| What an instance overrides: fills, strokes, effects, visibility, layer names, text content and every text property (resizing included), auto layout padding, gap and alignment, layout grids, export settings, prototype interactions, nested swaps and property values; the size and resizing (hug, fill, fixed, min and max) of layers inside it | done | each kept when the main changes that property, reset per group; opacity and corner radius too (documentation silent); size and resizing are kept through relayout, undo, save, `.fig` and REST import and detach, and stay with the instance on push | +| What an instance overrides: fills, strokes, effects, visibility, layer names, text content and every text property (resizing included), auto layout padding, gap and alignment, layout grids, export settings, prototype interactions, nested swaps and property values; the size and resizing (hug, fill, fixed, min and max) of layers inside it; an instance's own resizing (hug or fixed) follows its main's unless its size is overridden, measured: a plain instance turns Fixed when its main does (a child set to Fill along the hugging axis) and back to Hug with it, one whose width was typed keeps it, and Fill in its own auto layout parent is its own | done | each kept when the main changes that property, reset per group; opacity and corner radius too (documentation silent); size and resizing are kept through relayout, undo, save, `.fig` and REST import and detach, and stay with the instance on push | | What it doesn't: position, rotation, constraints and absolute or grid placement of layers inside it, its auto layout direction and other settings, its structure | done | refused with a message, the fields greyed out (Delete on a layer inside an instance hides it instead of removing it, as the help center says it does); the instance itself resizes and its layers follow the main's constraints | | Component sets / variants, add variant, switch | done | Combine as variants is in the Object menu, and the canvas and layers context menu and the Design panel offer it when two or more main components are selected; Add variant on a main component not in a set yet makes it a set of itself and the new variant, one undo step (#903); components that are variants already aren't combined again (it used to put a set inside a set) | | A main's copy within its file is an instance of it: Duplicate, Alt-drag, Copy then Paste | done | a variant duplicated in its set stays a new variant and a whole set copies as a new set; only the copied roots become instances (a main inside a copied frame is copied as a main); Cut then Paste and pastes into other files keep the component (#892) | @@ -81,6 +81,7 @@ updates with overrides kept: `library_tests.rs`, `components_scale_tests.rs`. | Date | Change | Summary | |---|---|---| | 2026-11-14 | patch | M3, #2354: the Local variables window resizes from its edges and corners, width and height (minimum 600 x 240), and keeps its size and place while the app runs. | +| 2026-11-07 | patch | M3, #2090: an instance's own resizing follows its main's unless its size is overridden. Measured in Figma: a plain instance turns Fixed when its main's width does (a child set to Fill along it) and back to Hug with it; an instance whose width was typed keeps it; Fill in its own auto layout parent is kept. Tests: `components_behaviour_tests::a_plain_instances_resizing_follows_the_mains_root_both_ways` and the instance resizing tests beside it. | | 2026-11-13 | patch | Rows that recent merges had duplicated or garbled are merged back into one row each (no behaviour change): Create component, instances, detach, reset, go to main, restore main, push changes. | | 2026-11-14 | patch | M3, #2353: renaming a group in the Local variables window to a path with `/` nests it, as in Figma: `Orange` renamed to `Palette/Orange` moves its variables to `Palette/Orange/100`… and the sidebar shows Orange indented under a new Palette group, where the slash used to become a hyphen (`Palette-Orange`). The typed path replaces the group's last part (a nested group stays in its parent), each part is trimmed and empty parts are dropped; a rename onto a variable name that stays is refused with nothing changed, and it is one undo step. Tests: `variables_select_tests::renaming_a_group_with_a_slash_nests_it_in_a_new_parent_group_in_one_undo_step` and the group rename tests beside it, `variables_panel::tests`. Grade unchanged. | | 2026-11-07 | minor | M3, #2084: a group's context menu in the Local variables window has Duplicate group (after Rename group, before Delete group). It adds a group named after the original plus " 2" (the next free number when taken: " 3"), whose variables are copies of the originals with the same leaf names, values in every mode, description, scopes, hidden-from-publishing and code syntax, each sent as `variable.duplicate` plus a rename in one `command.batch` labelled Duplicate group, so one undo step. Measured in the incumbent with one mode; an alias to a variable of the same group keeps pointing at the original. Ungroup is not built. Tests: `variables_select_tests` (headless UI). Grade unchanged | diff --git a/docs/mcp.md b/docs/mcp.md index b94c5a56e..0a557c6b2 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -205,8 +205,12 @@ Or in a project's `.mcp.json`: before the keys that tune it, so `{"layout": {"mode": "vertical"}, "gap": 8}` keeps the gap; auto layout keys beside a `layout` of `null` or `"none"` are refused. More auto layout props: - `sizingH` / `sizingV`: `fixed`, `hug` (auto layout frames and text) or `fill` (children in an - auto layout flow). A child can't fill an axis its parent hugs: setting `fill` turns the parent - `fixed` on that axis, and a parent set to `hug` turns the children that filled it `fixed`. A + auto layout flow). A child can't fill the axis its parent hugs along the flow: setting `fill` + turns the parent `fixed` on that axis (the session notice reads "Width set to Fixed for "), + and a parent set to `hug` turns the children that filled it `fixed`. Across the flow the parent keeps + hugging and the child takes the line's cross size (the largest sibling that doesn't fill, its min + counted, padding outside); the parent turns `fixed` ("Height set to Fixed for ") only when no + such sibling is left, and `fill` across a wrapping row that hugs that axis is refused. A layer moved out of auto layout (or whose frame loses it) keeps its size as `fixed`. Fill children share the space like CSS flexbox, within their min/max. - `minWidth` / `maxWidth` / `minHeight` / `maxHeight` (px, `null` removes) bound Hug, Fill and