From da1cfe3fdd6088853a5c049bd07fdb38b96f3220 Mon Sep 17 00:00:00 2001 From: bflatastic Date: Tue, 1 Dec 2026 11:29:19 +0700 Subject: [PATCH 1/2] M12: a mind map grows right, left or on both sides of its first node (#2642, part) The bar over a selected mind map node now ends in a Layout menu: Right, Left or Both sides (`board.mindMapLayout {id?, layout: right|left|both}`). The map's branches change side and it lays itself out again: every node keeps its parent, deeper nodes follow their side, and on both sides the first half of the first node's children go right. A new child of the first node, or a node dropped on it, goes on the map's side (on a two-sided map, the side with fewer children). One undo step. --- .../engine/src/board_mindmap_sides_tests.rs | 74 ++++++++++ crates/engine/src/board_mindmap_tests.rs | 4 +- crates/engine/src/boards/board.rs | 9 +- crates/engine/src/boards/board/mindmap.rs | 138 +++++++++++++++++- crates/engine/src/lib.rs | 2 + crates/ui-egui/locales/ar.toml | 1 + crates/ui-egui/locales/bn.toml | 1 + crates/ui-egui/locales/bs.toml | 1 + crates/ui-egui/locales/cs.toml | 1 + crates/ui-egui/locales/de.toml | 1 + crates/ui-egui/locales/en.toml | 1 + crates/ui-egui/locales/es.toml | 2 + crates/ui-egui/locales/fi.toml | 2 + crates/ui-egui/locales/fr.toml | 1 + crates/ui-egui/locales/he.toml | 2 + crates/ui-egui/locales/id.toml | 1 + crates/ui-egui/locales/it.toml | 2 + crates/ui-egui/locales/ja.toml | 1 + crates/ui-egui/locales/ka.toml | 1 + crates/ui-egui/locales/ko.toml | 1 + crates/ui-egui/locales/nl.toml | 1 + crates/ui-egui/locales/pl.toml | 1 + crates/ui-egui/locales/pt-BR.toml | 1 + crates/ui-egui/locales/ru.toml | 1 + crates/ui-egui/locales/sv.toml | 2 + crates/ui-egui/locales/ta.toml | 1 + crates/ui-egui/locales/th.toml | 1 + crates/ui-egui/locales/tr.toml | 1 + crates/ui-egui/locales/vi.toml | 1 + crates/ui-egui/locales/zh-Hans.toml | 1 + crates/ui-egui/locales/zh-Hant.toml | 1 + .../ui-egui/src/board_mind_layout_ui_tests.rs | 29 ++++ crates/ui-egui/src/board_ui_tests.rs | 10 +- crates/ui-egui/src/canvas/board_bar.rs | 65 ++++++--- crates/ui-egui/src/i18n/tests.rs | 1 + crates/ui-egui/src/lib.rs | 2 + docs/boards-parity.md | 5 +- docs/mcp.md | 9 +- 38 files changed, 345 insertions(+), 34 deletions(-) create mode 100644 crates/engine/src/board_mindmap_sides_tests.rs create mode 100644 crates/ui-egui/src/board_mind_layout_ui_tests.rs diff --git a/crates/engine/src/board_mindmap_sides_tests.rs b/crates/engine/src/board_mindmap_sides_tests.rs new file mode 100644 index 000000000..9749a88f1 --- /dev/null +++ b/crates/engine/src/board_mindmap_sides_tests.rs @@ -0,0 +1,74 @@ +//! Mind maps that grow left of their first node, or on both sides (`board.mindMapLayout`, #2642): +//! the branches change side, every node keeps its parent, new children follow the map's sides, +//! and one undo puts the map back. + +use figcraft_doc::NodeId; +use serde_json::json; + +use crate::Session; +use crate::board::{MindSides, mind_sides}; +use crate::board_mindmap_tests::{bx, map}; +use crate::board_tests::{board, id}; + +fn layout(s: &mut Session, node: NodeId, layout: &str) -> serde_json::Value { + s.execute("board.mindMapLayout", &json!({"id": node, "layout": layout})).unwrap() +} + +fn add_child(s: &mut Session, node: NodeId) -> NodeId { + id(&s.execute("board.mindMapAdd", &json!({"id": node})).unwrap(), "id") +} + +fn left_of(s: &Session, a: NodeId, b: NodeId) -> bool { + bx(s, a).x1 < bx(s, b).x0 +} + +#[test] +fn a_map_turned_left_grows_left_of_its_first_node_and_undo_turns_it_back() { + let mut s = board(); + let (root, kids, _) = map(&mut s); + let grandchild = add_child(&mut s, kids[0]); + let root_box = bx(&s, root); + let depth = s.undo_depth().0; + // Asked from any node of the map: it is the whole map that turns. + let out = layout(&mut s, grandchild, "left"); + assert_eq!((id(&out, "id"), out["layout"].as_str()), (root, Some("left"))); + assert_eq!(s.undo_depth().0, depth + 1); + assert!(kids.iter().all(|k| left_of(&s, *k, root))); + assert!(left_of(&s, grandchild, kids[0]), "deeper nodes follow their side"); + assert_eq!(bx(&s, root), root_box, "the first node stays"); + assert_eq!(mind_sides(s.doc().unwrap(), kids[1]), Some(MindSides::Left)); + // A new child of the first node goes on the map's side. + let new = add_child(&mut s, root); + assert!(left_of(&s, new, root)); + s.execute("edit.undo", &json!({})).unwrap(); + s.execute("edit.undo", &json!({})).unwrap(); + assert!(kids.iter().all(|k| left_of(&s, root, *k))); + assert_eq!(mind_sides(s.doc().unwrap(), root), Some(MindSides::Right)); +} + +#[test] +fn a_map_on_both_sides_splits_its_first_nodes_children_and_new_ones_fill_the_shorter_side() { + let mut s = board(); + let (root, kids, _) = map(&mut s); + layout(&mut s, root, "both"); + assert_eq!(mind_sides(s.doc().unwrap(), root), Some(MindSides::Both)); + assert!(left_of(&s, root, kids[0]) && left_of(&s, root, kids[1]), "the first half on the right"); + assert!(left_of(&s, kids[2], root), "the rest on the left"); + let new = add_child(&mut s, root); + assert!(left_of(&s, new, root), "two on the right, one on the left: the left"); + let next = add_child(&mut s, root); + assert!(left_of(&s, root, next), "a tie: the right"); + // Back to the right: every node keeps its parent. + layout(&mut s, root, "right"); + assert!([kids[0], kids[1], kids[2], new, next].iter().all(|k| left_of(&s, root, *k))); +} + +#[test] +fn a_layout_needs_a_mind_map_node_and_a_known_side() { + let mut s = board(); + let (root, _, lines) = map(&mut s); + assert!(s.execute("board.mindMapLayout", &json!({"id": root, "layout": "down"})).is_err()); + assert!(s.execute("board.mindMapLayout", &json!({"id": root})).is_err()); + assert!(s.execute("board.mindMapLayout", &json!({"id": lines[0], "layout": "left"})).is_err()); + assert_eq!(mind_sides(s.doc().unwrap(), lines[0]), None); +} diff --git a/crates/engine/src/board_mindmap_tests.rs b/crates/engine/src/board_mindmap_tests.rs index 0bb67a044..1cd66eb54 100644 --- a/crates/engine/src/board_mindmap_tests.rs +++ b/crates/engine/src/board_mindmap_tests.rs @@ -12,7 +12,7 @@ use crate::board_tests::{board, connector, drawn, id, near, node}; use crate::collab_live_tests::Room; use crate::tools::{PointerEvent, PointerKind, ToolId}; -fn bx(s: &Session, id: NodeId) -> Rect { +pub(crate) fn bx(s: &Session, id: NodeId) -> Rect { s.doc().unwrap().world_bounds(id).unwrap() } @@ -21,7 +21,7 @@ fn same(a: f64, b: f64) -> bool { } /// `board.mindMap` at (100, 200): the first node, its three children and their branches. -fn map(s: &mut Session) -> (NodeId, [NodeId; 3], [NodeId; 3]) { +pub(crate) fn map(s: &mut Session) -> (NodeId, [NodeId; 3], [NodeId; 3]) { let out = s.execute("board.mindMap", &json!({"x": 100, "y": 200})).unwrap(); let kids: Vec = out["children"].as_array().unwrap().clone(); let (c, k): (Vec, Vec) = kids.iter().map(|v| (id(v, "id"), id(v, "connector"))).unzip(); diff --git a/crates/engine/src/boards/board.rs b/crates/engine/src/boards/board.rs index e5c67b537..0a6cd4dfa 100644 --- a/crates/engine/src/boards/board.rs +++ b/crates/engine/src/boards/board.rs @@ -77,7 +77,7 @@ pub use items::{CONNECTED_GAP, connected_place}; pub use items::{STICKY_TEXT_SIZE, edit_text, owner_of_text, text_of}; use items::{add_connected, ink_cmd, next_sticky, shape_cmd, stamp_cmd, sticky_cmd}; pub(crate) use mindmap::settle_mind_maps; -pub use mindmap::{mind_node_target, mind_sibling}; +pub use mindmap::{MindSides, mind_node_target, mind_sibling, mind_sides}; pub(crate) use reshape::path_handle_at; pub use reshape::selected_connector_handles; @@ -264,6 +264,13 @@ pub fn specs() -> Vec { true, mindmap::mind_map_add ), + spec!( + "board.mindMapLayout", + "Mind map layout", + "{id? (a mind map node; default the selected or edited one), layout: right|left|both} → {id (the map's first node), layout} the sides of the first node its map grows on: on both, the first half of its children (right ones then left ones, top to bottom) go on the right and the rest on the left; every node keeps its parent and the map lays itself out again", + true, + mindmap::mind_map_layout + ), spec!( "board.codeBlock", "Code block", diff --git a/crates/engine/src/boards/board/mindmap.rs b/crates/engine/src/boards/board/mindmap.rs index 20d572981..bec798f2e 100644 --- a/crates/engine/src/boards/board/mindmap.rs +++ b/crates/engine/src/boards/board/mindmap.rs @@ -74,9 +74,15 @@ fn make_node(doc: &mut Document, parent: NodeId, at: (f64, f64), text: &str, roo Ok((frame, label)) } +/// The sides a branch leaves its parent from and arrives at its child on (left of the parent when +/// `left`). +fn sides(left: bool) -> (Side, Side) { + if left { (Side::Left, Side::Right) } else { (Side::Right, Side::Left) } +} + /// The branch from `parent` to `child` (on its left side when `left`), on `page`. fn branch(doc: &mut Document, page: NodeId, parent: NodeId, child: NodeId, left: bool) -> Result { - let (out, back) = if left { (Side::Left, Side::Right) } else { (Side::Right, Side::Left) }; + let (out, back) = sides(left); let c = Connector { from: End::Node { node: parent, side: out, at: None }, to: End::Node { node: child, side: back, at: None }, @@ -144,6 +150,131 @@ fn map_side(bs: &[Branch], node: NodeId) -> bool { left } +/// The side a new child of `node` goes on: its own side, or for a first node the side its map +/// grows on (with branches on both sides, the side with fewer of them; the right on a tie). +fn child_side(bs: &[Branch], node: NodeId) -> bool { + if arriving(bs, node).is_some() { + return map_side(bs, node); + } + let count = |left: bool| bs.iter().filter(|b| b.parent == node && b.left == left).count(); + let (right, left) = (count(false), count(true)); + left > 0 && (right == 0 || left < right) +} + +/// Which sides of its first node a mind map grows on (`board.mindMapLayout`). +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub enum MindSides { + Right, + Left, + Both, +} + +impl MindSides { + pub const ALL: [MindSides; 3] = [MindSides::Right, MindSides::Left, MindSides::Both]; + + /// Its name in commands. + pub fn id(self) -> &'static str { + match self { + MindSides::Right => "right", + MindSides::Left => "left", + MindSides::Both => "both", + } + } + + /// Its name in the UI (English; the UI translates it). + pub fn label(self) -> &'static str { + match self { + MindSides::Right => "Right", + MindSides::Left => "Left", + MindSides::Both => "Both sides", + } + } + + fn parse(s: &str) -> Option { + MindSides::ALL.into_iter().find(|m| m.id() == s) + } +} + +/// The first node of the map `node` is in (`node` itself when no branch arrives at it). A loop of +/// branches ends the walk after as many steps as there are branches. +fn map_root(bs: &[Branch], node: NodeId) -> NodeId { + let mut at = node; + for _ in 0..=bs.len() { + let Some(b) = arriving(bs, at) else { break }; + at = b.parent; + } + at +} + +/// The sides the map of mind map node `node` grows on (one without children: the right). +pub fn mind_sides(doc: &Document, node: NodeId) -> Option { + if !is_board(doc) || doc.node(node)?.board != Some(BoardItem::MindNode) { + return None; + } + let bs = branches(doc); + let root = map_root(&bs, node); + let on = |left: bool| !map_children(doc, &bs, root, left).is_empty(); + Some(match (on(false), on(true)) { + (_, false) => MindSides::Right, + (false, true) => MindSides::Left, + (true, true) => MindSides::Both, + }) +} + +/// `board.mindMapLayout`: the first node's children, right ones then left ones, each top to +/// bottom, go on the sides asked for (on both, the first half on the right), and every branch +/// under each follows its side; the normalize pass lays the map out again. +pub(super) fn mind_map_layout(s: &mut Session, p: &Value) -> Result { + let cmd = "board.mindMapLayout"; + require(s, cmd)?; + let layout = string(p, "layout").ok_or_else(|| bad(cmd, "`layout` is right, left or both"))?; + let sides_asked = MindSides::parse(&layout).ok_or_else(|| bad(cmd, format!("`layout` is right, left or both, not `{layout}`")))?; + let doc = s.doc()?; + let from = id(p, "id").or_else(|| target(s)).ok_or_else(|| EngineError::Disabled(cmd.into(), "select a mind map node first".into()))?; + if doc.get(from)?.board != Some(BoardItem::MindNode) { + return Err(bad(cmd, "that isn't a mind map node")); + } + let bs = branches(doc); + let root = map_root(&bs, from); + let firsts: Vec = [false, true].into_iter().flat_map(|left| map_children(doc, &bs, root, left)).collect(); + let half = firsts.len().div_ceil(2); + let (_, kids) = children_of(&bs); + // Every branch under each of the first node's children, with the side it goes on. + let (mut lines, mut seen) = (Vec::new(), BTreeSet::from([root])); + for (i, first) in firsts.iter().enumerate() { + let left = match sides_asked { + MindSides::Right => false, + MindSides::Left => true, + MindSides::Both => i >= half, + }; + let Some(a) = arriving(&bs, *first) else { continue }; + lines.push((a.line, left)); + let mut todo = vec![*first]; + while let Some(n) = todo.pop() { + for k in kids.get(&n).into_iter().flatten().filter(|k| seen.insert(k.child)) { + lines.push((k.line, left)); + todo.push(k.child); + } + } + } + let doc = s.doc_mut()?; + for (line, left) in lines { + let (out, back) = sides(left); + if let Some(BoardItem::Connector(c)) = doc.node_mut(line).and_then(|n| n.board.as_mut()) { + set_side(&mut c.from, out); + set_side(&mut c.to, back); + } + } + Ok(json!({"id": root, "layout": sides_asked.id()})) +} + +/// `end`'s side, when it is on a layer. +fn set_side(end: &mut End, to: Side) { + if let End::Node { side, .. } = end { + *side = to; + } +} + /// The text `p` gives for `key`, a node's at most [`MIND_MAX_TEXT`] characters. fn text_param(p: &Value, key: &str) -> String { string(p, key).unwrap_or_default().chars().take(MIND_MAX_TEXT).collect() @@ -255,7 +386,7 @@ pub(super) fn mind_map_add(s: &mut Session, p: &Value) -> Result { // Its middle lands between this node and the next sibling, so the order puts it right after. (a.parent, a.left, Point::new(at.x0, at.y1 + MIND_GAP_Y / 2.0 - new_h / 2.0)) } else { - let left = map_side(&bs, from); + let left = child_side(&bs, from); let last = map_children(doc, &bs, from, left).last().and_then(|l| doc.world_bounds(*l)); let top = last.map_or(at.center().y - new_h / 2.0, |l| l.y1 + MIND_GAP_Y); (from, left, Point::new(if left { at.x0 - MIND_GAP_X - MIND_MIN_W } else { at.x1 + MIND_GAP_X }, top)) @@ -356,8 +487,7 @@ fn regraft(doc: &mut Document, before: &Document, touched: &BTreeSet) -> .filter(|t| *t != id && is_node(doc, *t) && doc.page_of(*t) == page && doc.world_bounds(*t).is_some_and(|r| r.contains(mid))) .find(|t| !hangs_under(&bs, *t, id)); let Some(onto) = onto.filter(|t| *t != a.parent) else { continue }; - let left = map_side(&bs, onto); - let (out, back) = if left { (Side::Left, Side::Right) } else { (Side::Right, Side::Left) }; + let (out, back) = sides(child_side(&bs, onto)); if let Some(BoardItem::Connector(c)) = doc.node_mut(a.line).and_then(|n| n.board.as_mut()) { c.from = End::Node { node: onto, side: out, at: None }; c.to = End::Node { node: id, side: back, at: None }; diff --git a/crates/engine/src/lib.rs b/crates/engine/src/lib.rs index 5dad7d170..1376f12c9 100644 --- a/crates/engine/src/lib.rs +++ b/crates/engine/src/lib.rs @@ -238,6 +238,8 @@ mod board_ink_lasso_tests; #[cfg(test)] mod board_link_tests; #[cfg(test)] +mod board_mindmap_sides_tests; +#[cfg(test)] mod board_mindmap_tests; #[cfg(test)] mod board_reshape_tests; diff --git a/crates/ui-egui/locales/ar.toml b/crates/ui-egui/locales/ar.toml index 23485e55f..bc5871ab2 100644 --- a/crates/ui-egui/locales/ar.toml +++ b/crates/ui-egui/locales/ar.toml @@ -195,6 +195,7 @@ status = "draft — needs native review" "Boolean" = "منطقي" "Boolean groups" = "المجموعات المنطقية" "Both directions" = "كلا الاتجاهين" +"Both sides" = "كلا الجانبين" "Bottom" = "أسفل" "Bottom left radius" = "نصف قطر الزاوية السفلية اليسرى" "Bottom padding" = "الحشو السفلي" diff --git a/crates/ui-egui/locales/bn.toml b/crates/ui-egui/locales/bn.toml index e893f2a84..11ad3f86f 100644 --- a/crates/ui-egui/locales/bn.toml +++ b/crates/ui-egui/locales/bn.toml @@ -188,6 +188,7 @@ status = "draft — needs native review" "Boolean" = "বুলিয়ান" "Boolean groups" = "বুলিয়ান গ্রুপ" "Both directions" = "উভয় দিক" +"Both sides" = "উভয় পাশে" "Bottom" = "নিচে" "Bottom left radius" = "নিচের বাম ব্যাসার্ধ" "Bottom right radius" = "নিচের ডান ব্যাসার্ধ" diff --git a/crates/ui-egui/locales/bs.toml b/crates/ui-egui/locales/bs.toml index e1623f039..3f5683311 100644 --- a/crates/ui-egui/locales/bs.toml +++ b/crates/ui-egui/locales/bs.toml @@ -193,6 +193,7 @@ status = "draft — needs native review" "Boolean" = "Logička vrijednost" "Boolean groups" = "Booleove grupe" "Both directions" = "Oba smjera" +"Both sides" = "Obje strane" "Bottom" = "Dno" "Bottom left radius" = "Radijus donjeg lijevog ugla" "Bottom padding" = "Donja unutrašnja margina" diff --git a/crates/ui-egui/locales/cs.toml b/crates/ui-egui/locales/cs.toml index 98a79e99a..a6d13a610 100644 --- a/crates/ui-egui/locales/cs.toml +++ b/crates/ui-egui/locales/cs.toml @@ -182,6 +182,7 @@ status = "draft — needs native review" "Boolean" = "Logická hodnota" "Boolean groups" = "Booleovské skupiny" "Both directions" = "Oba směry" +"Both sides" = "Obě strany" "Bottom" = "Dole" "Bottom left radius" = "Poloměr levého dolního rohu" "Bottom right radius" = "Poloměr pravého dolního rohu" diff --git a/crates/ui-egui/locales/de.toml b/crates/ui-egui/locales/de.toml index 9d26534ce..0dabc0783 100644 --- a/crates/ui-egui/locales/de.toml +++ b/crates/ui-egui/locales/de.toml @@ -182,6 +182,7 @@ status = "draft — needs native review" "Boolean" = "Boolesch" "Boolean groups" = "Boolesche Gruppen" "Both directions" = "Beide Richtungen" +"Both sides" = "Beide Seiten" "Bottom" = "Unten" "Bottom left radius" = "Radius unten links" "Bottom right radius" = "Radius unten rechts" diff --git a/crates/ui-egui/locales/en.toml b/crates/ui-egui/locales/en.toml index ef811e063..f44897dc1 100644 --- a/crates/ui-egui/locales/en.toml +++ b/crates/ui-egui/locales/en.toml @@ -218,6 +218,7 @@ name = "English" "Boolean" = "Boolean" "Boolean groups" = "Boolean groups" "Both directions" = "Both directions" +"Both sides" = "Both sides" "Bottom" = "Bottom" "Bottom left radius" = "Bottom left radius" "Bottom padding" = "Bottom padding" diff --git a/crates/ui-egui/locales/es.toml b/crates/ui-egui/locales/es.toml index 7bf45f91e..ae0c8991c 100644 --- a/crates/ui-egui/locales/es.toml +++ b/crates/ui-egui/locales/es.toml @@ -225,6 +225,7 @@ status = "draft — needs native review" "Boolean" = "Booleano" "Boolean groups" = "Grupos booleanos" "Both directions" = "Ambas direcciones" +"Both sides" = "Ambos lados" "Bottom" = "Abajo" "Bottom left radius" = "Radio inferior izquierdo" "Bottom padding" = "Margen interno inferior" @@ -1955,6 +1956,7 @@ status = "draft — needs native review" "board.connector" = "Conector" "board.ink" = "Trazo de rotulador" "board.label" = "Etiqueta del conector" +"board.mindMapLayout" = "Disposición del mapa mental" "board.nextSticky" = "Siguiente nota adhesiva" "board.reattach" = "Volver a unir el conector" "board.setColor" = "Color en la pizarra" diff --git a/crates/ui-egui/locales/fi.toml b/crates/ui-egui/locales/fi.toml index fd09c7584..288438a96 100644 --- a/crates/ui-egui/locales/fi.toml +++ b/crates/ui-egui/locales/fi.toml @@ -198,6 +198,7 @@ status = "draft — needs native review" "Boolean" = "Totuusarvo" "Boolean groups" = "Boolen ryhmät" "Both directions" = "Molemmat suunnat" +"Both sides" = "Molemmat puolet" "Bottom" = "Alhaalta" "Bottom left radius" = "Vasemman alakulman säde" "Bottom padding" = "Alasisämarginaali" @@ -2101,6 +2102,7 @@ status = "draft — needs native review" "board.label" = "Yhdistimen nimiö" "board.mindMap" = "Ajatuskartta" "board.mindMapAdd" = "Lisää ajatuskartan solmu" +"board.mindMapLayout" = "Ajatuskartan asettelu" "board.nextSticky" = "Seuraava muistilappu" "board.reattach" = "Liitä yhdistin uudelleen" "board.setColor" = "Taulun väri" diff --git a/crates/ui-egui/locales/fr.toml b/crates/ui-egui/locales/fr.toml index 04b11f5fb..54b5ae7ff 100644 --- a/crates/ui-egui/locales/fr.toml +++ b/crates/ui-egui/locales/fr.toml @@ -187,6 +187,7 @@ status = "draft — needs native review" "Boolean" = "Booléen" "Boolean groups" = "Groupes booléens" "Both directions" = "Les deux sens" +"Both sides" = "Des deux côtés" "Bottom" = "Bas" "Bottom left radius" = "Rayon inférieur gauche" "Bottom right radius" = "Rayon inférieur droit" diff --git a/crates/ui-egui/locales/he.toml b/crates/ui-egui/locales/he.toml index 4cfc2aeba..71425069a 100644 --- a/crates/ui-egui/locales/he.toml +++ b/crates/ui-egui/locales/he.toml @@ -211,6 +211,7 @@ Archive = "העברה לארכיון" "Boolean" = "בוליאני" "Boolean groups" = "קבוצות בוליאניות" "Both directions" = "שני הכיוונים" +"Both sides" = "שני הצדדים" "Bottom" = "למטה" "Bottom left radius" = "רדיוס פינה שמאלית תחתונה" "Bottom padding" = "ריפוד תחתון" @@ -2167,6 +2168,7 @@ Update = "עדכון" "board.label" = "תווית מחבר" "board.mindMap" = "מפת חשיבה" "board.mindMapAdd" = "הוספת צומת למפת חשיבה" +"board.mindMapLayout" = "פריסת מפת חשיבה" "board.nextSticky" = "פתקית דביקה הבאה" "board.reattach" = "חיבור מחדש של מחבר" "board.reshape" = "עיצוב מחדש של מחבר" diff --git a/crates/ui-egui/locales/id.toml b/crates/ui-egui/locales/id.toml index f5849d0e6..c6d16bc4f 100644 --- a/crates/ui-egui/locales/id.toml +++ b/crates/ui-egui/locales/id.toml @@ -207,6 +207,7 @@ status = "draft — needs native review" "Boolean" = "Boolean" "Boolean groups" = "Grup boolean" "Both directions" = "Kedua arah" +"Both sides" = "Kedua sisi" "Bottom" = "Bawah" "Bottom left radius" = "Radius kiri bawah" "Bottom right radius" = "Radius kanan bawah" diff --git a/crates/ui-egui/locales/it.toml b/crates/ui-egui/locales/it.toml index 009c776df..9d74fe81e 100644 --- a/crates/ui-egui/locales/it.toml +++ b/crates/ui-egui/locales/it.toml @@ -212,6 +212,7 @@ status = "draft — needs native review" "Boolean" = "Booleano" "Boolean groups" = "Gruppi booleani" "Both directions" = "Entrambe le direzioni" +"Both sides" = "Entrambi i lati" "Bottom" = "In basso" "Bottom left radius" = "Raggio in basso a sinistra" "Bottom padding" = "Margine interno inferiore" @@ -2162,6 +2163,7 @@ status = "draft — needs native review" "board.label" = "Etichetta del connettore" "board.mindMap" = "Mappa mentale" "board.mindMapAdd" = "Aggiungi nodo alla mappa mentale" +"board.mindMapLayout" = "Layout della mappa mentale" "board.nextSticky" = "Nota adesiva successiva" "board.reattach" = "Ricollega connettore" "board.reshape" = "Rimodella connettore" diff --git a/crates/ui-egui/locales/ja.toml b/crates/ui-egui/locales/ja.toml index 8358dd595..f97ace1e8 100644 --- a/crates/ui-egui/locales/ja.toml +++ b/crates/ui-egui/locales/ja.toml @@ -188,6 +188,7 @@ status = "draft — needs native review" "Boolean" = "ブーリアン" "Boolean groups" = "ブーリアングループ" "Both directions" = "両方向" +"Both sides" = "両側" "Bottom" = "下" "Bottom left radius" = "左下の半径" "Bottom right radius" = "右下の半径" diff --git a/crates/ui-egui/locales/ka.toml b/crates/ui-egui/locales/ka.toml index 14f3b21c2..476c08f3c 100644 --- a/crates/ui-egui/locales/ka.toml +++ b/crates/ui-egui/locales/ka.toml @@ -199,6 +199,7 @@ status = "draft — reviewed by a native speaker, awaiting a maintainer's approv "Boolean" = "ლოგიკური" "Boolean groups" = "ლოგიკური ოპერაციების ჯგუფები" "Both directions" = "ორივე მიმართულება" +"Both sides" = "ორივე მხარე" "Bottom" = "ქვემოთ" "Bottom left radius" = "ქვედა მარცხენა რადიუსი" "Bottom padding" = "ქვედა შიდა დაშორება" diff --git a/crates/ui-egui/locales/ko.toml b/crates/ui-egui/locales/ko.toml index f3eef61f6..c33893361 100644 --- a/crates/ui-egui/locales/ko.toml +++ b/crates/ui-egui/locales/ko.toml @@ -179,6 +179,7 @@ status = "draft — needs native review" "Boolean" = "불리언" "Boolean groups" = "불리언 그룹" "Both directions" = "양방향" +"Both sides" = "양쪽" "Bottom" = "아래쪽" "Bottom left radius" = "왼쪽 아래 반경" "Bottom right radius" = "오른쪽 아래 반경" diff --git a/crates/ui-egui/locales/nl.toml b/crates/ui-egui/locales/nl.toml index bed51db99..4bde50c13 100644 --- a/crates/ui-egui/locales/nl.toml +++ b/crates/ui-egui/locales/nl.toml @@ -189,6 +189,7 @@ status = "draft — needs native review" "Boolean" = "Boolean" "Boolean groups" = "Booleaanse groepen" "Both directions" = "Beide richtingen" +"Both sides" = "Beide kanten" "Bottom" = "Onder" "Bottom left radius" = "Radius linksonder" "Bottom right radius" = "Radius rechtsonder" diff --git a/crates/ui-egui/locales/pl.toml b/crates/ui-egui/locales/pl.toml index 5dc842e20..18082cd2c 100644 --- a/crates/ui-egui/locales/pl.toml +++ b/crates/ui-egui/locales/pl.toml @@ -188,6 +188,7 @@ name = "Polski" "Boolean" = "Wartość logiczna" "Boolean groups" = "Grupy logiczne (Boolean)" "Both directions" = "W obu kierunkach" +"Both sides" = "Obie strony" "Bottom" = "Dół" "Bottom left radius" = "Promień lewego dolnego narożnika" "Bottom padding" = "Margines dolny" diff --git a/crates/ui-egui/locales/pt-BR.toml b/crates/ui-egui/locales/pt-BR.toml index d7338b2ab..09a565c65 100644 --- a/crates/ui-egui/locales/pt-BR.toml +++ b/crates/ui-egui/locales/pt-BR.toml @@ -177,6 +177,7 @@ status = "draft — needs native review" "Boolean" = "Booleano" "Boolean groups" = "Grupos booleanos" "Both directions" = "Ambas as direções" +"Both sides" = "Ambos os lados" "Bottom" = "Embaixo" "Bottom left radius" = "Raio inferior esquerdo" "Bottom right radius" = "Raio inferior direito" diff --git a/crates/ui-egui/locales/ru.toml b/crates/ui-egui/locales/ru.toml index 3b69328dd..620b23155 100644 --- a/crates/ui-egui/locales/ru.toml +++ b/crates/ui-egui/locales/ru.toml @@ -189,6 +189,7 @@ name = "Русский" "Boolean" = "Логическое" "Boolean groups" = "Булевы группы" "Both directions" = "Оба направления" +"Both sides" = "С обеих сторон" "Bottom" = "Снизу" "Bottom left radius" = "Радиус нижнего левого угла" "Bottom padding" = "Нижний внутренний отступ" diff --git a/crates/ui-egui/locales/sv.toml b/crates/ui-egui/locales/sv.toml index 0382dd5c8..5785880c2 100644 --- a/crates/ui-egui/locales/sv.toml +++ b/crates/ui-egui/locales/sv.toml @@ -205,6 +205,7 @@ name = "Svenska" "Boolean" = "Boolesk" "Boolean groups" = "Booleska grupper" "Both directions" = "Båda riktningarna" +"Both sides" = "Båda sidor" "Bottom" = "Nederkant" "Bottom left radius" = "Radie nere till vänster" "Bottom padding" = "Nedre padding" @@ -2142,6 +2143,7 @@ name = "Svenska" "board.label" = "Kopplingsetikett" "board.mindMap" = "Tankekarta" "board.mindMapAdd" = "Lägg till nod i tankekarta" +"board.mindMapLayout" = "Tankekartans layout" "board.nextSticky" = "Nästa lapp" "board.reattach" = "Koppla om koppling" "board.reshape" = "Omforma koppling" diff --git a/crates/ui-egui/locales/ta.toml b/crates/ui-egui/locales/ta.toml index 97d190ebd..73c89d9af 100644 --- a/crates/ui-egui/locales/ta.toml +++ b/crates/ui-egui/locales/ta.toml @@ -201,6 +201,7 @@ status = "draft — needs native review" "Boolean" = "பூலியன்" "Boolean groups" = "பூலியன் குழுக்கள்" "Both directions" = "இரு திசைகளிலும்" +"Both sides" = "இரு பக்கங்களிலும்" "Bottom" = "கீழ்" "Bottom left radius" = "கீழ் இடது ஆரம்" "Bottom padding" = "கீழ் பேடிங்" diff --git a/crates/ui-egui/locales/th.toml b/crates/ui-egui/locales/th.toml index ef0e3db3c..8b63a9653 100644 --- a/crates/ui-egui/locales/th.toml +++ b/crates/ui-egui/locales/th.toml @@ -188,6 +188,7 @@ status = "draft — needs native review" "Boolean" = "บูลีน" "Boolean groups" = "กลุ่มบูลีน" "Both directions" = "ทั้งสองทิศทาง" +"Both sides" = "ทั้งสองด้าน" "Bottom" = "ล่าง" "Bottom left radius" = "รัศมีมุมล่างซ้าย" "Bottom padding" = "ระยะขอบในด้านล่าง" diff --git a/crates/ui-egui/locales/tr.toml b/crates/ui-egui/locales/tr.toml index dab5f385f..55a8b07b1 100644 --- a/crates/ui-egui/locales/tr.toml +++ b/crates/ui-egui/locales/tr.toml @@ -187,6 +187,7 @@ name = "Türkçe" "Boolean" = "Boolean" "Boolean groups" = "Boolean grupları" "Both directions" = "İki yönde" +"Both sides" = "Her iki taraf" "Bottom" = "Alt" "Bottom left radius" = "Sol alt yarıçap" "Bottom right radius" = "Sağ alt yarıçap" diff --git a/crates/ui-egui/locales/vi.toml b/crates/ui-egui/locales/vi.toml index 114870929..5cb9ee4a1 100644 --- a/crates/ui-egui/locales/vi.toml +++ b/crates/ui-egui/locales/vi.toml @@ -178,6 +178,7 @@ status = "draft — needs native review" "Boolean" = "Boolean" "Boolean groups" = "Nhóm boolean" "Both directions" = "Cả hai hướng" +"Both sides" = "Hai bên" "Bottom" = "Dưới" "Bottom left radius" = "Bán kính góc dưới trái" "Bottom padding" = "Đệm dưới" diff --git a/crates/ui-egui/locales/zh-Hans.toml b/crates/ui-egui/locales/zh-Hans.toml index 958da35a1..9f3622dc3 100644 --- a/crates/ui-egui/locales/zh-Hans.toml +++ b/crates/ui-egui/locales/zh-Hans.toml @@ -180,6 +180,7 @@ status = "draft — needs native review" "Boolean" = "布尔" "Boolean groups" = "布尔组" "Both directions" = "双向" +"Both sides" = "两侧" "Bottom" = "底部" "Bottom left radius" = "左下圆角" "Bottom right radius" = "右下圆角" diff --git a/crates/ui-egui/locales/zh-Hant.toml b/crates/ui-egui/locales/zh-Hant.toml index 9455cee9d..c04278b7c 100644 --- a/crates/ui-egui/locales/zh-Hant.toml +++ b/crates/ui-egui/locales/zh-Hant.toml @@ -202,6 +202,7 @@ status = "draft — needs native review" "Boolean" = "布林" "Boolean groups" = "布林群組" "Both directions" = "雙向" +"Both sides" = "兩側" "Bottom" = "底部" "Bottom left radius" = "左下圓角半徑" "Bottom padding" = "下內距" diff --git a/crates/ui-egui/src/board_mind_layout_ui_tests.rs b/crates/ui-egui/src/board_mind_layout_ui_tests.rs new file mode 100644 index 000000000..57d9f71f3 --- /dev/null +++ b/crates/ui-egui/src/board_mind_layout_ui_tests.rs @@ -0,0 +1,29 @@ +//! The bar over a selected mind map node ends in its map's layout menu (#2642): it reads the sides +//! the map grows on, and a choice turns the whole map. + +use figcraft_engine::board::{MindSides, mind_sides}; +use serde_json::json; + +use crate::board_ui_tests::{board, click, mind_map, select}; +use crate::live_tests::{flat, has_text, text_center}; + +#[test] +fn a_selected_mind_map_node_has_a_layout_menu_that_turns_its_map() { + let mut u = board(); + let (root, [first, ..], _) = mind_map(&mut u); + select(&mut u, &[first]); + let sides = |u: &crate::layers_drag_tests::Ui| mind_sides(u.app.session.doc().unwrap(), root); + let shapes = flat(&u.frame_output(vec![]).shapes); + assert!(has_text(&shapes, "Right"), "the menu reads Right"); + click(&mut u, text_center(&shapes, "Right")); + let shapes = flat(&u.frame_output(vec![]).shapes); + for name in ["✓ Right", " Left", " Both sides"] { + assert!(has_text(&shapes, name), "{name:?} in the menu"); + } + click(&mut u, text_center(&shapes, " Both sides")); + assert_eq!(sides(&u), Some(MindSides::Both)); + u.frame(vec![]); + assert!(has_text(&flat(&u.frame_output(vec![]).shapes), "Both sides"), "the menu reads Both sides"); + u.app.run("edit.undo", json!({})); + assert_eq!(sides(&u), Some(MindSides::Right)); +} diff --git a/crates/ui-egui/src/board_ui_tests.rs b/crates/ui-egui/src/board_ui_tests.rs index 45c441c71..2c8fb1794 100644 --- a/crates/ui-egui/src/board_ui_tests.rs +++ b/crates/ui-egui/src/board_ui_tests.rs @@ -14,7 +14,7 @@ use crate::layers_drag_tests::Ui; use crate::live_tests::{flat, has_text, text_center}; use crate::shortcuts_tests::press; -fn click(u: &mut Ui, p: Pos2) { +pub(crate) fn click(u: &mut Ui, p: Pos2) { for pressed in [true, false] { u.frame(vec![Event::PointerMoved(p), Event::PointerButton { pos: p, button: PointerButton::Primary, pressed, modifiers: Modifiers::NONE }]); } @@ -26,7 +26,7 @@ fn id(v: &Value) -> NodeId { } /// The app on a new board. -fn board() -> Ui { +pub(crate) fn board() -> Ui { let mut s = Session::new(); s.execute("file.newBoard", &json!({})).unwrap(); let mut u = Ui::new(s); @@ -476,7 +476,7 @@ fn cmd_while_moving_a_connector_end_places_it_on_the_object() { } /// `board.mindMap` at the page's origin: the first node, its three children and their branches. -fn mind_map(u: &mut Ui) -> (NodeId, [NodeId; 3], [NodeId; 3]) { +pub(crate) fn mind_map(u: &mut Ui) -> (NodeId, [NodeId; 3], [NodeId; 3]) { let out = u.app.run("board.mindMap", json!({"x": 0, "y": 0})).unwrap(); u.frame(vec![]); u.frame(vec![]); @@ -512,7 +512,7 @@ fn text_of_node(u: &Ui, n: NodeId) -> String { u.app.session.doc().unwrap().node(t).unwrap().kind.text().unwrap().characters.clone() } -fn select(u: &mut Ui, ids: &[NodeId]) { +pub(crate) fn select(u: &mut Ui, ids: &[NodeId]) { u.app.session.execute("select.set", &json!({"ids": ids})).unwrap(); u.frame(vec![]); u.frame(vec![]); @@ -614,7 +614,7 @@ fn the_bar_colours_and_sizes_a_node_and_restyles_a_branch_without_line_types() { let (_, [c0, c1, _], lines) = mind_map(&mut u); select(&mut u, &[c0]); let r = bar(&u).expect("the bar shows"); - assert_eq!(r.width(), 336.0); + assert_eq!(r.width(), 436.0, "colours, text sizes, then the layout menu"); let text = figcraft_engine::board::text_of(u.app.session.doc().unwrap(), c0).unwrap(); let ink = u.app.session.doc().unwrap().node(text).unwrap().fills.clone(); click(&mut u, pos2(r.min.x + 8.0 + 5.0 * 24.0 + 10.0, r.center().y)); diff --git a/crates/ui-egui/src/canvas/board_bar.rs b/crates/ui-egui/src/canvas/board_bar.rs index 968073618..b1d9a3694 100644 --- a/crates/ui-egui/src/canvas/board_bar.rs +++ b/crates/ui-egui/src/canvas/board_bar.rs @@ -5,7 +5,7 @@ use egui::{Color32, CornerRadius, Pos2, Rect, Sense, Stroke, StrokeKind, Ui, pos2, vec2}; use figcraft_doc::{BOARD_COLORS, BoardItem, BoardShape, CodeLanguage, NodeId, NodeKind, Routing, Stamp, StrokeCap}; use figcraft_engine::ToolId; -use figcraft_engine::board::{BoardTool, STICKY_SIZES, TEXT_SIZES}; +use figcraft_engine::board::{BoardTool, MindSides, STICKY_SIZES, TEXT_SIZES}; use figcraft_engine::board_grid::GridStyle; use serde_json::{Value, json}; @@ -126,6 +126,8 @@ struct Has { code: Option, /// One link card selected: the bar offers to open its page. link: Option, + /// The sides the first selected mind map node's map grows on: the bar ends in the layout menu. + mind: Option, } /// The selected connectors' line as the bar shows it (the first one's), and their ids. @@ -186,6 +188,7 @@ fn has(app: &FigApp) -> Option { // A node's text takes the board colours as its colour. h.color = true; h.text = true; + h.mind = h.mind.or_else(|| figcraft_engine::board::mind_sides(&ds.doc, n.id)); } Some(BoardItem::Label { .. }) => h.text = true, Some(BoardItem::Table) => h.table = true, @@ -197,7 +200,7 @@ fn has(app: &FigApp) -> Option { } } h.only_lines = h.connector.is_some() && !others; - (h.color || h.text || h.connector.is_some() || h.table || h.code.is_some() || h.link.is_some()).then_some(h) + (h.color || h.text || h.connector.is_some() || h.table || h.code.is_some() || h.link.is_some() || h.mind.is_some()).then_some(h) } const CELL: f32 = 28.0; @@ -211,6 +214,8 @@ const STICKY_W: f32 = 96.0; const LANGUAGE_W: f32 = 104.0; /// The Open link button's width. const OPEN_W: f32 = 88.0; +/// The mind map layout menu's width: its name ("Both sides") and the chevron. +const MIND_W: f32 = 92.0; impl Has { /// The bar's width for these parts. @@ -243,6 +248,9 @@ impl Has { if self.link.is_some() { w += OPEN_W; } + if self.mind.is_some() { + w += MIND_W + PART_END; + } w } } @@ -296,6 +304,9 @@ pub fn show(app: &mut FigApp, ctx: &egui::Context) { if let Some(language) = h.code { x = language_part(app, ui, language, pos2(x, cy), &t); } + if let Some(sides) = h.mind { + x = mind_part(app, ui, sides, pos2(x, cy), &t); + } if let Some(line) = &h.connector { line_part(app, ui, line, pos2(x, cy), &t); } @@ -432,16 +443,9 @@ fn sticky_size_label(size: f64) -> Option<&'static str> { /// The sticky text size menu at `at` (its left edge and middle), showing `size` by name, or as a /// number when no entry has it; `board.setStyle {fontSize}`; where the next part starts. fn sticky_size_part(app: &mut FigApp, ui: &mut Ui, size: f64, at: Pos2, t: &Tokens) -> f32 { - let r = Rect::from_min_size(pos2(at.x, at.y - CELL / 2.0), vec2(STICKY_W, CELL)); let tip = tr("Text size"); - let resp = ui.interact(r, ui.scope_id().with("bb_sticky_size"), Sense::click()).on_hover_text(tip); - a11y::menu_button(&resp, tip, a11y::menu_open(&resp)); - if resp.hovered() { - ui.painter().rect_filled(r, CornerRadius::same(5), t.hover); - } let name = sticky_size_label(size).map_or_else(|| format!("{}", (size * 100.0).round() / 100.0), |l| tr(l).to_string()); - ui.painter().text(pos2(r.min.x + 8.0, at.y), egui::Align2::LEFT_CENTER, name, semibold(11.0), t.text); - icons::paint(ui.painter(), Rect::from_center_size(pos2(r.max.x - 9.0, at.y), vec2(12.0, 12.0)), Icon::Chevron, t.icon_secondary); + let resp = menu_button(ui, (at, STICKY_W), "bb_sticky_size", (tip, tip), &name, t); crate::right::menu_popup(&resp).show(|ui| { for (name, value) in STICKY_SIZES { let label = sticky_size_label(value).unwrap_or(name); @@ -457,15 +461,8 @@ fn sticky_size_part(app: &mut FigApp, ui: &mut Ui, size: f64, at: Pos2, t: &Toke /// The code language menu at `at` (its left edge and middle), showing `language`: /// `board.setLanguage` on the selected blocks; where the next part starts. fn language_part(app: &mut FigApp, ui: &mut Ui, language: CodeLanguage, at: Pos2, t: &Tokens) -> f32 { - let r = Rect::from_min_size(pos2(at.x, at.y - CELL / 2.0), vec2(LANGUAGE_W, CELL)); - let tip = tr("Language"); - let resp = ui.interact(r, ui.scope_id().with("bb_language"), Sense::click()).on_hover_text(tip); - a11y::menu_button(&resp, &format!("{tip} {}", tr(language.label())), a11y::menu_open(&resp)); - if resp.hovered() { - ui.painter().rect_filled(r, CornerRadius::same(5), t.hover); - } - ui.painter().text(pos2(r.min.x + 8.0, at.y), egui::Align2::LEFT_CENTER, tr(language.label()), semibold(11.0), t.text); - icons::paint(ui.painter(), Rect::from_center_size(pos2(r.max.x - 9.0, at.y), vec2(12.0, 12.0)), Icon::Chevron, t.icon_secondary); + let (tip, name) = (tr("Language"), tr(language.label())); + let resp = menu_button(ui, (at, LANGUAGE_W), "bb_language", (tip, &format!("{tip} {name}")), name, t); crate::right::menu_popup(&resp).show(|ui| { for l in CodeLanguage::ALL { if crate::right::menu_check(ui, l == language, tr(l.label()), "") { @@ -492,6 +489,36 @@ fn open_part(app: &mut FigApp, ui: &mut Ui, id: NodeId, at: Pos2, t: &Tokens) { } } +/// The mind map layout menu at `at` (its left edge and middle), showing the sides `sides` the map +/// grows on: `board.mindMapLayout` on the selected node's map; where the next part starts. +fn mind_part(app: &mut FigApp, ui: &mut Ui, sides: MindSides, at: Pos2, t: &Tokens) -> f32 { + let (tip, name) = (tr("Layout"), tr(sides.label())); + let resp = menu_button(ui, (at, MIND_W), "bb_mind_layout", (tip, &format!("{tip} {name}")), name, t); + crate::right::menu_popup(&resp).show(|ui| { + for m in MindSides::ALL { + if crate::right::menu_check(ui, m == sides, tr(m.label()), "") { + app.run("board.mindMapLayout", json!({"layout": m.id()})); + ui.close(); + } + } + }); + divider(ui, t, at.x + MIND_W, at.y) +} + +/// A menu button of the bar at `at` (its left edge and middle) and that wide, named `tip` on hover +/// and `spoken` to a screen reader (which starts with `tip`), showing `name` and a chevron. +fn menu_button(ui: &mut Ui, (at, w): (Pos2, f32), key: &str, (tip, spoken): (&str, &str), name: &str, t: &Tokens) -> egui::Response { + let r = Rect::from_min_size(pos2(at.x, at.y - CELL / 2.0), vec2(w, CELL)); + let resp = ui.interact(r, ui.scope_id().with(key), Sense::click()).on_hover_text(tip); + a11y::menu_button(&resp, spoken, a11y::menu_open(&resp)); + if resp.hovered() { + ui.painter().rect_filled(r, CornerRadius::same(5), t.hover); + } + ui.painter().text(pos2(r.min.x + 8.0, at.y), egui::Align2::LEFT_CENTER, name, semibold(11.0), t.text); + icons::paint(ui.painter(), Rect::from_center_size(pos2(r.max.x - 9.0, at.y), vec2(12.0, 12.0)), Icon::Chevron, t.icon_secondary); + resp +} + /// A start or end point menu's width: the end's picture and the menu's chevron. const CAP_W: f32 = 62.0; /// The line style menu's width. diff --git a/crates/ui-egui/src/i18n/tests.rs b/crates/ui-egui/src/i18n/tests.rs index 4e222c104..7cec75cc9 100644 --- a/crates/ui-egui/src/i18n/tests.rs +++ b/crates/ui-egui/src/i18n/tests.rs @@ -134,6 +134,7 @@ fn dynamic_labels() -> Vec<&'static str> { v.extend(figcraft_doc::BoardShape::ALL.iter().map(|b| b.label())); v.extend(figcraft_doc::Stamp::ALL.iter().map(|b| b.label())); v.extend(figcraft_doc::CodeLanguage::ALL.iter().map(|l| l.label())); + v.extend(figcraft_engine::board::MindSides::ALL.iter().map(|m| m.label())); v.extend(figcraft_engine::board_templates::TEMPLATES.iter().map(|t| t.name)); v.extend(Group::ALL.iter().map(|g| g.label())); v.extend(GESTURES.iter().flat_map(|(_, label, mac, other)| [*label, *mac, *other])); diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs index 944e393b1..7f8cbbbf3 100644 --- a/crates/ui-egui/src/lib.rs +++ b/crates/ui-egui/src/lib.rs @@ -48,6 +48,8 @@ mod board_connect_tests; #[cfg(test)] mod board_line_tests; #[cfg(test)] +mod board_mind_layout_ui_tests; +#[cfg(test)] mod board_picker_tests; #[cfg(test)] mod board_ui_tests; diff --git a/docs/boards-parity.md b/docs/boards-parity.md index 3c3c9f50e..8d239877e 100644 --- a/docs/boards-parity.md +++ b/docs/boards-parity.md @@ -1,6 +1,6 @@ # Boards parity -> **Last reviewed:** 2026-10-24 · **Last updated:** 2026-11-28 · **Change:** minor (a `.jam` file's connectors come in as native board connectors attached to the layers they join (#1808); the Pencil, Marker, Highlighter and Eraser show a round tip at the pointer, in the ink's colour and as wide as the stroke (#2641); code blocks from the toolbar's Text tools flyout or the `` ` `` key, a language menu in the bar over a selected block, and handles on a block's left and right edges only (#2237); a mind map node dropped on another node becomes its child, with everything under it (#2226); code blocks colour keywords, strings, numbers and comments by their language (#2237); the ink colour and stroke weight of the Marker, Highlighter and Pencil are chosen before drawing, in a bar above the toolbar (#2395); mind maps from the toolbar and the keyboard: Shapes ▸ Mind map places one with a click, Cmd/Ctrl+Enter adds a child and Shift+Cmd/Ctrl+Enter a sibling, Tab goes to the next sibling (#2226); code blocks, first step: a dark panel of monospace text as tall as its lines, in one of 16 languages (`board.codeBlock`, `board.setLanguage`, #2237); a `.jam` file's shapes with text come in as native board shapes for the 23 kinds FigCraft draws, the other 7 as frames (#1808); a sticky has a text-size menu in the contextual bar, Small 16, Medium 24, Large 40, Extra large 64 and Huge 96, with Small the default (an earlier reading of 18 did not reproduce); `board.setStyle {fontSize}` sizes stickies and the sticky tool remembers the last size for new ones; the note grows taller at Huge and shrinks back, as measured in FigJam's web app, 2026-11-12; resizing a board table by height changes its rows, not blank space below them: a bottom or top edge grows the last row, a corner shares the change over every row, and a table keeps at least 40 per cell, measured in FigJam's web app, 2026-11-09 (#2172); a `.jam` file's stickies come in as native board stickies, with their colour, text and author kept and the size as saved (#1808); a sticky's text stays 18 and the note grows taller instead of the text shrinking, as measured in FigJam's web app (#2157); mind maps, first step: a first node with three children on curved branches, laid out again after every edit (`board.mindMap`, `board.mindMapAdd`, #2226); a `.jam` elbowed connector saved with its path keeps it on import instead of being routed again (#1910); a "+" handle dragged carries the preview: the next shape is made where it is let go, or a connector joins the object it is let go on (#1919); a connector attached to a side starts 4 pt outside the border, so its stroke never lies on the fill (#1916); a connector end moved with Cmd/Ctrl held goes on any part of an object, and stays there as the object moves or resizes; a connector end dropped along a side of a shape attaches to that side (#1708); a board connector's path can be reshaped by dragging its path handles (#1710); boards have 16 more shapes (arrows, polygons, star, plus and flowchart symbols), in pickers that lay them out in a grid; a board keeps earlier votes' results, listed newest first in Results and deleted one at a time; a connector's bar sets its start and end points, dashes, weight and any colour (#1596); cells copied from a spreadsheet paste onto a board as a table; Shift+Cmd/Ctrl+Enter on a selected board shape adds the next shape already joined to it, and goes on typing (#1597); "+" handles beside a selected sticky or shape make the next one, joined by a connector (#1597); a FigJam `.jam` file opens as a board (#1342); board grid settings: dots, lines, graph paper or none, spacing, size and contrast; the connector tool shows the connector it will make while dragging, ends snapping to attach points (#1387); templates and tables; facilitation: a shared timer and voting sessions; the dot grid, dragging a connector's end to re-attach it, curved connectors, elbows that go around what they join) · **Target:** the incumbent's whiteboard product (behaviour from its public help centre) +> **Last reviewed:** 2026-10-24 · **Last updated:** 2026-12-01 · **Change:** minor (a mind map grows right, left or on both sides of its first node, chosen in the Layout menu of the bar over a node (`board.mindMapLayout`, #2642); a `.jam` file's connectors come in as native board connectors attached to the layers they join (#1808); the Pencil, Marker, Highlighter and Eraser show a round tip at the pointer, in the ink's colour and as wide as the stroke (#2641); code blocks from the toolbar's Text tools flyout or the `` ` `` key, a language menu in the bar over a selected block, and handles on a block's left and right edges only (#2237); a mind map node dropped on another node becomes its child, with everything under it (#2226); code blocks colour keywords, strings, numbers and comments by their language (#2237); the ink colour and stroke weight of the Marker, Highlighter and Pencil are chosen before drawing, in a bar above the toolbar (#2395); mind maps from the toolbar and the keyboard: Shapes ▸ Mind map places one with a click, Cmd/Ctrl+Enter adds a child and Shift+Cmd/Ctrl+Enter a sibling, Tab goes to the next sibling (#2226); code blocks, first step: a dark panel of monospace text as tall as its lines, in one of 16 languages (`board.codeBlock`, `board.setLanguage`, #2237); a `.jam` file's shapes with text come in as native board shapes for the 23 kinds FigCraft draws, the other 7 as frames (#1808); a sticky has a text-size menu in the contextual bar, Small 16, Medium 24, Large 40, Extra large 64 and Huge 96, with Small the default (an earlier reading of 18 did not reproduce); `board.setStyle {fontSize}` sizes stickies and the sticky tool remembers the last size for new ones; the note grows taller at Huge and shrinks back, as measured in FigJam's web app, 2026-11-12; resizing a board table by height changes its rows, not blank space below them: a bottom or top edge grows the last row, a corner shares the change over every row, and a table keeps at least 40 per cell, measured in FigJam's web app, 2026-11-09 (#2172); a `.jam` file's stickies come in as native board stickies, with their colour, text and author kept and the size as saved (#1808); a sticky's text stays 18 and the note grows taller instead of the text shrinking, as measured in FigJam's web app (#2157); mind maps, first step: a first node with three children on curved branches, laid out again after every edit (`board.mindMap`, `board.mindMapAdd`, #2226); a `.jam` elbowed connector saved with its path keeps it on import instead of being routed again (#1910); a "+" handle dragged carries the preview: the next shape is made where it is let go, or a connector joins the object it is let go on (#1919); a connector attached to a side starts 4 pt outside the border, so its stroke never lies on the fill (#1916); a connector end moved with Cmd/Ctrl held goes on any part of an object, and stays there as the object moves or resizes; a connector end dropped along a side of a shape attaches to that side (#1708); a board connector's path can be reshaped by dragging its path handles (#1710); boards have 16 more shapes (arrows, polygons, star, plus and flowchart symbols), in pickers that lay them out in a grid; a board keeps earlier votes' results, listed newest first in Results and deleted one at a time; a connector's bar sets its start and end points, dashes, weight and any colour (#1596); cells copied from a spreadsheet paste onto a board as a table; Shift+Cmd/Ctrl+Enter on a selected board shape adds the next shape already joined to it, and goes on typing (#1597); "+" handles beside a selected sticky or shape make the next one, joined by a connector (#1597); a FigJam `.jam` file opens as a board (#1342); board grid settings: dots, lines, graph paper or none, spacing, size and contrast; the connector tool shows the connector it will make while dragging, ends snapping to attach points (#1387); templates and tables; facilitation: a shared timer and voting sessions; the dot grid, dragging a connector's end to re-attach it, curved connectors, elbows that go around what they join) · **Target:** the incumbent's whiteboard product (behaviour from its public help centre) **Breadth ~48%, ready ~30% (estimated, erring low).** A board is a FigCraft file of its own kind (`file.newBoard`) with a dot grid on the page, sticky notes, shapes with text, connectors that @@ -58,7 +58,7 @@ all end with the same geometry. | Board widgets | missing | design-file widgets exist (`crates/engine/src/extensions/widgets.rs`), not wired to boards | | Templates (retrospective, brainstorm, flow chart…) | partial | five built-in templates drawn up for FigCraft (retrospective, brainstorm, weekly planner, flow chart, kanban board), placed from the toolbar's templates picker (each with a picture of itself) or `board.template {name, x?, y?}` as ordinary sections, stickies, shapes, connectors and text in one undo step; `board.templates` lists them. No community templates, no saving your own | | Tables | partial | `board.table {rows, columns, cells?, x?, y?}` (at most 50 × 20): an auto layout frame of rows of cells with text, a tinted header row and lines between rows and columns; a cell's row grows with its text; each column keeps its own width; resizing a table by its bottom edge or its height grows the last row, by a side edge or its width the last column, and a corner drag shares the change equally over every row and column (also after a column was sized); dragging the border between two columns of the selected table sizes the column on its left and the table grows or shrinks with it (on a table that isn't selected the drag moves it), also `board.tableEdit {action: resizeColumn, index, size}`; the table keeps hugging its rows and columns and a cell keeps at least 40 each way (measured 2026-11-09: the reference's floor is about 52, FigCraft's is 40); a table saved with equal columns keeps its look until it is resized or edited; a double-click types in the cell under the pointer; add or remove a row or column from the bar over the selection or `board.tableEdit {id, action, index?}`; cells copied from a spreadsheet (tab-separated text, quoted cells kept whole) paste as a table, up to 50 × 20 with a note when there was more; undoable and synced in live sessions. No row resizing by dragging a row's border, no cell colours, no Tab between cells; comma-separated text pastes as text | -| Mind maps | partial | Shapes ▸ Mind map in the toolbar, then a click: a first node (bold, no box) whose text starts at the click, with three children on its right joined by curved branches, and typing starts in the first node (#2226). Cmd/Ctrl+Enter on a node, selected or being typed in, adds a child below its other children; Shift+Cmd/Ctrl+Enter adds a sibling right after it (the first node has none); both go on typing in the new node. Tab and Shift+Tab select the next and previous sibling; Enter types in the selected node. The bar over a node sets its text colour and size; over a branch its colour, start and end points, dashes and weight. From commands: `board.mindMap {x?, y?, text?, children?}`, `board.mindMapAdd {id?, relation?: child\|sibling}`, `tool.mindMap`. Nodes are text that grows wider as it is typed and taller with line breaks; a node's children stand in one column 88 units right of the widest node of its own column, 48 apart, centred on it, and the map lays itself out again in the normalize pass after every edit, undo and live-session change; moving the first node moves the map; a node dropped on another node (its middle let go on it, by a drag or a nudge) becomes that node's child with everything under it, its branch leaving the new parent, and a drop on a node under it changes nothing, nor its parent (on its own parent it lands among its siblings by its middle, as any child moved by hand does); a deleted node's children stay where they are without their branch. Branches are board connectors (`branch`: stroke 4, #757575, round caps). No "+" handles, outline around the map, detaching a node by dragging it away, left side or `.jam` import yet | +| Mind maps | partial | Shapes ▸ Mind map in the toolbar, then a click: a first node (bold, no box) whose text starts at the click, with three children on its right joined by curved branches, and typing starts in the first node (#2226). Cmd/Ctrl+Enter on a node, selected or being typed in, adds a child below its other children; Shift+Cmd/Ctrl+Enter adds a sibling right after it (the first node has none); both go on typing in the new node. Tab and Shift+Tab select the next and previous sibling; Enter types in the selected node. The bar over a node sets its text colour and size; over a branch its colour, start and end points, dashes and weight. From commands: `board.mindMap {x?, y?, text?, children?}`, `board.mindMapAdd {id?, relation?: child\|sibling}`, `tool.mindMap`. Nodes are text that grows wider as it is typed and taller with line breaks; a node's children stand in one column 88 units right of the widest node of its own column, 48 apart, centred on it, and the map lays itself out again in the normalize pass after every edit, undo and live-session change; moving the first node moves the map; a node dropped on another node (its middle let go on it, by a drag or a nudge) becomes that node's child with everything under it, its branch leaving the new parent, and a drop on a node under it changes nothing, nor its parent (on its own parent it lands among its siblings by its middle, as any child moved by hand does); a deleted node's children stay where they are without their branch. Branches are board connectors (`branch`: stroke 4, #757575, round caps). The bar over a node ends in a Layout menu, Right, Left or Both sides (`board.mindMapLayout {id?, layout: right|left|both}`): the map's branches change side, every node keeps its parent, on both sides the first half of the first node's children go right, and a new child of the first node goes on the map's side (the shorter side on both). No "+" handles, outline view, top-down org chart layout, branch colour themes, images on nodes, detaching a node by dragging it away or `.jam` import yet | | Code blocks | partial | #2237: the toolbar's Text tools flyout ends in Code block (`tool.codeBlock`, also the `` ` `` key, boards only), and a click then places a block centred there and starts typing in it, back on the Move tool after; `board.codeBlock {x?, y?, language?, text?, width?}` places one by command. A block is a dark panel holding monospace text (Liberation Mono 16 on a 24 line where it is embedded or installed), 576 wide; its height is its lines (32 + 24 a line, wrapped lines counted, never under four lines) and only its width can be changed (210 at least): a selected block has handles on its left and right edges only, and a press on a corner or the top or bottom edge moves it; the bar over a selected block ends in a language menu, the block's language checked, and `board.setLanguage {id?, language}` keeps one of 16 languages (TypeScript by default); `board.nextSticky` on a block makes the next one 128 to its right, as wide and in the same language. In a block Tab types two spaces, Enter keeps the line's indent, and lists, links and styled ranges don't apply. The code is coloured as its language writes it: keywords, strings, numbers and comments each in a colour of FigCraft's own (each at least 4.5:1 on the panel), kept on the text's runs by the normalize pass, so the canvas and PNG, SVG and PDF exports show the same, and a language change or an edit colours it again (`board::code_tokens`, a small tokenizer per language; a quoted string ends with its line, plain text stays uncoloured). No line-number gutter or `.jam` import yet | | Link cards | partial | #2205: a web address pasted on a board (one `http` or `https` address, nothing around it) becomes a link card at once: a white card with the address as its title and the site under it (`board.link {url, x?, y?}`); then the desktop app reads the page in the background (10 seconds at most, 4 MB at most, no cookies) and shows the title, site name and picture its head names (its sharing tags, else its ``; `board.linkPreview {id?}`). Offline, in the browser build or when the page can't be read the card stays as it was and a note says why. The bar over one selected card has Open link (`board.openLink`). No embedded players, no description line, no refresh of a card's preview from the UI | | Washi tape, image cropping on boards | missing | images can be placed as in design files | @@ -73,6 +73,7 @@ all end with the same geometry. |---|---|---| | 2026-12-01 | minor | M12, #2176: board tables had no per-column widths: every cell filled its row, so a drag of the right edge split the change equally where the reference grows only the last column, and a column couldn't be sized on its own. Each cell is now fixed at its column's width and the rows and the table hug them; column lines sit on the borders. `board_table::settle_resize` puts a width change into the last column (a corner drag shares it over every column), and a press on the border between two columns of the selected table drags that border: the column on its left takes the change and the table grows or shrinks with it, in one undo step through `board.tableEdit {action: resizeColumn, index, size}`. New rows and columns take the table's widths (a new column 160 wide); a table saved with equal columns keeps its look and takes those widths as its own when it is resized or edited. Supersedes #1736's sizing part. Not done: row borders, the lock-proportions control (still shown). Numbers unchanged. Tests: `board_table_columns_tests`. | | 2026-12-01 | minor | M12, #2205: a web address pasted on a board stayed a text layer. It now becomes a link card (`BoardItem::Link`, `board.link`), filled in by a preview the desktop app reads in the background through the session's network link (`NetRequest::Web`, `board.linkPreview`): the page's title, site name and picture, or a note when it can't be read; Open link in the bar (`board.openLink`). Tests: `board_link_tests` | +| 2026-12-01 | minor | M12, #2642 (part: map structures): a mind map could only grow right of its first node. The bar over a selected node now ends in a Layout menu, Right, Left or Both sides (`board.mindMapLayout`): the map's branches change side and it lays itself out again, every node keeping its parent and deeper nodes following their side; on both sides the first half of the first node's children (right ones, then left ones, top to bottom) go right. A new child of the first node goes on the map's side, on a two-sided map the side with fewer children, and a node dropped on the first node joins it the same way. One undo step. Not in this change: the top-down org chart, the outline view, bends kept on branches, branch colour themes and images on nodes. Tests: `board_mindmap_sides_tests` (engine), `board_mind_layout_ui_tests` (UI). | | 2026-12-01 | minor | M12, #1919: a "+" dragged to empty board made the next one of the same kind there, with no way to choose another. Let go on empty board, it now opens a picker beside the drop point (the next one's box and connector shown meanwhile): the dragged-from one's own kind first with the keyboard on it, so Enter makes what the drop made before, then every shape (the arrows move through them); a click on one makes it there, joined and ready for typing, in one undo step. Escape or a click elsewhere closes it, making nothing; the bar above the selection stays away while it is open. `board.addConnected` gains `shape` (`sticky` or a shape kind; a shape after a sticky is a new shape's size). The "Add another" entry and choosing the connector type on drop are not done. Tests: `board_connect_tests` (the drop ones), engine `board_connected_tests::the_next_one_is_of_the_kind_asked_for`. Numbers unchanged. | | 2026-12-01 | minor | M12, #1707: an elbow connector was routed only from its two ends, so it ran straight through the shapes between them (one shape joined to three stacked on its right: the lines to the second and third crossed the ones above). An elbow whose way would run through another sticky, shape, code block or table on its page now goes around it, on lines 24 units clear of the objects near it, the cheapest way by length and turns (`board_route::route_around`, a search over those lines); with nothing in the way it is the short route as before. Moving an object into an elbow's way, out of it, or deleting it re-routes the elbows near it. An object an end sits on (a section behind both) is left out, a path reshaped by hand is kept, at most 32 objects near a route are gone around, and with no way around the route is as before. Connectors leaving one side still share their first run (the issue's second point, not changed here). Tests: `board_route_around_tests` (doc and engine). Numbers unchanged. | | 2026-12-01 | minor | M12, #2641 (part 3): ink could only be selected stroke by stroke or with the selection box, which takes shapes and stickies too. The drawing tools gain a Lasso (`tool.inkLasso`): a loop around marker and highlighter strokes selects the ones mostly inside it and nothing else, Shift adds, and the Move tool takes over so they move, resize, recolour or go together. A row for it. Tests: `board_ink_lasso_tests`. Numbers unchanged. | diff --git a/docs/mcp.md b/docs/mcp.md index c94000d28..c4d696aa7 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -729,7 +729,14 @@ one undo step and returns the ids it made: - `board.mindMapAdd {id?, relation?: child|sibling, text?, edit?}` → `{id, text, connector}`: a node of the map that the given (or selected, or edited) one belongs to: a child below its other children, or a sibling right after it (the first node has none); the map lays itself out again. - One undo step. With `edit: true` the app goes on typing in it. + One undo step. With `edit: true` the app goes on typing in it. A child of the first node goes on + the side its map grows on (on both sides, the side with fewer children; the right on a tie). +- `board.mindMapLayout {id?, layout: right|left|both}` → `{id, layout}`: the sides of its first node + the map of the given (or selected, or edited) node grows on (`id` in the result: the first node). + On both sides the first half of the first node's children (right ones, then left ones, top to + bottom) go right and the rest left; every node keeps its parent, deeper nodes follow their side, + and the map lays itself out again. One undo step. The bar over a selected node has it as its + Layout menu (#2642). - `board.codeBlock {x?, y?, language?, text?, width?, parent?, edit?}` → `{id, text, language}`: a code block (`codeBlock` with its `language`): a dark panel holding monospace text (Liberation Mono 16 on a 24 line where it is embedded or installed). `language` is `bash cpp css go graphql html javascript json From 6d869ff5c147478d0f67aaf2204a73d4cecd4923 Mon Sep 17 00:00:00 2001 From: bflatastic <bombayapirat@gmail.com> Date: Tue, 1 Dec 2026 12:23:49 +0700 Subject: [PATCH 2/2] M12: a mind map turns into a top-down org chart (#2642, part) The Layout menu of the bar over a mind map node now ends in Org chart (`board.mindMapLayout {layout: down}`). Every level becomes a row under its parent, siblings side by side with the parent centred over them, joined by right-angled lines. Turning between columns and rows keeps every node's place among its siblings (top to bottom becomes left to right, and back), and the lines turn back into curves. In a chart a new child lands at the end of its row and a sibling right after its node, however wide its text. One undo step. --- crates/doc/src/board_mindmap.rs | 16 + crates/doc/src/board_mindmap_down_tests.rs | 60 ++++ crates/doc/src/lib.rs | 4 +- crates/engine/src/board_mindmap_down_tests.rs | 74 +++++ .../engine/src/board_mindmap_sides_tests.rs | 2 +- crates/engine/src/boards/board.rs | 2 +- crates/engine/src/boards/board/mindmap.rs | 286 ++++++++++++------ crates/engine/src/lib.rs | 2 + crates/ui-egui/locales/ar.toml | 1 + crates/ui-egui/locales/bn.toml | 1 + crates/ui-egui/locales/bs.toml | 1 + crates/ui-egui/locales/cs.toml | 1 + crates/ui-egui/locales/de.toml | 1 + crates/ui-egui/locales/en.toml | 1 + crates/ui-egui/locales/es.toml | 1 + crates/ui-egui/locales/fi.toml | 1 + crates/ui-egui/locales/fr.toml | 1 + crates/ui-egui/locales/he.toml | 1 + crates/ui-egui/locales/id.toml | 1 + crates/ui-egui/locales/it.toml | 1 + crates/ui-egui/locales/ja.toml | 1 + crates/ui-egui/locales/ka.toml | 1 + crates/ui-egui/locales/ko.toml | 1 + crates/ui-egui/locales/nl.toml | 1 + crates/ui-egui/locales/pl.toml | 1 + crates/ui-egui/locales/pt-BR.toml | 1 + crates/ui-egui/locales/ru.toml | 1 + crates/ui-egui/locales/sv.toml | 1 + crates/ui-egui/locales/ta.toml | 1 + crates/ui-egui/locales/th.toml | 1 + crates/ui-egui/locales/tr.toml | 1 + crates/ui-egui/locales/vi.toml | 1 + crates/ui-egui/locales/zh-Hans.toml | 1 + crates/ui-egui/locales/zh-Hant.toml | 1 + docs/boards-parity.md | 5 +- docs/mcp.md | 6 +- 36 files changed, 391 insertions(+), 92 deletions(-) create mode 100644 crates/doc/src/board_mindmap_down_tests.rs create mode 100644 crates/engine/src/board_mindmap_down_tests.rs diff --git a/crates/doc/src/board_mindmap.rs b/crates/doc/src/board_mindmap.rs index 53b72fbc3..c53fe9b89 100644 --- a/crates/doc/src/board_mindmap.rs +++ b/crates/doc/src/board_mindmap.rs @@ -136,3 +136,19 @@ pub fn mind_layout(nodes: &[MindBox]) -> Vec<(NodeId, Point)> { } out } + +/// [`mind_layout`] grown downward, an org chart: each level is a row under its parent, its nodes +/// side by side and the parent centred over them. Siblings go in the order of their left edges, so +/// a sibling put just right of a node stays next to it however wide its text grows. `left` is not +/// read. +pub fn mind_layout_down(nodes: &[MindBox]) -> Vec<(NodeId, Point)> { + // The map turned a quarter (x for y) and laid out to the right. A node but the root goes in with + // its middle on its left edge, which orders it; only its size counts besides. + let turn = |(i, b): (usize, &MindBox)| { + let (r, half) = (b.rect, b.rect.width() / 2.0); + let rect = if i == 0 { Rect::new(r.y0, r.x0, r.y1, r.x1) } else { Rect::new(r.y0, r.x0 - half, r.y1, r.x0 + half) }; + MindBox { rect, left: false, ..*b } + }; + let turned: Vec<MindBox> = nodes.iter().enumerate().map(turn).collect(); + mind_layout(&turned).into_iter().map(|(id, p)| (id, Point::new(p.y, p.x))).collect() +} diff --git a/crates/doc/src/board_mindmap_down_tests.rs b/crates/doc/src/board_mindmap_down_tests.rs new file mode 100644 index 000000000..c527b6152 --- /dev/null +++ b/crates/doc/src/board_mindmap_down_tests.rs @@ -0,0 +1,60 @@ +//! Org chart layout (`mind_layout_down`, #2642): rows under their parents, siblings side by side in +//! the order of their left edges, parents centred over their children. + +use figcraft_geom::{Point, Rect}; + +use crate::NodeId; +use crate::board_mindmap::{MindBox, mind_layout_down}; + +fn node(id: u64, parent: Option<usize>, rect: Rect) -> MindBox { + MindBox { id: NodeId(id), rect, parent, left: true } +} + +/// The root at the origin; three children whose left edges put them in the order 3, 2, 4 (the +/// wide one first), and one grandchild under 2. +fn chart() -> Vec<MindBox> { + vec![ + node(1, None, Rect::new(0.0, 0.0, 120.0, 36.0)), + node(2, Some(0), Rect::new(50.0, 0.0, 110.0, 24.0)), + node(3, Some(0), Rect::new(-500.0, 300.0, -200.0, 348.0)), + node(4, Some(0), Rect::new(60.0, -90.0, 100.0, -66.0)), + node(5, Some(1), Rect::new(0.0, 0.0, 40.0, 24.0)), + ] +} + +fn placed(nodes: &[MindBox]) -> Vec<MindBox> { + let to = mind_layout_down(nodes); + nodes + .iter() + .map(|b| match to.iter().find(|(id, _)| *id == b.id) { + Some((_, p)) => MindBox { rect: Rect::from_origin_size(*p, b.rect.size()), ..*b }, + None => *b, + }) + .collect() +} + +#[test] +fn an_org_chart_puts_each_level_in_a_row_under_its_parent_in_left_edge_order() { + let laid = placed(&chart()); + let [root, two, three, four, five] = [0, 1, 2, 3, 4].map(|i| laid[i].rect); + assert_eq!(root, chart()[0].rect, "the root stays"); + // One row under the root, top-aligned, in the order of the left edges they had, not apart. + assert!(two.y0 > root.y1 && two.y0 == three.y0 && two.y0 == four.y0); + assert!(three.x1 < two.x0 && two.x1 < four.x0, "3, 2, 4 from left to right"); + // The row is centred under the root, and the grandchild is a row lower, centred under 2. + assert!(((three.x0 + four.x1) / 2.0 - root.center().x).abs() < 1e-6); + assert!(five.y0 > three.y1 && (five.center().x - two.center().x).abs() < 1e-6); + // Laying the result out again moves nothing. + assert!(mind_layout_down(&laid).iter().all(|(id, p)| laid.iter().any(|b| b.id == *id && (b.rect.origin() - *p).hypot() < 1e-6))); +} + +#[test] +fn a_node_added_just_right_of_its_sibling_stays_next_to_it_however_wide() { + let mut laid = placed(&chart()); + let three = laid[2].rect; + // A new child of the root, 400 wide, whose left edge is just past 3's right edge. + laid.push(node(6, Some(0), Rect::from_origin_size(Point::new(three.x1 + 1.0, three.y0), (400.0, 24.0)))); + let again = placed(&laid); + let (three, new, two) = (again[2].rect, again[5].rect, again[1].rect); + assert!(three.x1 < new.x0 && new.x1 < two.x0, "between 3 and 2, though its middle was past 2's"); +} diff --git a/crates/doc/src/lib.rs b/crates/doc/src/lib.rs index be5e4cf7e..46e30d2ca 100644 --- a/crates/doc/src/lib.rs +++ b/crates/doc/src/lib.rs @@ -32,7 +32,7 @@ pub mod vector_regions; pub use board::*; pub use board_code::*; -pub use board_mindmap::{MIND_GAP_X, MIND_GAP_Y, MIND_MAX_DEPTH, MIND_MAX_NODES, MindBox, mind_layout}; +pub use board_mindmap::{MIND_GAP_X, MIND_GAP_Y, MIND_MAX_DEPTH, MIND_MAX_NODES, MindBox, mind_layout, mind_layout_down}; pub use board_route::{END_GAP, MAX_RUNS, RouteEnd, attach_points, attached_sides, path_handles, reshaped, route_along, route_around, route_points}; pub use colors::*; pub use comments::*; @@ -1378,6 +1378,8 @@ mod blur_tests; #[cfg(test)] mod board_code_tests; #[cfg(test)] +mod board_mindmap_down_tests; +#[cfg(test)] mod board_mindmap_tests; #[cfg(test)] mod board_route_around_tests; diff --git a/crates/engine/src/board_mindmap_down_tests.rs b/crates/engine/src/board_mindmap_down_tests.rs new file mode 100644 index 000000000..5b3eb3d65 --- /dev/null +++ b/crates/engine/src/board_mindmap_down_tests.rs @@ -0,0 +1,74 @@ +//! Mind maps turned into org charts (`board.mindMapLayout {layout: down}`, #2642): every level is a +//! row under its parent joined by right-angled lines, siblings keep their order through every turn, +//! and new nodes land at their place in the row. + +use figcraft_doc::{NodeId, Routing}; +use serde_json::json; + +use crate::Session; +use crate::board::{MindSides, mind_sides}; +use crate::board_mindmap_tests::{bx, map}; +use crate::board_tests::{board, connector, id}; + +fn layout(s: &mut Session, node: NodeId, layout: &str) { + s.execute("board.mindMapLayout", &json!({"id": node, "layout": layout})).unwrap(); +} + +fn add(s: &mut Session, node: NodeId, relation: &str) -> NodeId { + id(&s.execute("board.mindMapAdd", &json!({"id": node, "relation": relation})).unwrap(), "id") +} + +fn left_to_right(s: &Session, row: &[NodeId]) -> bool { + row.windows(2).all(|w| bx(s, w[0]).x1 < bx(s, w[1]).x0) +} + +fn top_to_bottom(s: &Session, column: &[NodeId]) -> bool { + column.windows(2).all(|w| bx(s, w[0]).y1 < bx(s, w[1]).y0) +} + +fn below(s: &Session, child: NodeId, parent: NodeId) -> bool { + bx(s, child).y0 > bx(s, parent).y1 +} + +#[test] +fn an_org_chart_puts_each_level_in_a_row_and_turns_back_in_the_same_order() { + let mut s = board(); + let (root, kids, lines) = map(&mut s); + let grandchild = add(&mut s, kids[0], "child"); + let root_box = bx(&s, root); + layout(&mut s, grandchild, "down"); + assert_eq!(mind_sides(s.doc().unwrap(), kids[2]), Some(MindSides::Down)); + assert_eq!(bx(&s, root), root_box, "the first node stays"); + assert!(kids.iter().all(|k| below(&s, *k, root)) && below(&s, grandchild, kids[0])); + assert!(left_to_right(&s, &kids), "top to bottom became left to right"); + assert!(lines.iter().all(|l| connector(&s, *l).routing == Routing::Elbow), "reporting lines"); + // A sibling of the first child lands between it and the second; a child of the first node at the end. + let sibling = add(&mut s, kids[0], "sibling"); + let last = add(&mut s, root, "child"); + assert!(below(&s, sibling, root) && below(&s, last, root)); + assert!(left_to_right(&s, &[kids[0], sibling, kids[1], kids[2], last])); + // Back to the right: the row becomes a column in the same order, with curves again. + layout(&mut s, root, "right"); + assert!(top_to_bottom(&s, &[kids[0], sibling, kids[1], kids[2], last])); + assert!(kids.iter().all(|k| bx(&s, root).x1 < bx(&s, *k).x0)); + assert!(lines.iter().all(|l| connector(&s, *l).routing == Routing::Curved)); +} + +#[test] +fn a_two_sided_map_becomes_a_row_of_its_right_side_then_its_left_and_undo_turns_it_back() { + let mut s = board(); + let (root, kids, _) = map(&mut s); + layout(&mut s, root, "both"); + let depth = s.undo_depth().0; + layout(&mut s, root, "down"); + assert_eq!(s.undo_depth().0, depth + 1, "one undo step"); + assert!(left_to_right(&s, &kids)); + s.execute("edit.undo", &json!({})).unwrap(); + assert_eq!(mind_sides(s.doc().unwrap(), root), Some(MindSides::Both)); + // From the chart to both sides: the first half of the row on the right, the rest on the left. + s.execute("edit.redo", &json!({})).unwrap(); + layout(&mut s, root, "both"); + assert!(bx(&s, root).x1 < bx(&s, kids[0]).x0 && bx(&s, root).x1 < bx(&s, kids[1]).x0); + assert!(bx(&s, kids[2]).x1 < bx(&s, root).x0); + assert!(top_to_bottom(&s, &kids[..2])); +} diff --git a/crates/engine/src/board_mindmap_sides_tests.rs b/crates/engine/src/board_mindmap_sides_tests.rs index 9749a88f1..82a9eddbc 100644 --- a/crates/engine/src/board_mindmap_sides_tests.rs +++ b/crates/engine/src/board_mindmap_sides_tests.rs @@ -67,7 +67,7 @@ fn a_map_on_both_sides_splits_its_first_nodes_children_and_new_ones_fill_the_sho fn a_layout_needs_a_mind_map_node_and_a_known_side() { let mut s = board(); let (root, _, lines) = map(&mut s); - assert!(s.execute("board.mindMapLayout", &json!({"id": root, "layout": "down"})).is_err()); + assert!(s.execute("board.mindMapLayout", &json!({"id": root, "layout": "up"})).is_err()); assert!(s.execute("board.mindMapLayout", &json!({"id": root})).is_err()); assert!(s.execute("board.mindMapLayout", &json!({"id": lines[0], "layout": "left"})).is_err()); assert_eq!(mind_sides(s.doc().unwrap(), lines[0]), None); diff --git a/crates/engine/src/boards/board.rs b/crates/engine/src/boards/board.rs index 0a6cd4dfa..b7e021bc7 100644 --- a/crates/engine/src/boards/board.rs +++ b/crates/engine/src/boards/board.rs @@ -267,7 +267,7 @@ pub fn specs() -> Vec<CommandSpec> { spec!( "board.mindMapLayout", "Mind map layout", - "{id? (a mind map node; default the selected or edited one), layout: right|left|both} → {id (the map's first node), layout} the sides of the first node its map grows on: on both, the first half of its children (right ones then left ones, top to bottom) go on the right and the rest on the left; every node keeps its parent and the map lays itself out again", + "{id? (a mind map node; default the selected or edited one), layout: right|left|both|down} → {id (the map's first node), layout} the sides of the first node its map grows on, or down from it as an org chart with right-angled lines: on both, the first half of its children (right ones then left ones, top to bottom) go on the right and the rest on the left; every node keeps its parent and its place among its siblings, and the map lays itself out again", true, mindmap::mind_map_layout ), diff --git a/crates/engine/src/boards/board/mindmap.rs b/crates/engine/src/boards/board/mindmap.rs index bec798f2e..4abb7ebf6 100644 --- a/crates/engine/src/boards/board/mindmap.rs +++ b/crates/engine/src/boards/board/mindmap.rs @@ -8,7 +8,7 @@ use std::collections::{BTreeMap, BTreeSet}; use figcraft_color::{Color, Paint}; use figcraft_doc::{ AutoLayout, BoardItem, Connector, Document, End, LetterSpacing, LineHeight, MIND_GAP_X, MIND_GAP_Y, MIND_MAX_DEPTH, MIND_MAX_NODES, MindBox, - NodeId, NodeKind, Routing, Side, Sizing, StrokeCap, TextAlignH, TextAutoResize, mind_layout, + NodeId, NodeKind, Routing, Side, Sizing, StrokeCap, TextAlignH, TextAutoResize, mind_layout, mind_layout_down, }; use figcraft_geom::{Affine, Point, Rect}; use serde_json::{Value, json}; @@ -74,19 +74,43 @@ fn make_node(doc: &mut Document, parent: NodeId, at: (f64, f64), text: &str, roo Ok((frame, label)) } -/// The sides a branch leaves its parent from and arrives at its child on (left of the parent when -/// `left`). -fn sides(left: bool) -> (Side, Side) { - if left { (Side::Left, Side::Right) } else { (Side::Right, Side::Left) } +/// The way a branch grows from its parent: right, left, or down in an org chart. +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +enum Grow { + Right, + Left, + Down, } -/// The branch from `parent` to `child` (on its left side when `left`), on `page`. -fn branch(doc: &mut Document, page: NodeId, parent: NodeId, child: NodeId, left: bool) -> Result<NodeId> { - let (out, back) = sides(left); +impl Grow { + /// The sides a branch leaves its parent from and arrives at its child on. + fn sides(self) -> (Side, Side) { + match self { + Grow::Right => (Side::Right, Side::Left), + Grow::Left => (Side::Left, Side::Right), + Grow::Down => (Side::Bottom, Side::Top), + } + } + + /// Its line: an org chart's are right-angled reporting lines, the others curves. + fn routing(self) -> Routing { + if self == Grow::Down { Routing::Elbow } else { Routing::Curved } + } + + /// What orders siblings growing this way: their left edges in an org chart (as + /// [`mind_layout_down`] does), their middles' heights on the sides. + fn key(self, r: Rect) -> f64 { + if self == Grow::Down { r.x0 } else { r.center().y } + } +} + +/// The branch from `parent` to `child` growing `grow`, on `page`. +fn branch(doc: &mut Document, page: NodeId, parent: NodeId, child: NodeId, grow: Grow) -> Result<NodeId> { + let (out, back) = grow.sides(); let c = Connector { from: End::Node { node: parent, side: out, at: None }, to: End::Node { node: child, side: back, at: None }, - routing: Routing::Curved, + routing: grow.routing(), path: None, branch: true, }; @@ -103,7 +127,7 @@ struct Branch { line: NodeId, parent: NodeId, child: NodeId, - left: bool, + grow: Grow, } /// The branches of `doc` that join two different layers of their own page, by id. (Others are @@ -115,7 +139,12 @@ fn branches(doc: &Document) -> Vec<Branch> { Some(BoardItem::Connector(Connector { from: End::Node { node: a, side, .. }, to: End::Node { node: b, .. }, branch: true, .. })) if a != b && doc.contains(*a) && doc.contains(*b) && doc.page_of(*a) == doc.page_of(n.id) && doc.page_of(*b) == doc.page_of(n.id) => { - Some(Branch { line: n.id, parent: *a, child: *b, left: *side == Side::Left }) + let grow = match side { + Side::Left => Grow::Left, + Side::Bottom => Grow::Down, + _ => Grow::Right, + }; + Some(Branch { line: n.id, parent: *a, child: *b, grow }) } _ => None, }) @@ -129,48 +158,57 @@ fn arriving(bs: &[Branch], node: NodeId) -> Option<Branch> { bs.iter().find(|b| b.child == node).copied() } -/// The children of `node` on one side, in layout order (by their middles, then id). -fn map_children(doc: &Document, bs: &[Branch], node: NodeId, left: bool) -> Vec<NodeId> { +/// The children of `node` growing `grow`, in layout order (by [`Grow::key`], then id). +fn map_children(doc: &Document, bs: &[Branch], node: NodeId, grow: Grow) -> Vec<NodeId> { let mut v: Vec<(f64, NodeId)> = bs .iter() - .filter(|b| b.parent == node && b.left == left && arriving(bs, b.child).is_some_and(|a| a.line == b.line)) - .filter_map(|b| doc.world_bounds(b.child).map(|r| (r.center().y, b.child))) + .filter(|b| b.parent == node && b.grow == grow && arriving(bs, b.child).is_some_and(|a| a.line == b.line)) + .filter_map(|b| doc.world_bounds(b.child).map(|r| (grow.key(r), b.child))) .collect(); v.sort_by(|a, b| a.0.total_cmp(&b.0).then(a.1.cmp(&b.1))); v.into_iter().map(|p| p.1).collect() } -/// Whether `node` is on the left of its map (a first node: no). -fn map_side(bs: &[Branch], node: NodeId) -> bool { - let (mut at, mut left) = (node, false); +/// The way `node`'s part of its map grows: the way of the first node's branch above it (a first +/// node: right). +fn map_side(bs: &[Branch], node: NodeId) -> Grow { + let (mut at, mut grow) = (node, Grow::Right); for _ in 0..MIND_MAX_DEPTH { let Some(b) = arriving(bs, at) else { break }; - (at, left) = (b.parent, b.left); + (at, grow) = (b.parent, b.grow); } - left + grow } -/// The side a new child of `node` goes on: its own side, or for a first node the side its map -/// grows on (with branches on both sides, the side with fewer of them; the right on a tie). -fn child_side(bs: &[Branch], node: NodeId) -> bool { +/// The way a new child of `node` grows: its own part's way, or for a first node its map's (down in +/// an org chart; with branches on both sides, the side with fewer of them; the right on a tie). +fn child_side(bs: &[Branch], node: NodeId) -> Grow { if arriving(bs, node).is_some() { return map_side(bs, node); } - let count = |left: bool| bs.iter().filter(|b| b.parent == node && b.left == left).count(); - let (right, left) = (count(false), count(true)); - left > 0 && (right == 0 || left < right) + let count = |grow: Grow| bs.iter().filter(|b| b.parent == node && b.grow == grow).count(); + let (right, left) = (count(Grow::Right), count(Grow::Left)); + if count(Grow::Down) > 0 { + Grow::Down + } else if left > 0 && (right == 0 || left < right) { + Grow::Left + } else { + Grow::Right + } } -/// Which sides of its first node a mind map grows on (`board.mindMapLayout`). +/// Which sides of its first node a mind map grows on, or down from it as an org chart +/// (`board.mindMapLayout`). #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub enum MindSides { Right, Left, Both, + Down, } impl MindSides { - pub const ALL: [MindSides; 3] = [MindSides::Right, MindSides::Left, MindSides::Both]; + pub const ALL: [MindSides; 4] = [MindSides::Right, MindSides::Left, MindSides::Both, MindSides::Down]; /// Its name in commands. pub fn id(self) -> &'static str { @@ -178,6 +216,7 @@ impl MindSides { MindSides::Right => "right", MindSides::Left => "left", MindSides::Both => "both", + MindSides::Down => "down", } } @@ -187,6 +226,7 @@ impl MindSides { MindSides::Right => "Right", MindSides::Left => "Left", MindSides::Both => "Both sides", + MindSides::Down => "Org chart", } } @@ -212,23 +252,32 @@ pub fn mind_sides(doc: &Document, node: NodeId) -> Option<MindSides> { return None; } let bs = branches(doc); - let root = map_root(&bs, node); - let on = |left: bool| !map_children(doc, &bs, root, left).is_empty(); - Some(match (on(false), on(true)) { + Some(map_sides(doc, &bs, map_root(&bs, node))) +} + +/// The sides the map of first node `root` grows on. +fn map_sides(doc: &Document, bs: &[Branch], root: NodeId) -> MindSides { + let on = |grow: Grow| !map_children(doc, bs, root, grow).is_empty(); + if on(Grow::Down) { + return MindSides::Down; + } + match (on(Grow::Right), on(Grow::Left)) { (_, false) => MindSides::Right, (false, true) => MindSides::Left, (true, true) => MindSides::Both, - }) + } } -/// `board.mindMapLayout`: the first node's children, right ones then left ones, each top to -/// bottom, go on the sides asked for (on both, the first half on the right), and every branch -/// under each follows its side; the normalize pass lays the map out again. +/// `board.mindMapLayout`: the first node's children, right ones then left ones (each top to +/// bottom) then those below it (left to right), go the way asked (on both sides, the first half on +/// the right), and every branch under each follows its way; the normalize pass lays the map out +/// again. A turn between columns and an org chart's rows also turns the branches into reporting +/// lines or back into curves, and lays the map out at once in its old order. pub(super) fn mind_map_layout(s: &mut Session, p: &Value) -> Result<Value> { let cmd = "board.mindMapLayout"; require(s, cmd)?; - let layout = string(p, "layout").ok_or_else(|| bad(cmd, "`layout` is right, left or both"))?; - let sides_asked = MindSides::parse(&layout).ok_or_else(|| bad(cmd, format!("`layout` is right, left or both, not `{layout}`")))?; + let layout = string(p, "layout").ok_or_else(|| bad(cmd, "`layout` is right, left, both or down"))?; + let asked = MindSides::parse(&layout).ok_or_else(|| bad(cmd, format!("`layout` is right, left, both or down, not `{layout}`")))?; let doc = s.doc()?; let from = id(p, "id").or_else(|| target(s)).ok_or_else(|| EngineError::Disabled(cmd.into(), "select a mind map node first".into()))?; if doc.get(from)?.board != Some(BoardItem::MindNode) { @@ -236,36 +285,84 @@ pub(super) fn mind_map_layout(s: &mut Session, p: &Value) -> Result<Value> { } let bs = branches(doc); let root = map_root(&bs, from); - let firsts: Vec<NodeId> = [false, true].into_iter().flat_map(|left| map_children(doc, &bs, root, left)).collect(); + let was = map_sides(doc, &bs, root); + let turn = (was == MindSides::Down) != (asked == MindSides::Down); + let firsts: Vec<NodeId> = [Grow::Right, Grow::Left, Grow::Down].into_iter().flat_map(|g| map_children(doc, &bs, root, g)).collect(); let half = firsts.len().div_ceil(2); let (_, kids) = children_of(&bs); - // Every branch under each of the first node's children, with the side it goes on. - let (mut lines, mut seen) = (Vec::new(), BTreeSet::from([root])); + let old = if was == MindSides::Down { Grow::Down } else { Grow::Right }; + // Every branch under each of the first node's children with the way it grows, and every + // node's place among its siblings. + let (mut lines, mut rank, mut seen) = (Vec::new(), BTreeMap::new(), BTreeSet::from([root])); for (i, first) in firsts.iter().enumerate() { - let left = match sides_asked { - MindSides::Right => false, - MindSides::Left => true, - MindSides::Both => i >= half, + let grow = match asked { + MindSides::Right => Grow::Right, + MindSides::Left => Grow::Left, + MindSides::Both if i >= half => Grow::Left, + MindSides::Both => Grow::Right, + MindSides::Down => Grow::Down, }; let Some(a) = arriving(&bs, *first) else { continue }; - lines.push((a.line, left)); - let mut todo = vec![*first]; - while let Some(n) = todo.pop() { - for k in kids.get(&n).into_iter().flatten().filter(|k| seen.insert(k.child)) { - lines.push((k.line, left)); - todo.push(k.child); - } + lines.push((a.line, grow)); + rank.insert(*first, i); + for (k, j) in under(doc, &kids, *first, old, &mut seen) { + lines.push((k.line, grow)); + rank.insert(k.child, j); } } let doc = s.doc_mut()?; - for (line, left) in lines { - let (out, back) = sides(left); + for (line, grow) in lines { + let (out, back) = grow.sides(); if let Some(BoardItem::Connector(c)) = doc.node_mut(line).and_then(|n| n.board.as_mut()) { set_side(&mut c.from, out); set_side(&mut c.to, back); + if turn { + set_routing(c, grow.routing()); + } } } - Ok(json!({"id": root, "layout": sides_asked.id()})) + if turn { + lay_out_ranked(doc, root, &rank); + } + Ok(json!({"id": root, "layout": asked.id()})) +} + +/// Every branch under `top` (not yet `seen`), with the child's place among its siblings in `old`'s +/// order. +fn under(doc: &Document, kids: &Children, top: NodeId, old: Grow, seen: &mut BTreeSet<NodeId>) -> Vec<(Branch, usize)> { + let key = |b: &Branch| doc.world_bounds(b.child).map_or(0.0, |r| old.key(r)); + let (mut out, mut todo) = (Vec::new(), vec![top]); + while let Some(n) = todo.pop() { + let mut next: Vec<Branch> = kids.get(&n).into_iter().flatten().filter(|k| seen.insert(k.child)).copied().collect(); + next.sort_by(|a, b| key(a).total_cmp(&key(b)).then(a.child.cmp(&b.child))); + todo.extend(next.iter().map(|k| k.child)); + out.extend(next.into_iter().enumerate().map(|(j, k)| (k, j))); + } + out +} + +/// A branch's routing, dropping a hand-drawn path made for another one. +fn set_routing(c: &mut Connector, to: Routing) { + c.path = c.path.take().filter(|_| c.routing == to); + c.routing = to; +} + +/// The map under `root` laid out now with every node at its `rank` among its siblings: the +/// normalize pass orders siblings by where they are, which a turn between columns and rows +/// scrambles. Only the sizes are read from the nodes but the first. +fn lay_out_ranked(doc: &mut Document, root: NodeId, rank: &BTreeMap<NodeId, usize>) { + let bs = branches(doc); + let (_, kids) = children_of(&bs); + let Some((mut boxes, _)) = map_boxes(doc, root, &kids) else { return }; + if !layable(doc, &boxes) { + return; + } + let down = child_side(&bs, root) == Grow::Down; + for b in boxes.iter_mut().skip(1) { + let (i, size) = (rank.get(&b.id).copied().unwrap_or(0) as f64, b.rect.size()); + b.rect = if down { Rect::from_origin_size((i, 0.0), size) } else { Rect::from_center_size((0.0, i), size) }; + } + place(doc, &boxes, down); } /// `end`'s side, when it is on a layer. @@ -320,7 +417,7 @@ pub(super) fn mind_map_cmd(s: &mut Session, p: &Value) -> Result<Value> { let line = MIND_NODE_SIZE * MIND_LINE_HEIGHT / 100.0 + MIND_GAP_Y; for (i, t) in texts.iter().enumerate() { let (k, text) = make_node(doc, parent, (x + MIND_MIN_W + MIND_GAP_X, y + i as f64 * line), t, false)?; - let b = branch(doc, page, root, k, false)?; + let b = branch(doc, page, root, k, Grow::Right)?; made.push(json!({"id": k, "text": text, "connector": b})); } s.set_selection(vec![root]); @@ -352,7 +449,7 @@ pub fn mind_sibling(doc: &Document, node: NodeId, dir: i64) -> Option<NodeId> { } let bs = branches(doc); let a = arriving(&bs, node)?; - let sibs = map_children(doc, &bs, a.parent, a.left); + let sibs = map_children(doc, &bs, a.parent, a.grow); let at = sibs.iter().position(|n| *n == node)? as i64; let len = sibs.len() as i64; sibs.get((at + dir).rem_euclid(len.max(1)) as usize).copied() @@ -380,16 +477,27 @@ pub(super) fn mind_map_add(s: &mut Session, p: &Value) -> Result<Value> { let bs = branches(doc); let at = doc.world_bounds(from).ok_or_else(|| bad(cmd, "that node has no place"))?; let new_h = MIND_NODE_SIZE * MIND_LINE_HEIGHT / 100.0; - // The parent, the side, and where the new node's top-left goes on the page. - let (parent, left, top_left) = if sibling { + // The parent, the way, and where the new node's top-left goes on the page. + let (parent, grow, top_left) = if sibling { let a = arriving(&bs, from).ok_or_else(|| bad(cmd, "the first node has no siblings: add a child"))?; - // Its middle lands between this node and the next sibling, so the order puts it right after. - (a.parent, a.left, Point::new(at.x0, at.y1 + MIND_GAP_Y / 2.0 - new_h / 2.0)) + // Its key lands between this node's and the next sibling's, so the order puts it right after. + let to = if a.grow == Grow::Down { + Point::new(at.x1 + MIND_GAP_Y / 2.0, at.y0) + } else { + Point::new(at.x0, at.y1 + MIND_GAP_Y / 2.0 - new_h / 2.0) + }; + (a.parent, a.grow, to) } else { - let left = child_side(&bs, from); - let last = map_children(doc, &bs, from, left).last().and_then(|l| doc.world_bounds(*l)); - let top = last.map_or(at.center().y - new_h / 2.0, |l| l.y1 + MIND_GAP_Y); - (from, left, Point::new(if left { at.x0 - MIND_GAP_X - MIND_MIN_W } else { at.x1 + MIND_GAP_X }, top)) + let grow = child_side(&bs, from); + let last = map_children(doc, &bs, from, grow).last().and_then(|l| doc.world_bounds(*l)); + let to = match grow { + Grow::Down => Point::new(last.map_or(at.center().x - MIND_MIN_W / 2.0, |l| l.x1 + MIND_GAP_Y), at.y1 + MIND_GAP_X), + Grow::Left | Grow::Right => { + let top = last.map_or(at.center().y - new_h / 2.0, |l| l.y1 + MIND_GAP_Y); + Point::new(if grow == Grow::Left { at.x0 - MIND_GAP_X - MIND_MIN_W } else { at.x1 + MIND_GAP_X }, top) + } + }; + (from, grow, to) }; let local = doc.world_transform(container).inverse() * top_left; if !(local.x.is_finite() && local.y.is_finite()) { @@ -401,7 +509,7 @@ pub(super) fn mind_map_add(s: &mut Session, p: &Value) -> Result<Value> { } let doc = s.doc_mut()?; let (node, label) = make_node(doc, container, (local.x, local.y), &text, false)?; - let line = branch(doc, page, parent, node, left)?; + let line = branch(doc, page, parent, node, grow)?; s.set_selection(vec![node]); if boolean(p, "edit") == Some(true) { s.request_ui("board.editText", json!({"id": node})); @@ -487,10 +595,15 @@ fn regraft(doc: &mut Document, before: &Document, touched: &BTreeSet<NodeId>) -> .filter(|t| *t != id && is_node(doc, *t) && doc.page_of(*t) == page && doc.world_bounds(*t).is_some_and(|r| r.contains(mid))) .find(|t| !hangs_under(&bs, *t, id)); let Some(onto) = onto.filter(|t| *t != a.parent) else { continue }; - let (out, back) = sides(child_side(&bs, onto)); + let grow = child_side(&bs, onto); + let (out, back) = grow.sides(); if let Some(BoardItem::Connector(c)) = doc.node_mut(a.line).and_then(|n| n.board.as_mut()) { c.from = End::Node { node: onto, side: out, at: None }; c.to = End::Node { node: id, side: back, at: None }; + // Dropped between an org chart and a map that grows sideways: the new map's line. + if (a.grow == Grow::Down) != (grow == Grow::Down) { + set_routing(c, grow.routing()); + } stirred.extend([a.parent, onto, id]); } } @@ -514,7 +627,7 @@ fn map_boxes(doc: &Document, root: NodeId, kids: &Children) -> Option<(Vec<MindB if boxes.len() >= MIND_MAX_NODES { return None; } - boxes.push(MindBox { id: k.child, rect: doc.world_bounds(k.child)?, parent: Some(at), left: k.left }); + boxes.push(MindBox { id: k.child, rect: doc.world_bounds(k.child)?, parent: Some(at), left: k.grow == Grow::Left }); depths.push(depth + 1); lines.push(k.line); } @@ -562,26 +675,29 @@ pub(crate) fn settle_mind_maps(doc: &mut Document, before: &Document, touched: & let roots: Vec<NodeId> = kids.keys().copied().filter(|p| !arrived.contains(p)).collect(); for root in roots { let Some((boxes, lines)) = map_boxes(doc, root, &kids) else { continue }; - if boxes.iter().any(|b| !(b.rect.x0.is_finite() && b.rect.y0.is_finite() && b.rect.x1.is_finite() && b.rect.y1.is_finite())) { - continue; - } - // A map holding a layer and something inside it would move that layer with its own - // children: leave it as it is. - let ids: BTreeSet<NodeId> = boxes.iter().map(|b| b.id).collect(); - if boxes.iter().any(|b| doc.ancestors(b.id).iter().any(|a| ids.contains(a))) { - continue; - } let stale = boxes.iter().any(|b| stirred.contains(&b.id) || hit(doc, b.id)) || lines.iter().any(|l| hit(doc, *l)); - if !stale { - continue; + if stale && layable(doc, &boxes) { + place(doc, &boxes, child_side(&bs, root) == Grow::Down); } - let now: BTreeMap<NodeId, Rect> = boxes.iter().map(|b| (b.id, b.rect)).collect(); - for (id, to) in mind_layout(&boxes) { - let Some(was) = now.get(&id) else { continue }; - let d = to - was.origin(); - if d.x.is_finite() && d.y.is_finite() && d.hypot() > 1e-6 { - shift(doc, id, Point::new(d.x, d.y)); - } + } +} + +/// Whether a map's boxes can be laid out: all finite, and none inside another (a map holding a +/// layer and something inside it would move that layer with its own children). +fn layable(doc: &Document, boxes: &[MindBox]) -> bool { + let ids: BTreeSet<NodeId> = boxes.iter().map(|b| b.id).collect(); + boxes.iter().all(|b| [b.rect.x0, b.rect.y0, b.rect.x1, b.rect.y1].iter().all(|v| v.is_finite())) + && !boxes.iter().any(|b| doc.ancestors(b.id).iter().any(|a| ids.contains(a))) +} + +/// Every node of a map moved to where the layout puts it (an org chart's when `down`); a node in +/// place is not written to. +fn place(doc: &mut Document, boxes: &[MindBox], down: bool) { + for (id, to) in if down { mind_layout_down(boxes) } else { mind_layout(boxes) } { + let Some(was) = doc.world_bounds(id) else { continue }; + let d = to - was.origin(); + if d.x.is_finite() && d.y.is_finite() && d.hypot() > 1e-6 { + shift(doc, id, Point::new(d.x, d.y)); } } } diff --git a/crates/engine/src/lib.rs b/crates/engine/src/lib.rs index 1376f12c9..b2273eef8 100644 --- a/crates/engine/src/lib.rs +++ b/crates/engine/src/lib.rs @@ -238,6 +238,8 @@ mod board_ink_lasso_tests; #[cfg(test)] mod board_link_tests; #[cfg(test)] +mod board_mindmap_down_tests; +#[cfg(test)] mod board_mindmap_sides_tests; #[cfg(test)] mod board_mindmap_tests; diff --git a/crates/ui-egui/locales/ar.toml b/crates/ui-egui/locales/ar.toml index bc5871ab2..6fa6dae13 100644 --- a/crates/ui-egui/locales/ar.toml +++ b/crates/ui-egui/locales/ar.toml @@ -1024,6 +1024,7 @@ status = "draft — needs native review" "Open|comments" = "مفتوحة" "Options" = "الخيارات" "Orange" = "برتقالي" +"Org chart" = "مخطط تنظيمي" "Order" = "الترتيب" "Other apps may not open every .fig file exported here." = "قد لا تتمكن التطبيقات الأخرى من فتح كل ملف .fig يُصدّر هنا." "Other" = "أخرى" diff --git a/crates/ui-egui/locales/bn.toml b/crates/ui-egui/locales/bn.toml index 11ad3f86f..d210dc8fb 100644 --- a/crates/ui-egui/locales/bn.toml +++ b/crates/ui-egui/locales/bn.toml @@ -993,6 +993,7 @@ status = "draft — needs native review" "Open|comments" = "খুলুন" "Options" = "বিকল্পসমূহ" "Orange" = "কমলা" +"Org chart" = "সাংগঠনিক চার্ট" "Order" = "ক্রম" "Other apps may not open every .fig file exported here." = "অন্যান্য অ্যাপ এখানে এক্সপোর্ট করা প্রতিটি .fig ফাইল নাও খুলতে পারে।" "Other" = "অন্যান্য" diff --git a/crates/ui-egui/locales/bs.toml b/crates/ui-egui/locales/bs.toml index 3f5683311..b7009aeb0 100644 --- a/crates/ui-egui/locales/bs.toml +++ b/crates/ui-egui/locales/bs.toml @@ -1029,6 +1029,7 @@ status = "draft — needs native review" "Open|comments" = "Otvoreno" "Options" = "Opcije" "Orange" = "Narandžasta" +"Org chart" = "Organizaciona šema" "Order" = "Redoslijed" "Other apps may not open every .fig file exported here." = "Druge aplikacije možda neće otvoriti svaku .fig datoteku izvezenu ovdje." "Other" = "Ostalo" diff --git a/crates/ui-egui/locales/cs.toml b/crates/ui-egui/locales/cs.toml index a6d13a610..05fba8731 100644 --- a/crates/ui-egui/locales/cs.toml +++ b/crates/ui-egui/locales/cs.toml @@ -974,6 +974,7 @@ status = "draft — needs native review" "Open|comments" = "Otevřené" "Options" = "Možnosti" "Orange" = "Oranžová" +"Org chart" = "Organizační schéma" "Order" = "Pořadí" "Other apps may not open every .fig file exported here." = "Jiné aplikace nemusí otevřít všechny zde exportované soubory .fig." "Others lose access and keep their copy; the file stays on the server for you" = "Ostatní ztratí přístup a ponechají si svou kopii; soubor pro vás zůstane na serveru" diff --git a/crates/ui-egui/locales/de.toml b/crates/ui-egui/locales/de.toml index 0dabc0783..12499f09f 100644 --- a/crates/ui-egui/locales/de.toml +++ b/crates/ui-egui/locales/de.toml @@ -958,6 +958,7 @@ status = "draft — needs native review" "Open|comments" = "Offen" "Options" = "Optionen" "Orange" = "Orange" +"Org chart" = "Organigramm" "Other apps may not open every .fig file exported here." = "Andere Apps öffnen möglicherweise nicht jede hier exportierte .fig-Datei." "Others lose access and keep their copy; the file stays on the server for you" = "Die anderen verlieren den Zugriff und behalten ihre Kopie; die Datei bleibt für Sie auf dem Server" "Others type this under Share ▸ Join with a code" = "Die anderen geben ihn unter Teilen ▸ Mit einem Code beitreten ein" diff --git a/crates/ui-egui/locales/en.toml b/crates/ui-egui/locales/en.toml index f44897dc1..b93653a06 100644 --- a/crates/ui-egui/locales/en.toml +++ b/crates/ui-egui/locales/en.toml @@ -1143,6 +1143,7 @@ name = "English" "Open|comments" = "Open" "Options" = "Options" "Orange" = "Orange" +"Org chart" = "Org chart" "Order" = "Order" "Other apps may not open every .fig file exported here." = "Other apps may not open every .fig file exported here." "Other" = "Other" diff --git a/crates/ui-egui/locales/es.toml b/crates/ui-egui/locales/es.toml index ae0c8991c..1ebdff36e 100644 --- a/crates/ui-egui/locales/es.toml +++ b/crates/ui-egui/locales/es.toml @@ -1025,6 +1025,7 @@ status = "draft — needs native review" "Open|comments" = "Abiertos" "Options" = "Opciones" "Orange" = "Naranja" +"Org chart" = "Organigrama" "Order" = "Orden" "Other apps may not open every .fig file exported here." = "Puede que otras aplicaciones no abran todos los archivos .fig exportados aquí." "Other" = "Otros" diff --git a/crates/ui-egui/locales/fi.toml b/crates/ui-egui/locales/fi.toml index 288438a96..00971dbfe 100644 --- a/crates/ui-egui/locales/fi.toml +++ b/crates/ui-egui/locales/fi.toml @@ -1098,6 +1098,7 @@ status = "draft — needs native review" "Open|comments" = "Avoin" "Options" = "Asetukset" "Orange" = "Oranssi" +"Org chart" = "Organisaatiokaavio" "Order" = "Järjestys" "Other" = "Muu" "Other apps may not open every .fig file exported here." = "Muut sovellukset eivät välttämättä avaa kaikkia tässä vietyjä .fig-tiedostoja." diff --git a/crates/ui-egui/locales/fr.toml b/crates/ui-egui/locales/fr.toml index 54b5ae7ff..f6afd2a8b 100644 --- a/crates/ui-egui/locales/fr.toml +++ b/crates/ui-egui/locales/fr.toml @@ -995,6 +995,7 @@ status = "draft — needs native review" "Open|comments" = "Ouverts" "Options" = "Options" "Orange" = "Orange" +"Org chart" = "Organigramme" "Order" = "Ordre" "Other" = "Autre" "Other apps may not open every .fig file exported here." = "D’autres applications risquent de ne pas ouvrir tous les fichiers .fig exportés ici." diff --git a/crates/ui-egui/locales/he.toml b/crates/ui-egui/locales/he.toml index 71425069a..3bac89dea 100644 --- a/crates/ui-egui/locales/he.toml +++ b/crates/ui-egui/locales/he.toml @@ -1114,6 +1114,7 @@ Open = "פתיחה" "Open|comments" = "פתוחות" "Options" = "אפשרויות" "Orange" = "כתום" +"Org chart" = "תרשים ארגוני" "Order" = "סדר" "Other" = "אחר" "Other apps may not open every .fig file exported here." = "יישומים אחרים עשויים שלא לפתוח כל קובץ .fig המיוצא מכאן." diff --git a/crates/ui-egui/locales/id.toml b/crates/ui-egui/locales/id.toml index c6d16bc4f..0ef30d2e2 100644 --- a/crates/ui-egui/locales/id.toml +++ b/crates/ui-egui/locales/id.toml @@ -981,6 +981,7 @@ status = "draft — needs native review" "Open|comments" = "Terbuka" "Options" = "Opsi" "Orange" = "Oranye" +"Org chart" = "Bagan organisasi" "Order" = "Urutan" "Other apps may not open every .fig file exported here." = "Aplikasi lain mungkin tidak dapat membuka setiap file .fig yang diekspor di sini." "Others lose access and keep their copy; the file stays on the server for you" = "Orang lain kehilangan akses tetapi tetap memiliki salinannya; file tetap di server untuk Anda" diff --git a/crates/ui-egui/locales/it.toml b/crates/ui-egui/locales/it.toml index 9d74fe81e..d182b3724 100644 --- a/crates/ui-egui/locales/it.toml +++ b/crates/ui-egui/locales/it.toml @@ -1241,6 +1241,7 @@ status = "draft — needs native review" "Open|comments" = "Aperti" "Options" = "Opzioni" "Orange" = "Arancione" +"Org chart" = "Organigramma" "Order" = "Ordine" "Other apps may not open every .fig file exported here." = "Altre app potrebbero non aprire tutti i file .fig esportati qui." "Other" = "Altro" diff --git a/crates/ui-egui/locales/ja.toml b/crates/ui-egui/locales/ja.toml index f97ace1e8..8e55e625f 100644 --- a/crates/ui-egui/locales/ja.toml +++ b/crates/ui-egui/locales/ja.toml @@ -986,6 +986,7 @@ status = "draft — needs native review" "Open|comments" = "未解決" "Options" = "オプション" "Orange" = "オレンジ" +"Org chart" = "組織図" "Order" = "並び順" "Other apps may not open every .fig file exported here." = "ここで書き出した .fig ファイルは、他のアプリで開けない場合がある。" "Others lose access and keep their copy; the file stays on the server for you" = "他の人はアクセスできなくなり、各自のコピーは残る。ファイルはあなた用にサーバーに残る" diff --git a/crates/ui-egui/locales/ka.toml b/crates/ui-egui/locales/ka.toml index 476c08f3c..e8be4a0ef 100644 --- a/crates/ui-egui/locales/ka.toml +++ b/crates/ui-egui/locales/ka.toml @@ -1086,6 +1086,7 @@ status = "draft — reviewed by a native speaker, awaiting a maintainer's approv "Open|comments" = "გახსნა" "Options" = "პარამეტრები" "Orange" = "ნარინჯისფერი" +"Org chart" = "ორგანიზაციული სქემა" "Order" = "რიგი" "Other apps may not open every .fig file exported here." = "სხვა აპებმა შეიძლება ვერ გახსნან აქ ექსპორტირებული ყველა .fig ფაილი." "Other" = "სხვა" diff --git a/crates/ui-egui/locales/ko.toml b/crates/ui-egui/locales/ko.toml index c33893361..d8fb486de 100644 --- a/crates/ui-egui/locales/ko.toml +++ b/crates/ui-egui/locales/ko.toml @@ -941,6 +941,7 @@ status = "draft — needs native review" "Open|comments" = "미해결" "Options" = "옵션" "Orange" = "주황" +"Org chart" = "조직도" "Other apps may not open every .fig file exported here." = "여기서 내보낸 .fig 파일을 다른 앱에서 모두 열 수 있는 것은 아님." "Others lose access and keep their copy; the file stays on the server for you" = "다른 사람들은 접근 권한을 잃고 각자의 사본을 유지함. 파일은 나를 위해 서버에 남음" "Others type this under Share ▸ Join with a code" = "다른 사람들이 공유 ▸ 코드로 참여에서 이 코드를 입력" diff --git a/crates/ui-egui/locales/nl.toml b/crates/ui-egui/locales/nl.toml index 4bde50c13..55fff6fb5 100644 --- a/crates/ui-egui/locales/nl.toml +++ b/crates/ui-egui/locales/nl.toml @@ -996,6 +996,7 @@ status = "draft — needs native review" "Open|comments" = "Open" "Options" = "Opties" "Orange" = "Oranje" +"Org chart" = "Organogram" "Order" = "Volgorde" "Other" = "Overige" "Other apps may not open every .fig file exported here." = "Het kan zijn dat andere apps niet elk .fig-bestand openen dat hier wordt geëxporteerd." diff --git a/crates/ui-egui/locales/pl.toml b/crates/ui-egui/locales/pl.toml index 18082cd2c..d0c749d89 100644 --- a/crates/ui-egui/locales/pl.toml +++ b/crates/ui-egui/locales/pl.toml @@ -999,6 +999,7 @@ name = "Polski" "Open|comments" = "Otwarte" "Options" = "Opcje" "Orange" = "Pomarańczowy" +"Org chart" = "Schemat organizacyjny" "Order" = "Kolejność" "Other apps may not open every .fig file exported here." = "Inne aplikacje mogą nie otworzyć każdego pliku .fig wyeksportowanego tutaj." "Other" = "Inne" diff --git a/crates/ui-egui/locales/pt-BR.toml b/crates/ui-egui/locales/pt-BR.toml index 09a565c65..8392baca7 100644 --- a/crates/ui-egui/locales/pt-BR.toml +++ b/crates/ui-egui/locales/pt-BR.toml @@ -940,6 +940,7 @@ status = "draft — needs native review" "Open|comments" = "Abertos" "Options" = "Opções" "Orange" = "Laranja" +"Org chart" = "Organograma" "Other apps may not open every .fig file exported here." = "Outros aplicativos podem não abrir todos os arquivos .fig exportados aqui." "Others lose access and keep their copy; the file stays on the server for you" = "Os outros perdem o acesso e ficam com a própria cópia; o arquivo continua no servidor para você" "Others type this under Share ▸ Join with a code" = "Os outros digitam isto em Compartilhar ▸ Entrar com um código" diff --git a/crates/ui-egui/locales/ru.toml b/crates/ui-egui/locales/ru.toml index 620b23155..2e1c2dde4 100644 --- a/crates/ui-egui/locales/ru.toml +++ b/crates/ui-egui/locales/ru.toml @@ -1000,6 +1000,7 @@ name = "Русский" "Open|comments" = "Открытые" "Options" = "Параметры" "Orange" = "Оранжевый" +"Org chart" = "Оргструктура" "Order" = "Порядок" "Other" = "Другое" "Other apps may not open every .fig file exported here." = "Другие приложения могут открыть не каждый экспортированный здесь файл .fig." diff --git a/crates/ui-egui/locales/sv.toml b/crates/ui-egui/locales/sv.toml index 5785880c2..eadfcced0 100644 --- a/crates/ui-egui/locales/sv.toml +++ b/crates/ui-egui/locales/sv.toml @@ -1123,6 +1123,7 @@ name = "Svenska" "Open|comments" = "Öppna" "Options" = "Alternativ" "Orange" = "Orange" +"Org chart" = "Organisationsschema" "Order" = "Ordning" "Other apps may not open every .fig file exported here." = "Andra appar kanske inte kan öppna alla .fig-filer som exporteras här." "Other" = "Annat" diff --git a/crates/ui-egui/locales/ta.toml b/crates/ui-egui/locales/ta.toml index 73c89d9af..87a245b40 100644 --- a/crates/ui-egui/locales/ta.toml +++ b/crates/ui-egui/locales/ta.toml @@ -1071,6 +1071,7 @@ status = "draft — needs native review" "Open|comments" = "திறந்தவை" "Options" = "விருப்பங்கள்" "Orange" = "ஆரஞ்சு" +"Org chart" = "நிறுவன விளக்கப்படம்" "Order" = "வரிசை" "Other" = "பிற" "Other apps may not open every .fig file exported here." = "இங்கே ஏற்றுமதி செய்யப்படும் ஒவ்வொரு .fig கோப்பையும் பிற ஆப்கள் திறக்காமல் போகலாம்." diff --git a/crates/ui-egui/locales/th.toml b/crates/ui-egui/locales/th.toml index 8b63a9653..f1911b854 100644 --- a/crates/ui-egui/locales/th.toml +++ b/crates/ui-egui/locales/th.toml @@ -991,6 +991,7 @@ status = "draft — needs native review" "Open|comments" = "ยังเปิดอยู่" "Options" = "ตัวเลือก" "Orange" = "ส้ม" +"Org chart" = "แผนผังองค์กร" "Order" = "ลำดับ" "Other apps may not open every .fig file exported here." = "แอปอื่นอาจเปิดไฟล์ .fig ที่ส่งออกจากที่นี่ได้ไม่ครบทุกไฟล์" "Other" = "อื่นๆ" diff --git a/crates/ui-egui/locales/tr.toml b/crates/ui-egui/locales/tr.toml index 55a8b07b1..5ec4317f2 100644 --- a/crates/ui-egui/locales/tr.toml +++ b/crates/ui-egui/locales/tr.toml @@ -979,6 +979,7 @@ name = "Türkçe" "Open|comments" = "Açık" "Options" = "Seçenekler" "Orange" = "Turuncu" +"Org chart" = "Organizasyon şeması" "Order" = "Sıra" "Other apps may not open every .fig file exported here." = "Diğer uygulamalar burada dışa aktarılan her .fig dosyasını açamayabilir." "Others lose access and keep their copy; the file stays on the server for you" = "Diğerleri erişimini kaybeder ve kopyalarını saklar; dosya sizin için sunucuda kalır" diff --git a/crates/ui-egui/locales/vi.toml b/crates/ui-egui/locales/vi.toml index 5cb9ee4a1..cace066a3 100644 --- a/crates/ui-egui/locales/vi.toml +++ b/crates/ui-egui/locales/vi.toml @@ -965,6 +965,7 @@ status = "draft — needs native review" "Open|comments" = "Đang mở" "Options" = "Tùy chọn" "Orange" = "Cam" +"Org chart" = "Sơ đồ tổ chức" "Order" = "Thứ tự" "Other" = "Khác" "Other apps may not open every .fig file exported here." = "Các ứng dụng khác có thể không mở được mọi tệp .fig xuất từ đây." diff --git a/crates/ui-egui/locales/zh-Hans.toml b/crates/ui-egui/locales/zh-Hans.toml index 9f3622dc3..f1a6c2375 100644 --- a/crates/ui-egui/locales/zh-Hans.toml +++ b/crates/ui-egui/locales/zh-Hans.toml @@ -946,6 +946,7 @@ status = "draft — needs native review" "Open|comments" = "未解决" "Options" = "选项" "Orange" = "橙" +"Org chart" = "组织结构图" "Other apps may not open every .fig file exported here." = "其他应用不一定能打开此处导出的所有 .fig 文件。" "Others lose access and keep their copy; the file stays on the server for you" = "其他人将失去访问权限并保留各自的副本;文件仍为你保留在服务器上" "Others type this under Share ▸ Join with a code" = "其他人在“分享 ▸ 用代码加入”中输入它" diff --git a/crates/ui-egui/locales/zh-Hant.toml b/crates/ui-egui/locales/zh-Hant.toml index c04278b7c..4ba1f70e2 100644 --- a/crates/ui-egui/locales/zh-Hant.toml +++ b/crates/ui-egui/locales/zh-Hant.toml @@ -1059,6 +1059,7 @@ status = "draft — needs native review" "Open|comments" = "未解決" "Options" = "選項" "Orange" = "橘色" +"Org chart" = "組織圖" "Order" = "順序" "Other" = "其他" "Other apps may not open every .fig file exported here." = "其他應用程式可能無法開啟此處匯出的每個 .fig 檔案。" diff --git a/docs/boards-parity.md b/docs/boards-parity.md index 8d239877e..bf2278902 100644 --- a/docs/boards-parity.md +++ b/docs/boards-parity.md @@ -1,6 +1,6 @@ # Boards parity -> **Last reviewed:** 2026-10-24 · **Last updated:** 2026-12-01 · **Change:** minor (a mind map grows right, left or on both sides of its first node, chosen in the Layout menu of the bar over a node (`board.mindMapLayout`, #2642); a `.jam` file's connectors come in as native board connectors attached to the layers they join (#1808); the Pencil, Marker, Highlighter and Eraser show a round tip at the pointer, in the ink's colour and as wide as the stroke (#2641); code blocks from the toolbar's Text tools flyout or the `` ` `` key, a language menu in the bar over a selected block, and handles on a block's left and right edges only (#2237); a mind map node dropped on another node becomes its child, with everything under it (#2226); code blocks colour keywords, strings, numbers and comments by their language (#2237); the ink colour and stroke weight of the Marker, Highlighter and Pencil are chosen before drawing, in a bar above the toolbar (#2395); mind maps from the toolbar and the keyboard: Shapes ▸ Mind map places one with a click, Cmd/Ctrl+Enter adds a child and Shift+Cmd/Ctrl+Enter a sibling, Tab goes to the next sibling (#2226); code blocks, first step: a dark panel of monospace text as tall as its lines, in one of 16 languages (`board.codeBlock`, `board.setLanguage`, #2237); a `.jam` file's shapes with text come in as native board shapes for the 23 kinds FigCraft draws, the other 7 as frames (#1808); a sticky has a text-size menu in the contextual bar, Small 16, Medium 24, Large 40, Extra large 64 and Huge 96, with Small the default (an earlier reading of 18 did not reproduce); `board.setStyle {fontSize}` sizes stickies and the sticky tool remembers the last size for new ones; the note grows taller at Huge and shrinks back, as measured in FigJam's web app, 2026-11-12; resizing a board table by height changes its rows, not blank space below them: a bottom or top edge grows the last row, a corner shares the change over every row, and a table keeps at least 40 per cell, measured in FigJam's web app, 2026-11-09 (#2172); a `.jam` file's stickies come in as native board stickies, with their colour, text and author kept and the size as saved (#1808); a sticky's text stays 18 and the note grows taller instead of the text shrinking, as measured in FigJam's web app (#2157); mind maps, first step: a first node with three children on curved branches, laid out again after every edit (`board.mindMap`, `board.mindMapAdd`, #2226); a `.jam` elbowed connector saved with its path keeps it on import instead of being routed again (#1910); a "+" handle dragged carries the preview: the next shape is made where it is let go, or a connector joins the object it is let go on (#1919); a connector attached to a side starts 4 pt outside the border, so its stroke never lies on the fill (#1916); a connector end moved with Cmd/Ctrl held goes on any part of an object, and stays there as the object moves or resizes; a connector end dropped along a side of a shape attaches to that side (#1708); a board connector's path can be reshaped by dragging its path handles (#1710); boards have 16 more shapes (arrows, polygons, star, plus and flowchart symbols), in pickers that lay them out in a grid; a board keeps earlier votes' results, listed newest first in Results and deleted one at a time; a connector's bar sets its start and end points, dashes, weight and any colour (#1596); cells copied from a spreadsheet paste onto a board as a table; Shift+Cmd/Ctrl+Enter on a selected board shape adds the next shape already joined to it, and goes on typing (#1597); "+" handles beside a selected sticky or shape make the next one, joined by a connector (#1597); a FigJam `.jam` file opens as a board (#1342); board grid settings: dots, lines, graph paper or none, spacing, size and contrast; the connector tool shows the connector it will make while dragging, ends snapping to attach points (#1387); templates and tables; facilitation: a shared timer and voting sessions; the dot grid, dragging a connector's end to re-attach it, curved connectors, elbows that go around what they join) · **Target:** the incumbent's whiteboard product (behaviour from its public help centre) +> **Last reviewed:** 2026-10-24 · **Last updated:** 2026-12-01 · **Change:** minor (a mind map turns into a top-down org chart from the Layout menu of the bar over a node (`board.mindMapLayout {layout: down}`, #2642); a mind map grows right, left or on both sides of its first node, chosen in the same menu (`board.mindMapLayout`, #2642); a `.jam` file's connectors come in as native board connectors attached to the layers they join (#1808); the Pencil, Marker, Highlighter and Eraser show a round tip at the pointer, in the ink's colour and as wide as the stroke (#2641); code blocks from the toolbar's Text tools flyout or the `` ` `` key, a language menu in the bar over a selected block, and handles on a block's left and right edges only (#2237); a mind map node dropped on another node becomes its child, with everything under it (#2226); code blocks colour keywords, strings, numbers and comments by their language (#2237); the ink colour and stroke weight of the Marker, Highlighter and Pencil are chosen before drawing, in a bar above the toolbar (#2395); mind maps from the toolbar and the keyboard: Shapes ▸ Mind map places one with a click, Cmd/Ctrl+Enter adds a child and Shift+Cmd/Ctrl+Enter a sibling, Tab goes to the next sibling (#2226); code blocks, first step: a dark panel of monospace text as tall as its lines, in one of 16 languages (`board.codeBlock`, `board.setLanguage`, #2237); a `.jam` file's shapes with text come in as native board shapes for the 23 kinds FigCraft draws, the other 7 as frames (#1808); a sticky has a text-size menu in the contextual bar, Small 16, Medium 24, Large 40, Extra large 64 and Huge 96, with Small the default (an earlier reading of 18 did not reproduce); `board.setStyle {fontSize}` sizes stickies and the sticky tool remembers the last size for new ones; the note grows taller at Huge and shrinks back, as measured in FigJam's web app, 2026-11-12; resizing a board table by height changes its rows, not blank space below them: a bottom or top edge grows the last row, a corner shares the change over every row, and a table keeps at least 40 per cell, measured in FigJam's web app, 2026-11-09 (#2172); a `.jam` file's stickies come in as native board stickies, with their colour, text and author kept and the size as saved (#1808); a sticky's text stays 18 and the note grows taller instead of the text shrinking, as measured in FigJam's web app (#2157); mind maps, first step: a first node with three children on curved branches, laid out again after every edit (`board.mindMap`, `board.mindMapAdd`, #2226); a `.jam` elbowed connector saved with its path keeps it on import instead of being routed again (#1910); a "+" handle dragged carries the preview: the next shape is made where it is let go, or a connector joins the object it is let go on (#1919); a connector attached to a side starts 4 pt outside the border, so its stroke never lies on the fill (#1916); a connector end moved with Cmd/Ctrl held goes on any part of an object, and stays there as the object moves or resizes; a connector end dropped along a side of a shape attaches to that side (#1708); a board connector's path can be reshaped by dragging its path handles (#1710); boards have 16 more shapes (arrows, polygons, star, plus and flowchart symbols), in pickers that lay them out in a grid; a board keeps earlier votes' results, listed newest first in Results and deleted one at a time; a connector's bar sets its start and end points, dashes, weight and any colour (#1596); cells copied from a spreadsheet paste onto a board as a table; Shift+Cmd/Ctrl+Enter on a selected board shape adds the next shape already joined to it, and goes on typing (#1597); "+" handles beside a selected sticky or shape make the next one, joined by a connector (#1597); a FigJam `.jam` file opens as a board (#1342); board grid settings: dots, lines, graph paper or none, spacing, size and contrast; the connector tool shows the connector it will make while dragging, ends snapping to attach points (#1387); templates and tables; facilitation: a shared timer and voting sessions; the dot grid, dragging a connector's end to re-attach it, curved connectors, elbows that go around what they join) · **Target:** the incumbent's whiteboard product (behaviour from its public help centre) **Breadth ~48%, ready ~30% (estimated, erring low).** A board is a FigCraft file of its own kind (`file.newBoard`) with a dot grid on the page, sticky notes, shapes with text, connectors that @@ -58,7 +58,7 @@ all end with the same geometry. | Board widgets | missing | design-file widgets exist (`crates/engine/src/extensions/widgets.rs`), not wired to boards | | Templates (retrospective, brainstorm, flow chart…) | partial | five built-in templates drawn up for FigCraft (retrospective, brainstorm, weekly planner, flow chart, kanban board), placed from the toolbar's templates picker (each with a picture of itself) or `board.template {name, x?, y?}` as ordinary sections, stickies, shapes, connectors and text in one undo step; `board.templates` lists them. No community templates, no saving your own | | Tables | partial | `board.table {rows, columns, cells?, x?, y?}` (at most 50 × 20): an auto layout frame of rows of cells with text, a tinted header row and lines between rows and columns; a cell's row grows with its text; each column keeps its own width; resizing a table by its bottom edge or its height grows the last row, by a side edge or its width the last column, and a corner drag shares the change equally over every row and column (also after a column was sized); dragging the border between two columns of the selected table sizes the column on its left and the table grows or shrinks with it (on a table that isn't selected the drag moves it), also `board.tableEdit {action: resizeColumn, index, size}`; the table keeps hugging its rows and columns and a cell keeps at least 40 each way (measured 2026-11-09: the reference's floor is about 52, FigCraft's is 40); a table saved with equal columns keeps its look until it is resized or edited; a double-click types in the cell under the pointer; add or remove a row or column from the bar over the selection or `board.tableEdit {id, action, index?}`; cells copied from a spreadsheet (tab-separated text, quoted cells kept whole) paste as a table, up to 50 × 20 with a note when there was more; undoable and synced in live sessions. No row resizing by dragging a row's border, no cell colours, no Tab between cells; comma-separated text pastes as text | -| Mind maps | partial | Shapes ▸ Mind map in the toolbar, then a click: a first node (bold, no box) whose text starts at the click, with three children on its right joined by curved branches, and typing starts in the first node (#2226). Cmd/Ctrl+Enter on a node, selected or being typed in, adds a child below its other children; Shift+Cmd/Ctrl+Enter adds a sibling right after it (the first node has none); both go on typing in the new node. Tab and Shift+Tab select the next and previous sibling; Enter types in the selected node. The bar over a node sets its text colour and size; over a branch its colour, start and end points, dashes and weight. From commands: `board.mindMap {x?, y?, text?, children?}`, `board.mindMapAdd {id?, relation?: child\|sibling}`, `tool.mindMap`. Nodes are text that grows wider as it is typed and taller with line breaks; a node's children stand in one column 88 units right of the widest node of its own column, 48 apart, centred on it, and the map lays itself out again in the normalize pass after every edit, undo and live-session change; moving the first node moves the map; a node dropped on another node (its middle let go on it, by a drag or a nudge) becomes that node's child with everything under it, its branch leaving the new parent, and a drop on a node under it changes nothing, nor its parent (on its own parent it lands among its siblings by its middle, as any child moved by hand does); a deleted node's children stay where they are without their branch. Branches are board connectors (`branch`: stroke 4, #757575, round caps). The bar over a node ends in a Layout menu, Right, Left or Both sides (`board.mindMapLayout {id?, layout: right|left|both}`): the map's branches change side, every node keeps its parent, on both sides the first half of the first node's children go right, and a new child of the first node goes on the map's side (the shorter side on both). No "+" handles, outline view, top-down org chart layout, branch colour themes, images on nodes, detaching a node by dragging it away or `.jam` import yet | +| Mind maps | partial | Shapes ▸ Mind map in the toolbar, then a click: a first node (bold, no box) whose text starts at the click, with three children on its right joined by curved branches, and typing starts in the first node (#2226). Cmd/Ctrl+Enter on a node, selected or being typed in, adds a child below its other children; Shift+Cmd/Ctrl+Enter adds a sibling right after it (the first node has none); both go on typing in the new node. Tab and Shift+Tab select the next and previous sibling; Enter types in the selected node. The bar over a node sets its text colour and size; over a branch its colour, start and end points, dashes and weight. From commands: `board.mindMap {x?, y?, text?, children?}`, `board.mindMapAdd {id?, relation?: child\|sibling}`, `tool.mindMap`. Nodes are text that grows wider as it is typed and taller with line breaks; a node's children stand in one column 88 units right of the widest node of its own column, 48 apart, centred on it, and the map lays itself out again in the normalize pass after every edit, undo and live-session change; moving the first node moves the map; a node dropped on another node (its middle let go on it, by a drag or a nudge) becomes that node's child with everything under it, its branch leaving the new parent, and a drop on a node under it changes nothing, nor its parent (on its own parent it lands among its siblings by its middle, as any child moved by hand does); a deleted node's children stay where they are without their branch. Branches are board connectors (`branch`: stroke 4, #757575, round caps). The bar over a node ends in a Layout menu, Right, Left, Both sides or Org chart (`board.mindMapLayout {id?, layout: right|left|both|down}`): the map's branches change side, every node keeps its parent, on both sides the first half of the first node's children go right, and a new child of the first node goes on the map's side (the shorter side on both). As an org chart every level is a row 88 below its parent, siblings side by side 48 apart in the order of their left edges with the parent centred over them, joined by right-angled lines; turning between columns and rows keeps each node's place among its siblings (top to bottom becomes left to right) and the lines become curves again; a new child goes at the right end of its row and a sibling right after the node. No "+" handles, outline view, org chart boxes, branch colour themes, images on nodes, detaching a node by dragging it away or `.jam` import yet | | Code blocks | partial | #2237: the toolbar's Text tools flyout ends in Code block (`tool.codeBlock`, also the `` ` `` key, boards only), and a click then places a block centred there and starts typing in it, back on the Move tool after; `board.codeBlock {x?, y?, language?, text?, width?}` places one by command. A block is a dark panel holding monospace text (Liberation Mono 16 on a 24 line where it is embedded or installed), 576 wide; its height is its lines (32 + 24 a line, wrapped lines counted, never under four lines) and only its width can be changed (210 at least): a selected block has handles on its left and right edges only, and a press on a corner or the top or bottom edge moves it; the bar over a selected block ends in a language menu, the block's language checked, and `board.setLanguage {id?, language}` keeps one of 16 languages (TypeScript by default); `board.nextSticky` on a block makes the next one 128 to its right, as wide and in the same language. In a block Tab types two spaces, Enter keeps the line's indent, and lists, links and styled ranges don't apply. The code is coloured as its language writes it: keywords, strings, numbers and comments each in a colour of FigCraft's own (each at least 4.5:1 on the panel), kept on the text's runs by the normalize pass, so the canvas and PNG, SVG and PDF exports show the same, and a language change or an edit colours it again (`board::code_tokens`, a small tokenizer per language; a quoted string ends with its line, plain text stays uncoloured). No line-number gutter or `.jam` import yet | | Link cards | partial | #2205: a web address pasted on a board (one `http` or `https` address, nothing around it) becomes a link card at once: a white card with the address as its title and the site under it (`board.link {url, x?, y?}`); then the desktop app reads the page in the background (10 seconds at most, 4 MB at most, no cookies) and shows the title, site name and picture its head names (its sharing tags, else its `<title>`; `board.linkPreview {id?}`). Offline, in the browser build or when the page can't be read the card stays as it was and a note says why. The bar over one selected card has Open link (`board.openLink`). No embedded players, no description line, no refresh of a card's preview from the UI | | Washi tape, image cropping on boards | missing | images can be placed as in design files | @@ -73,6 +73,7 @@ all end with the same geometry. |---|---|---| | 2026-12-01 | minor | M12, #2176: board tables had no per-column widths: every cell filled its row, so a drag of the right edge split the change equally where the reference grows only the last column, and a column couldn't be sized on its own. Each cell is now fixed at its column's width and the rows and the table hug them; column lines sit on the borders. `board_table::settle_resize` puts a width change into the last column (a corner drag shares it over every column), and a press on the border between two columns of the selected table drags that border: the column on its left takes the change and the table grows or shrinks with it, in one undo step through `board.tableEdit {action: resizeColumn, index, size}`. New rows and columns take the table's widths (a new column 160 wide); a table saved with equal columns keeps its look and takes those widths as its own when it is resized or edited. Supersedes #1736's sizing part. Not done: row borders, the lock-proportions control (still shown). Numbers unchanged. Tests: `board_table_columns_tests`. | | 2026-12-01 | minor | M12, #2205: a web address pasted on a board stayed a text layer. It now becomes a link card (`BoardItem::Link`, `board.link`), filled in by a preview the desktop app reads in the background through the session's network link (`NetRequest::Web`, `board.linkPreview`): the page's title, site name and picture, or a note when it can't be read; Open link in the bar (`board.openLink`). Tests: `board_link_tests` | +| 2026-12-01 | minor | M12, #2642 (part: org chart): a mind map could not grow downward. The Layout menu of the bar over a node now has Org chart (`board.mindMapLayout {layout: down}`): every level becomes a row under its parent, joined by right-angled lines, siblings keeping their order (top to bottom becomes left to right, and back); a new child lands at the end of its row and a sibling right after its node. One undo step. | | 2026-12-01 | minor | M12, #2642 (part: map structures): a mind map could only grow right of its first node. The bar over a selected node now ends in a Layout menu, Right, Left or Both sides (`board.mindMapLayout`): the map's branches change side and it lays itself out again, every node keeping its parent and deeper nodes following their side; on both sides the first half of the first node's children (right ones, then left ones, top to bottom) go right. A new child of the first node goes on the map's side, on a two-sided map the side with fewer children, and a node dropped on the first node joins it the same way. One undo step. Not in this change: the top-down org chart, the outline view, bends kept on branches, branch colour themes and images on nodes. Tests: `board_mindmap_sides_tests` (engine), `board_mind_layout_ui_tests` (UI). | | 2026-12-01 | minor | M12, #1919: a "+" dragged to empty board made the next one of the same kind there, with no way to choose another. Let go on empty board, it now opens a picker beside the drop point (the next one's box and connector shown meanwhile): the dragged-from one's own kind first with the keyboard on it, so Enter makes what the drop made before, then every shape (the arrows move through them); a click on one makes it there, joined and ready for typing, in one undo step. Escape or a click elsewhere closes it, making nothing; the bar above the selection stays away while it is open. `board.addConnected` gains `shape` (`sticky` or a shape kind; a shape after a sticky is a new shape's size). The "Add another" entry and choosing the connector type on drop are not done. Tests: `board_connect_tests` (the drop ones), engine `board_connected_tests::the_next_one_is_of_the_kind_asked_for`. Numbers unchanged. | | 2026-12-01 | minor | M12, #1707: an elbow connector was routed only from its two ends, so it ran straight through the shapes between them (one shape joined to three stacked on its right: the lines to the second and third crossed the ones above). An elbow whose way would run through another sticky, shape, code block or table on its page now goes around it, on lines 24 units clear of the objects near it, the cheapest way by length and turns (`board_route::route_around`, a search over those lines); with nothing in the way it is the short route as before. Moving an object into an elbow's way, out of it, or deleting it re-routes the elbows near it. An object an end sits on (a section behind both) is left out, a path reshaped by hand is kept, at most 32 objects near a route are gone around, and with no way around the route is as before. Connectors leaving one side still share their first run (the issue's second point, not changed here). Tests: `board_route_around_tests` (doc and engine). Numbers unchanged. | diff --git a/docs/mcp.md b/docs/mcp.md index c4d696aa7..dcde710c9 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -731,8 +731,10 @@ one undo step and returns the ids it made: children, or a sibling right after it (the first node has none); the map lays itself out again. One undo step. With `edit: true` the app goes on typing in it. A child of the first node goes on the side its map grows on (on both sides, the side with fewer children; the right on a tie). -- `board.mindMapLayout {id?, layout: right|left|both}` → `{id, layout}`: the sides of its first node - the map of the given (or selected, or edited) node grows on (`id` in the result: the first node). +- `board.mindMapLayout {id?, layout: right|left|both|down}` → `{id, layout}`: the sides of its first + node the map of the given (or selected, or edited) node grows on, or `down` from it as an org chart + (`id` in the result: the first node). An org chart has a row per level under its parent and + right-angled lines; turning between columns and rows keeps every node's place among its siblings. On both sides the first half of the first node's children (right ones, then left ones, top to bottom) go right and the rest left; every node keeps its parent, deeper nodes follow their side, and the map lays itself out again. One undo step. The bar over a selected node has it as its