From 3e3bfc72d103d94ad3baacfb5bc1ef7928a8175a Mon Sep 17 00:00:00 2001 From: Denis Gomes <6731020+denisg0mes@users.noreply.github.com> Date: Thu, 3 Dec 2026 01:26:13 -0500 Subject: [PATCH 1/4] M4: a click on a paint's bound variable opens a picker to change it A fill or stroke whose colour is bound to a variable showed the variable's name in a chip that only had a tooltip, so changing it to another meant detaching it first or opening the section's Styles menu. The chip is now a button (a combo box for screen readers). For the only paint of its list it opens the style picker the section's Styles button opens, which lists styles and colour variables; for one of several paints it opens the variable picker for that paint, since the style picker acts on the whole list; for the page background it opens the variable picker. Neither picker marked the variable in use, so the one to change from was not shown. Both now put a check on it (and mark it selected for screen readers): the variable picker for the field it binds, the style picker for the first paint of its slot or a Selection colors row's paints. A library variable is matched by the copy this document made of it. Both also open scrolled to it, and the style picker to the style in use: with styles listed first, a variable in use sat far below the top the list opened at. The scroll is instant (an animated one would still be moving when the picker shows) and waits for the popup's shown pass, since its first pass only measures it. Tests: bound_paint_chip_tests (3), and the library variable in selection_colors_picker_tests::the_rows_styles_button_opens_the_style_picker_with_search_and_library_names. --- crates/ui-egui/src/bound_paint_chip_tests.rs | 108 ++++++++++++++++++ crates/ui-egui/src/lib.rs | 2 + crates/ui-egui/src/panels/right.rs | 4 +- crates/ui-egui/src/panels/right/paints.rs | 13 ++- crates/ui-egui/src/panels/variable_ui.rs | 101 +++++++++++++--- .../src/selection_colors_picker_tests.rs | 6 + crates/ui-egui/src/widgets/style_picker.rs | 40 ++++++- docs/ui-parity.md | 3 +- 8 files changed, 254 insertions(+), 23 deletions(-) create mode 100644 crates/ui-egui/src/bound_paint_chip_tests.rs diff --git a/crates/ui-egui/src/bound_paint_chip_tests.rs b/crates/ui-egui/src/bound_paint_chip_tests.rs new file mode 100644 index 000000000..0623126f7 --- /dev/null +++ b/crates/ui-egui/src/bound_paint_chip_tests.rs @@ -0,0 +1,108 @@ +//! A paint whose colour is bound to a variable shows the variable's name in a chip; a click on it +//! opens a picker to change it: the only paint of a list the style picker (styles and colour +//! variables), one of several the variable picker for that paint. Either marks the variable the +//! paint uses now. + +use egui::accesskit::{Role, Toggled}; +use egui::{Pos2, pos2}; +use figcraft_doc::NodeId; +use figcraft_engine::Session; +use serde_json::json; + +use crate::layers_drag_tests::Ui; + +/// A selected rectangle with `fills` solid fills, the top one bound to the colour variable +/// "text/secondary" (beside "text/primary"). +fn bound_rect(fills: usize) -> (Ui, NodeId) { + let mut s = Session::new(); + let r = NodeId(s.execute("shape.rectangle", &json!({"x": 0, "y": 0, "width": 40, "height": 40})).unwrap()["id"].as_u64().unwrap()); + for _ in 1..fills { + s.execute("fill.add", &json!({"ids": [r]})).unwrap(); + } + s.execute("variable.createCollection", &json!({"name": "Theme"})).unwrap(); + s.execute("variable.create", &json!({"collection": "Theme", "name": "text/primary", "type": "color", "value": "#000000"})).unwrap(); + let v = s.execute("variable.create", &json!({"collection": "Theme", "name": "text/secondary", "type": "color", "value": "#808080"})).unwrap(); + let key = if fills == 1 { "fill".to_string() } else { format!("fills/{}/color", fills - 1) }; + s.execute("variable.bind", &json!({"ids": [r], "field": key, "variable": v["id"]})).unwrap(); + s.execute("select.set", &json!({"ids": [r]})).unwrap(); + let mut u = Ui::new(s); + u.ctx.enable_accesskit(); + u.frame(vec![]); + (u, r) +} + +/// The middle of the chip showing the variable `name`. +fn chip(u: &mut Ui, name: &str) -> Pos2 { + u.frame(vec![]); + let out = u.frame_output(vec![]); + let nodes = out.platform_output.accesskit_update.expect("an AccessKit update").nodes; + let n = nodes + .iter() + .map(|(_, n)| n) + .find(|n| n.role() == Role::ComboBox && n.value() == Some(name)) + .unwrap_or_else(|| panic!("no chip showing {name:?}")); + let b = n.bounds().expect("bounds"); + pos2(((b.x0 + b.x1) / 2.0) as f32, ((b.y0 + b.y1) / 2.0) as f32) +} + +/// Whether the open picker's row of the variable `name` is marked as the one in use. +fn marked(u: &mut Ui, name: &str) -> bool { + let out = u.frame_output(vec![]); + let nodes = out.platform_output.accesskit_update.expect("an AccessKit update").nodes; + let row = nodes.iter().map(|(_, n)| n).find(|n| n.role() == Role::RadioButton && n.label() == Some(name)); + row.unwrap_or_else(|| panic!("no picker row {name:?}")).toggled() == Some(Toggled::True) +} + +/// The open picker's row of the variable `name` and the search field above its list, as +/// `(row top, row bottom, search bottom)`. +fn row_under_search(u: &mut Ui, name: &str) -> (f64, f64, f64) { + let out = u.frame_output(vec![]); + let nodes = out.platform_output.accesskit_update.expect("an AccessKit update").nodes; + let row = nodes.iter().map(|(_, n)| n).find(|n| n.role() == Role::RadioButton && n.label() == Some(name)).expect("the row"); + let search = nodes.iter().map(|(_, n)| n).find(|n| n.role() == Role::TextInput).expect("the search field"); + let (r, s) = (row.bounds().expect("row bounds"), search.bounds().expect("search bounds")); + (r.y0, r.y1, s.y1) +} + +fn click(u: &mut Ui, p: Pos2) { + u.button(p, true); + u.button(p, false); + u.frame(vec![]); +} + +#[test] +fn the_chip_of_the_only_fill_opens_the_style_picker() { + let (mut u, _) = bound_rect(1); + let p = chip(&mut u, "text/secondary"); + click(&mut u, p); + assert!(u.app.ui.style_picker.is_some(), "the style picker opens"); + assert!(!crate::variable_ui::picker_open(&u.ctx)); + assert!(marked(&mut u, "text/secondary"), "the variable in use is marked"); + assert!(!marked(&mut u, "text/primary")); +} + +#[test] +fn the_chip_of_one_of_several_fills_opens_the_variable_picker() { + let (mut u, r) = bound_rect(2); + let p = chip(&mut u, "text/secondary"); + click(&mut u, p); + assert!(crate::variable_ui::picker_open(&u.ctx), "the variable picker opens"); + assert!(u.app.ui.style_picker.is_none()); + assert!(!u.app.session.doc().unwrap().node(r).unwrap().bound.is_empty(), "opening it changes nothing"); + assert!(marked(&mut u, "text/secondary"), "the variable in use is marked"); + assert!(!marked(&mut u, "text/primary")); +} + +#[test] +fn the_picker_opens_scrolled_to_the_variable_in_use() { + let (mut u, _) = bound_rect(1); + for i in 0..40 { + u.app.run("style.create", json!({"type": "paint", "name": format!("Swatch {i:02}"), "value": "#00ff00"})); + } + let p = chip(&mut u, "text/secondary"); + click(&mut u, p); + u.frame(vec![]); + let (top, bottom, search) = row_under_search(&mut u, "text/secondary"); + assert!(top > search && bottom < search + 360.0, "the row in use is in view below the search field: {top}..{bottom}, search ends at {search}"); + assert!(marked(&mut u, "text/secondary")); +} diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs index 69ab1a190..b332c1de8 100644 --- a/crates/ui-egui/src/lib.rs +++ b/crates/ui-egui/src/lib.rs @@ -65,6 +65,8 @@ mod board_mind_outline_ui_tests; mod board_picker_tests; #[cfg(test)] mod board_ui_tests; +#[cfg(test)] +mod bound_paint_chip_tests; #[cfg(all(test, not(target_arch = "wasm32")))] mod chat_tests; #[cfg(test)] diff --git a/crates/ui-egui/src/panels/right.rs b/crates/ui-egui/src/panels/right.rs index 73cd63cc5..242967550 100644 --- a/crates/ui-egui/src/panels/right.rs +++ b/crates/ui-egui/src/panels/right.rs @@ -373,7 +373,9 @@ fn page_section(app: &mut FigApp, ui: &mut Ui, doc: &Document) { let (sw, opacity) = widgets::paint_field(ui, Id::unique("pagebg_swatch"), Id::unique("pagebg_a"), &p, ui.available_width(), |child, text_r| { if let Some(name) = &bound { - crate::variable_ui::paint_chip(app, child, &[page], "background", name, text_r, Id::unique("pagebg_bound")); + if crate::variable_ui::paint_chip(app, child, &[page], "background", name, text_r, Id::unique("pagebg_bound")) { + crate::variable_ui::open(child, &[page], "background", VariableType::Color, text_r.left_bottom()); + } return; } hex_area = Some(text_r); diff --git a/crates/ui-egui/src/panels/right/paints.rs b/crates/ui-egui/src/panels/right/paints.rs index 148a964f3..6cbf931c9 100644 --- a/crates/ui-egui/src/panels/right/paints.rs +++ b/crates/ui-egui/src/panels/right/paints.rs @@ -557,7 +557,18 @@ fn paint_row( match &display.kind { PaintKind::Solid { .. } if bound.is_some() => { let (key, name) = bound.clone().unwrap_or_default(); - crate::variable_ui::paint_chip(app, child, &ids, &key, &name, text_r, Id::unique(("bound_paint", fills, i))); + if crate::variable_ui::paint_chip(app, child, &ids, &key, &name, text_r, Id::unique(("bound_paint", fills, i))) { + // The only paint opens the style picker the section's Styles button does (styles + // and colour variables); one of several opens the variable picker for itself. + let only = app.session.doc().ok().is_some_and(|d| { + ids.iter().all(|id| d.node(*id).is_some_and(|n| if fills { n.fills.len() } else { n.strokes.len() } == 1)) + }); + if only { + style_picker::open(app, child, &ids, if fills { StyleSlot::Fill } else { StyleSlot::Stroke }); + } else { + crate::variable_ui::open(child, &ids, &key, VariableType::Color, text_r.left_bottom()); + } + } } PaintKind::Solid { color } => { let hex = shown.unwrap_or(*color).to_hex(); diff --git a/crates/ui-egui/src/panels/variable_ui.rs b/crates/ui-egui/src/panels/variable_ui.rs index 2febf8f1d..02e2c06f7 100644 --- a/crates/ui-egui/src/panels/variable_ui.rs +++ b/crates/ui-egui/src/panels/variable_ui.rs @@ -43,6 +43,12 @@ struct Picker { at: Pos2, } +/// Open `p` (one picker at a time), its row in use scrolled into view. +fn open_picker(ui: &Ui, p: Picker) { + ask_reveal(ui.ctx()); + ui.data_mut(|d| d.insert_temp(picker_id(), p)); +} + /// Stable egui id for the variable picker. fn picker_id() -> Id { Id::unique("variable_picker") @@ -50,12 +56,53 @@ fn picker_id() -> Id { /// The variable `field` is bound to on every one of `ids` (its name), if they agree. pub fn bound_name(doc: &Document, ids: &[NodeId], field: &str) -> Option { + bound_id(doc, ids, field).and_then(|id| doc.variables.get_by_id(&id).map(|v| v.name.clone())) +} + +/// The variable `field` is bound to on every one of `ids` (its id in this document), if they agree. +pub fn bound_id(doc: &Document, ids: &[NodeId], field: &str) -> Option { let mut it = ids.iter().map(|i| doc.node(*i).and_then(|n| n.bound.get(field)).cloned()); let first = it.next().flatten()?; - if !it.all(|v| v.as_ref() == Some(&first)) { - return None; + it.all(|v| v.as_ref() == Some(&first)).then_some(first) +} + +fn reveal_id() -> Id { + Id::unique("picker_reveal_current") +} + +/// A picker opening now: its first frame scrolls the row in use into view +/// ([`reveal_if_asked`]), then [`end_reveal`] lets the list be scrolled freely. +pub fn ask_reveal(ctx: &egui::Context) { + ctx.data_mut(|d| d.insert_temp(reveal_id(), true)); +} + +/// Scroll `rect` (the row in use) to the middle of its list when the picker has just opened, at +/// once rather than animated, so the list opens there. A popup's first pass only measures it, so +/// the request waits for the pass that is shown. +pub fn reveal_if_asked(ui: &Ui, rect: Rect) { + if ui.data(|d| d.get_temp::(reveal_id())).unwrap_or(false) { + ui.scroll_to_rect_animation(rect, Some(egui::Align::Center), egui::style::ScrollAnimation::none()); + if !ui.is_sizing_pass() { + ui.data_mut(|d| d.remove_temp::(reveal_id())); + } + } +} + +/// The picker's first shown frame is over (`ui` its list's): nothing more scrolls by itself. +pub fn end_reveal(ui: &Ui) { + if !ui.is_sizing_pass() { + ui.data_mut(|d| d.remove_temp::(reveal_id())); + } +} + +/// Whether `v`, listed from `lib` (None: this file), is the variable `current` (an id in this +/// document): itself, or for a library variable the copy this document made of it. +pub fn is_current(doc: &Document, current: Option<&str>, lib: Option<&PublishedLibrary>, v: &Variable) -> bool { + let Some(current) = current else { return false }; + match lib { + None => v.id == current, + Some(l) => doc.libraries.variables.iter().any(|r| r.library == l.manifest.id && r.key == v.id && r.local == current), } - doc.variables.get_by_id(&first).map(|v| v.name.clone()) } /// A variable a picker offers: one of this file's, or a published one of an enabled library. @@ -151,11 +198,12 @@ pub fn mode_rows<'a>(doc: &'a Document, libs: &'a [Arc]) -> Ve out } -/// A picker row: the variable's swatch (colours) or icon, its name and (other types) its value in -/// the default modes; true when clicked. -pub fn variable_row(ui: &mut Ui, vars: &Variables, v: &Variable, width: f32) -> bool { +/// A picker row: the variable's swatch (colours) or icon, its name, (other types) its value in +/// the default modes and a check when it is `current` (what the field uses now); true when clicked. +pub fn variable_row(ui: &mut Ui, vars: &Variables, v: &Variable, width: f32, current: bool) -> bool { let t = Tokens::get(ui.ctx()); let (r, resp) = ui.allocate_exact_size(vec2(width, 26.0), Sense::click()); + crate::a11y::radio(&resp, &v.name, current); if resp.hovered() { ui.painter().rect_filled(r, CornerRadius::same(5), t.menu_hover); } @@ -165,9 +213,17 @@ pub fn variable_row(ui: &mut Ui, vars: &Variables, v: &Variable, width: f32) -> Some(VariableValue::Color(c)) => widgets::paint_swatch(ui.painter(), lead, &figcraft_color::Paint::solid(*c)), _ => icons::paint(ui.painter(), lead.shrink(1.0), Icon::Variable, t.menu_text), } - let name_r = Rect::from_min_max(pos2(r.min.x + 26.0, r.min.y), pos2(r.max.x - 6.0, r.max.y)); + let end = if current { + reveal_if_asked(ui, r); + let check = Rect::from_center_size(pos2(r.max.x - 14.0, r.center().y), vec2(12.0, 12.0)); + icons::paint(ui.painter(), check, Icon::Check, t.menu_text); + check.min.x - 4.0 + } else { + r.max.x - 6.0 + }; + let name_r = Rect::from_min_max(pos2(r.min.x + 26.0, r.min.y), pos2(end, r.max.y)); if let Some(val) = value.filter(|v| !matches!(v, VariableValue::Color(_))) { - ui.painter().text(pos2(r.max.x - 6.0, r.center().y), Align2::RIGHT_CENTER, val.display(), regular(11.0), t.menu_dim); + ui.painter().text(pos2(end, r.center().y), Align2::RIGHT_CENTER, val.display(), regular(11.0), t.menu_dim); } ui.painter().with_clip_rect(name_r).text(name_r.left_center(), Align2::LEFT_CENTER, &v.name, regular(11.0), t.menu_text); resp.clicked() @@ -186,25 +242,25 @@ pub fn group_caption(ui: &mut Ui, lib: Option<&PublishedLibrary>, coll: &Collect /// Open the picker for `field` of `ids` at `at`. pub fn open(ui: &Ui, ids: &[NodeId], field: &str, kind: VariableType, at: Pos2) { let target = Target::Bind { ids: ids.to_vec(), field: field.to_string() }; - ui.data_mut(|d| d.insert_temp(picker_id(), Picker { target, kind: Some(kind), at })); + open_picker(ui, Picker { target, kind: Some(kind), at }); } /// Open the picker at `at` to pick a variable (of `kind`, or any) for a prototype action. pub fn open_proto(ui: &Ui, slot: crate::proto_editor::VarSlot, kind: Option, at: Pos2) { - ui.data_mut(|d| d.insert_temp(picker_id(), Picker { target: Target::Proto(slot), kind, at })); + open_picker(ui, Picker { target: Target::Proto(slot), kind, at }); } /// Open the picker at `at` to bind a variable of `kind` to `field` of the shared style `style`. pub fn open_style(ui: &Ui, style: &str, field: &str, kind: VariableType, at: Pos2) { let target = Target::Style { style: style.to_string(), field: field.to_string() }; - ui.data_mut(|d| d.insert_temp(picker_id(), Picker { target, kind: Some(kind), at })); + open_picker(ui, Picker { target, kind: Some(kind), at }); } /// Open the picker at `at` to bind a string (face name) or number (weight) variable to the weight of /// the shared text style `style`. pub fn open_style_weight(ui: &Ui, style: &str, at: Pos2) { let target = Target::StyleWeight { style: style.to_string() }; - ui.data_mut(|d| d.insert_temp(picker_id(), Picker { target, kind: None, at })); + open_picker(ui, Picker { target, kind: None, at }); } /// Where the open picker is on screen (clicks in it don't close what opened it). @@ -220,7 +276,7 @@ pub fn picker_open(ctx: &egui::Context) -> bool { /// Open the picker at `at` to alias `variable`'s value in `mode` to another variable. pub fn open_alias(ui: &Ui, variable: &str, mode: &str, kind: VariableType, at: Pos2) { let target = Target::Alias { variable: variable.to_string(), mode: mode.to_string() }; - ui.data_mut(|d| d.insert_temp(picker_id(), Picker { target, kind: Some(kind), at })); + open_picker(ui, Picker { target, kind: Some(kind), at }); } /// Open the picker for `field` of `ids` under the pointer (from a section header button). @@ -355,7 +411,8 @@ pub fn bindable( /// In a paint field's text area `text_r`: the chip of the colour variable `name` that `key` of /// `ids` is bound to (its last path part, the whole name on hover) and a button that detaches it. -pub fn paint_chip(app: &mut FigApp, ui: &mut Ui, ids: &[NodeId], key: &str, name: &str, text_r: Rect, id: Id) { +/// The chip is a button: true when it was clicked, for the caller to open a picker to change it. +pub fn paint_chip(app: &mut FigApp, ui: &mut Ui, ids: &[NodeId], key: &str, name: &str, text_r: Rect, id: Id) -> bool { let t = Tokens::get(ui.ctx()); let r = ui.max_rect(); let chip = Rect::from_min_max(pos2(text_r.min.x - 2.0, r.min.y + 3.0), pos2(text_r.max.x - 20.0, r.max.y - 3.0)); @@ -369,13 +426,20 @@ pub fn paint_chip(app: &mut FigApp, ui: &mut Ui, ids: &[NodeId], key: &str, name regular(11.0), t.text, ); - let _ = ui.interact(chip, id, Sense::hover()).on_hover_text(name); + let resp = ui.interact(chip, id, Sense::click()); + crate::a11y::combo(&resp, tr("Variable"), name, false); + if resp.hovered() { + ui.painter().rect_stroke(chip, CornerRadius::same(4), Stroke::new(1.0, t.field_hover_border), egui::StrokeKind::Inside); + } + let clicked = resp.on_hover_text(name).clicked(); let dr = Rect::from_center_size(pos2(text_r.max.x - 9.0, r.center().y), vec2(18.0, 18.0)); let dresp = ui.interact(dr, id.with("detach"), Sense::click()).tip(tr("Detach variable")); icons::paint(ui.painter(), dr.shrink(3.0), Icon::Detach, t.icon_secondary); if dresp.clicked() { app.run("variable.bind", json!({"ids": ids, "field": key, "variable": null})); + return false; } + clicked } /// A variable button at the right end of `rect` while the pointer is over it: opens the picker @@ -447,6 +511,10 @@ pub fn picker(app: &mut FigApp, ctx: &egui::Context) { Target::Bind { field, .. } => Some(field.as_str()), _ => None, }; + let current = match &p.target { + Target::Bind { ids, field } => bound_id(&doc, ids, field), + _ => None, + }; let keep = |lib: Option<&PublishedLibrary>, v: &Variable| { kind_fits(p.kind, field, v.kind) && !(local_only && lib.is_some()) @@ -485,12 +553,13 @@ pub fn picker(app: &mut FigApp, ctx: &egui::Context) { group_caption(ui, *lib, c); let all = lib.map_or(&doc.variables, |l| &l.doc.variables); for v in vars { - if variable_row(ui, all, v, 224.0) { + if variable_row(ui, all, v, 224.0, is_current(&doc, current.as_deref(), *lib, v)) { chosen = Some(Pick { library: lib.map(|l| l.manifest.id.clone()), id: v.id.clone() }); } } } }); + end_reveal(ui); if groups.is_empty() { // Whole sentences per type: languages place the type differently. let (fit, none) = match p.kind { diff --git a/crates/ui-egui/src/selection_colors_picker_tests.rs b/crates/ui-egui/src/selection_colors_picker_tests.rs index bdb760b94..765d558fc 100644 --- a/crates/ui-egui/src/selection_colors_picker_tests.rs +++ b/crates/ui-egui/src/selection_colors_picker_tests.rs @@ -112,6 +112,12 @@ fn the_rows_styles_button_opens_the_style_picker_with_search_and_library_names() assert_eq!(doc.node(b).unwrap().fills[0].solid_color().unwrap().to_hex(), "008080"); assert!(doc.node(a).unwrap().bound.is_empty()); assert!(u.app.ui.last_error.is_none()); + // Opened again, the picker marks the library variable the row uses (by its copy here). + open_picker(&mut u, "Sea"); + let out = u.frame_output(vec![]); + let nodes = out.platform_output.accesskit_update.expect("an AccessKit update").nodes; + let sea = nodes.iter().map(|(_, n)| n).find(|n| n.role() == Role::RadioButton && n.label() == Some("Sea")).expect("the picker's Sea row"); + assert_eq!(sea.toggled(), Some(egui::accesskit::Toggled::True), "the variable in use is marked"); let _ = std::fs::remove_dir_all(&dir); } diff --git a/crates/ui-egui/src/widgets/style_picker.rs b/crates/ui-egui/src/widgets/style_picker.rs index c99bf7ecf..e744471cf 100644 --- a/crates/ui-egui/src/widgets/style_picker.rs +++ b/crates/ui-egui/src/widgets/style_picker.rs @@ -167,6 +167,8 @@ pub struct Picker { /// The Selection colors row it was opened for: a pick applies to these paints /// (`selection.*` commands) instead of `slot` of `ids`. colors: Option>, + /// Just opened: the next list scrolls the style or variable in use into view. + reveal: bool, } /// The source menu's choice: every source, this file's styles, or one enabled library's (by @@ -203,7 +205,8 @@ pub fn open(app: &mut FigApp, ui: &Ui, ids: &[NodeId], slot: StyleSlot) { // Opening the style picker closes the colour picker (it would linger beside it). crate::colorpicker::close(app); app.ui.style_picker_popover = None; - app.ui.style_picker = Some(Picker { slot, ids: ids.to_vec(), y, query: String::new(), edit: None, source: Source::All, colors: None }); + app.ui.style_picker = + Some(Picker { slot, ids: ids.to_vec(), y, query: String::new(), edit: None, source: Source::All, colors: None, reveal: true }); } /// Open the picker for a Selection colors row, level with the pointer: the style or colour @@ -222,7 +225,7 @@ pub fn open_for_selection(app: &mut FigApp, slot: StyleSlot, style: Option<&str> let edit = style.and_then(|s| app.session.doc().ok()?.style(s).map(editing)); crate::colorpicker::close(app); app.ui.style_picker_popover = None; - app.ui.style_picker = Some(Picker { slot, ids, y: 140.0, query: String::new(), edit, source: Source::All, colors: None }); + app.ui.style_picker = Some(Picker { slot, ids, y: 140.0, query: String::new(), edit, source: Source::All, colors: None, reveal: true }); } fn editing(s: &Style) -> Editing { @@ -235,6 +238,23 @@ fn colors_link(doc: &Document, ids: &[NodeId], targets: &[PaintTarget]) -> Optio Some(selection_colors::collect(doc, ids).into_iter().find(|c| c.targets == targets).and_then(|c| c.style)) } +/// The colour variable the picker's paints use now (its id in this document): a Selection colors +/// row's `colors`, else the first paint of `slot` of `ids` when they all use the same one. +fn bound_variable(doc: &Document, ids: &[NodeId], slot: StyleSlot, colors: Option<&[PaintTarget]>) -> Option { + if let Some(targets) = colors { + return selection_colors::collect(doc, ids).into_iter().find(|c| c.targets == targets).and_then(|c| c.variable); + } + if !slot.paints() { + return None; + } + let fills = slot == StyleSlot::Fill; + let mut it = ids + .iter() + .map(|id| doc.node(*id).and_then(|n| figcraft_engine::cmd::lists::paint_binding_key(n, fills, 0).and_then(|k| n.bound.get(k).cloned()))); + let first = it.next().flatten()?; + it.all(|v| v.as_ref() == Some(&first)).then_some(first) +} + /// The style `slot` of `ids` links to: `Some(Some(id))` one style, `Some(None)` none, None when /// they differ. Text goes by chars: the selected chars of the text being edited, else every char. fn link_of(app: &FigApp, doc: &Document, ids: &[NodeId], slot: StyleSlot) -> Option> { @@ -540,6 +560,9 @@ fn style_row(ui: &mut Ui, s: &Style, key: Key, slot: StyleSlot, applied: bool, e } else if applied { icons::paint(ui.painter(), edit_r.shrink(5.0), Icon::Check, t.menu_text); } + if applied { + crate::variable_ui::reveal_if_asked(ui, r); + } let tip = match (s.description.is_empty(), text_def(s)) { (true, None) if !s.bound.is_empty() => Some(format!("{}\n{}", s.name, tr("Uses variables: each layer shows them in its own mode"))), (true, None) => None, @@ -585,6 +608,7 @@ fn style_grid(ui: &mut Ui, list: &[(&Style, Key)], applied: Option<&Key>, editab } if applied == Some(key) { ui.painter().rect_stroke(r.expand(2.0), CornerRadius::same(5), Stroke::new(2.0, crate::theme::ACCENT), egui::StrokeKind::Inside); + crate::variable_ui::reveal_if_asked(ui, r); } else if resp.hovered() && !text { ui.painter().rect_stroke(r.expand(2.0), CornerRadius::same(4), Stroke::new(1.0, t.menu_text), egui::StrokeKind::Inside); } @@ -642,6 +666,7 @@ fn listing(app: &FigApp, ui: &mut Ui, doc: &Document, p: &mut Picker, out: &mut None => link_of(app, doc, &p.ids, slot), }; let applied = link.clone().flatten().map(|id| Key::of_local(doc, &id)); + let current = bound_variable(doc, &p.ids, slot, p.colors.as_deref()); let grid = slot.has_grid() && app.ui.style_grid; // The title is the popover's; this row keeps the view toggle, detach and create. let (hr, _) = ui.allocate_exact_size(vec2(W, 24.0), Sense::hover()); @@ -708,6 +733,11 @@ fn listing(app: &FigApp, ui: &mut Ui, doc: &Document, p: &mut Picker, out: &mut } else { Vec::new() }; + if p.reveal { + crate::variable_ui::ask_reveal(ui.ctx()); + // A popup's first pass only measures it: the shown pass asks again. + p.reveal = ui.is_sizing_pass(); + } egui::ScrollArea::vertical().id_salt("style_picker_scroll").max_height(320.0).show(ui, |ui| { ui.spacing_mut().item_spacing.y = 0.0; if sources.iter().all(|(_, l)| l.is_empty()) { @@ -777,12 +807,13 @@ fn listing(app: &FigApp, ui: &mut Ui, doc: &Document, p: &mut Picker, out: &mut crate::variable_ui::group_caption(ui, *lib, c); let all = lib.map_or(&doc.variables, |l| &l.doc.variables); for v in vars { - if crate::variable_ui::variable_row(ui, all, v, W) { + if crate::variable_ui::variable_row(ui, all, v, W, crate::variable_ui::is_current(doc, current.as_deref(), *lib, v)) { out.act = Some(Act::Bind(crate::variable_ui::Pick { library: lib.map(|l| l.manifest.id.clone()), id: v.id.clone() })); } } } }); + crate::variable_ui::end_reveal(ui); } /// One property row in the editor (a paint, an effect, a grid); paints open the colour picker. @@ -1406,7 +1437,8 @@ fn edit_local(app: &mut FigApp, ui: &Ui, slot: StyleSlot, id: &str) { let edit = app.session.doc().ok().and_then(|d| d.style(id).map(editing)); crate::colorpicker::close(app); app.ui.style_picker_popover = None; - app.ui.style_picker = Some(Picker { slot, ids: app.session.selection(), y, query: String::new(), edit, source: Source::All, colors: None }); + app.ui.style_picker = + Some(Picker { slot, ids: app.session.selection(), y, query: String::new(), edit, source: Source::All, colors: None, reveal: true }); } /// `style.move` for the shown style `from` dropped at shown position `to` (`shown` in display diff --git a/docs/ui-parity.md b/docs/ui-parity.md index 36693cd9c..2b3758870 100644 --- a/docs/ui-parity.md +++ b/docs/ui-parity.md @@ -1,6 +1,6 @@ # UI and interaction parity -> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-12-03 · **Change:** minor (a selected text's font size handle on the Move tool (#1563); Notched corners in the corner style menu (#1680); the auto layout's settings popover off the gap row (#803); View ▸ Panels ▸ Auto-hide navigation bar hides the icon bar at the window's edge, giving the canvas its width, and brings it out over the layers panel while the pointer is at that edge (#2785); the colour picker shows the WCAG contrast of a layer's fill against the colour behind it, with a pass or fail mark for AA or AAA (#2779); a Selection colors row's Styles button opens the style picker, with search and each library's styles and variables under its name; while a field is scrubbed the selection's frame and handles hide, so the value shows on the layer, as they already did while the colour picker is used (#1319); the Pencil, Marker, Highlighter and Eraser show a round tip in the ink's colour and width instead of a crosshair (#2641); the `` ` `` key chooses the code block tool on boards (#2237); Cmd/Ctrl+L copies a link to the selected layer, as in Figma; M4: the eyedropper colours the stroke of a layer that has only a stroke, samples for an open colour picker from the shortcut too, and shows the colour under it beside the pointer; Shift with a double-click goes a level deeper and keeps the rest of the selection, so layers nested in neighbouring artboards can be selected together; M1: Frame selection makes a frame without a fill; M1: centred auto-width text keeps its middle as it grows and shrinks; M1: a drag on a section's background, or on the background of a frame in it, draws a marquee; the Layers panel's eye and padlock stay at the list's right edge, and a name takes at most 400 pt; in vector edit mode, deleting a point selects the next one on its path, so Delete pressed again goes on along it; the hover and selection outline of a curved layer bends smoothly instead of showing straight pieces; text copied while editing, or a whole text layer copied, pastes into a text edit with its formatting and its layer's colour, and Shift+Cmd/Ctrl+V (also Alt+Cmd/Ctrl+V) pastes it in the style at the caret; crop mode: the layer's sides and corners crop its image in an auto layout frame too, up to the image's edges, change a locked ratio (Shift keeps it), the image's own corners scale freely with Shift proportional as a resize does, and crop mode and vector edit mode end each other; after a click on a layer row the arrow keys nudge the selection, or move a layer in an auto layout flow one place, as in Figma; the rows take the arrows once they have the keyboard (F6); Shift+Cmd/Ctrl+V with several layers selected pastes after the last of them as seen: next in an auto layout frame's flow, else below the lowest or right of the rightmost, at the selection's own gap; Tab and Shift+Tab while editing a text layer go on to the next or previous text layer of its frame, in reading order, with all of its text selected; a file opens again on the page and at the view it was left at; the desktop app reopens the files open when it quit, in their tabs' order with the same one in front, and with nothing to reopen starts on the Home screen instead of in a new file; a dropdown, button menu or context menu in the panels that is taller than the window scrolls, so its last rows can be picked; frames, sections, components and instances move, resize and draw on whole pixels whatever Snap to pixel grid says and whatever they snap to, as Figma's help says; the pixel grid shows on a dark canvas and dark fills as well as on white, its lines one screen pixel wide in a light grey at a fifth of its strength, as measured in Figma; Shift+Cmd/Ctrl+' says at the bottom of the window whether snapping to the pixel grid is now on or off; Paste properties links the copied layer's colour, effect, grid and text styles and binds the variables it follows, and a frame's layout grids come along; links another file lacks paste as values; 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); a dragged layer is drawn from a sprite that moves with its outline (#2033); the Scale tool keeps variable-bound lengths scaled: a scaled instance keeps its bindings and draws them at the variable's value times its scale factor, other scaled layers keep the scaled value and drop the binding (#2090); Type settings ▸ Details ▸ Position sets the selected text layers, or the selected characters while editing, to superscript or subscript, or neither (#2338); Shift with the Pencil, Marker or Highlighter draws one straight segment from where the stroke started, at the nearest 45° step, as the Line tool and the Pen do (#2447); the Design panel's header names a selected component or component set, after its icon, instead of only its type (#2347); dragging near the canvas edge pans the view toward it, as measured in Figma: 40 px/s for each px within about 15 px of the edge, 600 px/s at it, for moving layers, the selection box, drawing and prototype connections (#2015); M8: a Shift-click range in the Layers panel across parents keeps a frame and not its covered children, measured in Figma's web app on 2026-11-12; points align and distribute in vector edit mode as in Figma: the six Align commands, the keys Alt+A/H/D/W/V/S, and Distribute horizontal and vertical spacing act on the selected points, each moving along one axis to their box's edge or centre line, spaced evenly between the outermost for distribute, with the alignment row first in the Design panel (#2109); going back to a page shows it where it was left, not fitted again; Duplicate repeats the last copy's move and its rotation (about the copy's centre, or the selection's centre for several layers), the move turning with it so the copies go round a ring (#2862), not its size, and forgets the step when the selection changes, measured in Figma's web app on 2026-11-12 (#2293); M8: a double-click on a layer's icon zooms to it instead of renaming, measured in Figma's web app on 2026-11-12; Tidy up keeps the order and sizes and evens the gaps, as measured in Figma's web app on 2026-11-12, rounds the gap half up, tidies overlapping rows and packs a grid along its longer axis, and is greyed out for fewer than three layers, a diagonal and an irregular layout (M8); after Crop is chosen in the image fill's colour picker, a drag on the image crops it instead of moving the layer, and no internal gesture message shows (#2307); Align is disabled for a layer in an auto layout frame's flow, as measured in Figma's web app on 2026-11-12, with a tip saying the frame places it; Select layer lists locked layers with a padlock and selects them, and shows only with more than one layer under the pointer (#1560); M8: Scale tool handle drags pivot on the opposite handle whatever the origin, and the origin starts at the centre (measured in Figma's web app, 2026-11-09); M8: a selected polygon or star has a Count handle on the canvas, on its first point clockwise from the top; Zoom to selection leaves a 40 pt margin and clears the bottom toolbar, measured in Figma's web app; M1: Paste over selection puts the pasted layers just above the selected layer; drag modifiers compared in Figma's web app (2026-11-08): Shift locks a move to the dominant axis, Alt copies, Shift keeps a resize's ratio, Alt keeps its centre, all read afresh on every move, and FigCraft matches (Ctrl/Cmd not measurable); a mirror mode (angle, or angle and length) on a sharp point turns it smooth, as in Figma (#2110); M8: Tab while renaming the last layer wraps to the first row, measured in Figma's web app on 2026-11-12; the text caret takes the text's solid fill colour (#2156); the Rotation field shows and sets the rotation on the page, in frames and groups, through node.set absoluteRotation (#2196); the eyedropper picks a magnified image's pixel under the pointer, not a blend with its neighbours (#2189); Selection colors shows from one distinct colour when a selected layer has children, and from two otherwise, measured in Figma's web app on 2026-11-09 on a frame, a group and plain rectangles; the crosshair of the shape and Text tools is drawn dark with a white edge, so it shows on a white frame whatever the system's pointer style (#2198); a boolean group takes a corner radius (and smoothing) that rounds every sharp corner of its result (#2222); the Point section's X and Y in vector edit mode show Mixed and set every selected point of the layer being edited, as in Figma; Preferences ▸ Invert zoom direction reverses wheel zoom, pinch unchanged (#2145); Shift while rotating lands on absolute multiples of 15°, measured in Figma; Flatten bakes a vector's point corner radius into its path (#2195); a click on a fill, stroke or effect row's grip or background highlights it, Cmd/Ctrl+C copies that paint or effect and Cmd/Ctrl+V pastes it onto the selected layers, as the help center's Copy and paste properties between layers says (#1494); wrap style per paragraph and in text styles (#1827); the Annotation tool (Shift+T, `tool.annotation {id?}`): with a layer selected (or an `id`) it asks the UI for that layer's note at once, and in the tool a press on a layer selects it and asks for its note, a press on empty canvas does nothing; the marquee follows Figma's measured rules: a partly covered frame or section gives the layers in it the marquee touches, a rotated shape is touched by its outline, a drag from inside a frame selects that frame only when the marquee also takes another top-level frame (then whole) (`marquee_behaviour_tests`); copy, cut and paste in vector edit mode act on the selected points and segments (#1875); M8, #2146: K focuses the Scale tool's factor field with its text selected, so K, 2, Enter scales the selection by two about the panel's origin (FigCraft's starts at the top left; Figma's grid starts at the centre, left for a follow-up because the origin also sets where a handle drag pivots, which is not measured) in one undo step, after which the tool returns to Move with the selection kept; Escape in the field closes it with the tool back on Move and nothing changed (measured in Figma's web app, 2026-11-09; `pressing_k_focuses_the_scale_field_with_its_text_selected`, `k_two_enter_scales_the_selection_by_two`, `escape_in_the_scale_field_closes_it_and_changes_nothing`); the main menu and its submenus stay inside the window, moving up to fit and scrolling when taller (#2217); locked layers ignore the arrow keys and a locked parent's children can't be locked on their own (#1560); the left rail's and tab strip's icons are larger, 20 pt (#553); pick select: Tab while the keyboard selection box shows (or the chord again) puts a pink outline on a layer and the keys walk the layer tree from it, as Accessibility at Figma says (#1836); scrubbing a field faster or slower by the pointer's height, with a notice of the speed, as the help center's Scrub fields says (#1837); component rows in the Layers panel at AA contrast in the theme's component tint, with the rows inside a selected component in a tone of its row (#1903); Cmd/Ctrl-click on a padding field sets all four sides with the value typed, a documented auto layout shortcut; a fill per region of a vector: with regions selected in edit mode, the Fill section and the fill commands edit those regions' own fills, as Edit vector layers says (#1875); the Fill section of a text whose characters were coloured differently while editing shows mixed content, characters that all share fills the layer doesn't have show those, and a layer-level fill edit reaches every character (#1856); a number field scrubs when dragged with Alt held, as the help center's scrub section says, not only by its label; reuse visible layer selection roots (M8); ; with a shape or frame tool chosen and nothing selected, the arrows show a placement crosshair in the middle of the view and move it, and Enter places there, as Accessibility at Figma says (#1839); text direction per paragraph: Text ▸ Text direction forces a paragraph left to right or right to left, as Add right-to-left text says (#1830), with `text.direction`, `node.set textDirection`, the Type settings control once a right-to-left script is in the text, inspect, the CSS `direction` and the `.fig` lines' `sourceDirectionality`; the boolean operation menu in the Design panel leads each entry with an original icon drawn in code, a filled preview of the result (#2003); a press on the open gradient's handles or stops on the canvas keeps the colour picker open through the drag, as its own control (#1852); a click with the Bend tool on a sharp point curves it, its handles along the line between its neighbours, as Edit vector layers says (#1875); wrap style: Auto, Balance and Pretty on a text layer decide where its lines break, as Explore text properties says (#1827), with the Type settings control, `text.wrapStyle`, `node.set wrapStyle`, inspect and the CSS `text-wrap`; Backspace or Delete at the start of a list item keeps the item's indentation level, as the lists article says; max lines on auto-width text keep it auto width, hugging that many lines, as the text properties article says; superscript and subscript are synthesised where the font has no glyphs for them, from the standard glyphs shrunk and shifted by the font's OS/2 metrics, and a run mixing available and unavailable glyphs is synthesised whole, as Explore text properties says (#1828); Alt+Enter while editing text opens the link at the caret, as the accessibility page documents; Minimize, by its shortcut or the button by the file name, collapses the navigation bar and both sidebars as the help center says, with the right sidebar back while something is selected (#1835); the interface size keys of the help center's accessibility page: Cmd/Ctrl+Shift+Alt with =, - and 0 step the interface through the Preferences sizes and back to the system's size; Cmd/Ctrl+Alt+arrows rotate the selection a degree at a time, 15 with Shift, as the help center's accessibility page says; they resized before; the Layers panel answers Ctrl+1 as well as Alt+1 on Windows and Linux, the two keys the help center gives it; the colour picker's Image tab shows a placeholder and Upload from computer, an asset preview, and a file dropped on it replaces the image, keeping the fill mode, crop and position (#1682); the keyboard's Menu key opens the context menu, as Shift+F10 does; the eyedropper with Cmd/Ctrl+Shift makes a colour style or variable of what it picks; sidebar number and text fields keep their text vertically centered when focused, including typography spacing; with the pen out, Enter or a double-click ends the path and edits the vector with the Move tool instead of drawing on (#1430); the Actions palette offers only commands that run from it, and no second row reading like a menu item: Place image opens the file dialog (#1574); Preferences ▸ Scroll wheel zoom: a mouse wheel zooms the canvas about the pointer and Cmd/Ctrl+wheel scrolls (#1390); boolean operations refuse input past their caps, and a boolean group past them draws without its result (#1104); the selection and hover outlines of rounded rectangles and frames follow their corners (#1506); colour picker review fixes for text undo, fitted sidebars, moving controls and gradient variables; Corner smoothing: an original icon and the shared number-field drag gesture, preserving fractional baselines; guides snap to layers when dragged; Crop image: Object ▸ Crop image, the right-click menu and the image fill row enter crop mode (`image.crop`, #1464); the Design panel's sections on one grid — 16 / 8 margins, 88 + 8 + 88 + 8 + 24 columns, 24 pt rows, 4 pt between a row's buttons (#858); the toolbar on one 32 pt grid, without its Resources button (#1210); colour picker LCH and OKLCH models; an XML (Android Vector Drawable) export format; Context menus: the Menu key reaches egui 0.37 but is unbound (row done → partial); the Text on a path tool; board tool keys pinned; community fixes: the text box by dragging, the font picker keys, the pen path on leaving Design, a still canvas in vector edit mode, a scrolling pages list, colour emoji, readable new text in frames, system theme on first run; the Small caps sample in Type settings drawn from capitals; recent files as cards; vector edit mode: hovering, hatching, selecting and dragging filled regions; home screen: Templates tab, first-run templates and Getting started tips; number fields: scrub rates, arrow steps, arithmetic with brackets, relative edits of mixed values; outline mode's hidden layers and object bounds; Hide when publishing; cursors per tool and modifier; panel widths; dark pages for files made in the dark theme; drag threshold and double-clicks into text in groups; rotation origin on Alt+R and placing with Enter: no documented shortcut missing; keyboard shortcut parity suite and bindings; cursor chat and spotlight in live sessions; layers and assets panels behaviour suite and fixes; vector multi-edit and the vector edit tail; canvas navigation, guides and grids behaviour suite and fixes; shapes and vector behaviour suite and fixes; paint and effects behaviour suite and fixes; frames, groups, sections and masks behaviour suite and fixes; layers panel keyboard: F2 rename, Shift+F10 context menu, F8 box selection; selection and transform behaviour suite and fixes; Display P3: gamut warning and soft-proof (true P3 blocked upstream); several windows; boolean hit testing on the result, group drags, frame outlines and slices; outlines for the selection, mask outlines; arc fields, live boolean editing, shape builder on strokes, one-sided widths; fields select their text on focus; Typography spacing icons support scrubbing (#373); CSS colour names in hex fields; a rename selects the whole name, so typing replaces it; Escape or Enter after a pen path stays on the same vector (#760); IME composition kept on through idle frames of a text edit, candidates at the caret (#747); Selection colors for mixed selections and smart-selection spacing (#753); submenus with a hover delay and a safe triangle; the Actions palette's tabs, ranked search, highlight and recents; menu items that ask for a value; editor fixes from the community batches) · **Target:** Figma Design UI3 (desktop app 126.10.7) +> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-12-03 · **Change:** minor (a click on the variable a paint's colour is bound to opens a picker to change it, with that variable marked and scrolled into view; a selected text's font size handle on the Move tool (#1563); Notched corners in the corner style menu (#1680); the auto layout's settings popover off the gap row (#803); View ▸ Panels ▸ Auto-hide navigation bar hides the icon bar at the window's edge, giving the canvas its width, and brings it out over the layers panel while the pointer is at that edge (#2785); the colour picker shows the WCAG contrast of a layer's fill against the colour behind it, with a pass or fail mark for AA or AAA (#2779); a Selection colors row's Styles button opens the style picker, with search and each library's styles and variables under its name; while a field is scrubbed the selection's frame and handles hide, so the value shows on the layer, as they already did while the colour picker is used (#1319); the Pencil, Marker, Highlighter and Eraser show a round tip in the ink's colour and width instead of a crosshair (#2641); the `` ` `` key chooses the code block tool on boards (#2237); Cmd/Ctrl+L copies a link to the selected layer, as in Figma; M4: the eyedropper colours the stroke of a layer that has only a stroke, samples for an open colour picker from the shortcut too, and shows the colour under it beside the pointer; Shift with a double-click goes a level deeper and keeps the rest of the selection, so layers nested in neighbouring artboards can be selected together; M1: Frame selection makes a frame without a fill; M1: centred auto-width text keeps its middle as it grows and shrinks; M1: a drag on a section's background, or on the background of a frame in it, draws a marquee; the Layers panel's eye and padlock stay at the list's right edge, and a name takes at most 400 pt; in vector edit mode, deleting a point selects the next one on its path, so Delete pressed again goes on along it; the hover and selection outline of a curved layer bends smoothly instead of showing straight pieces; text copied while editing, or a whole text layer copied, pastes into a text edit with its formatting and its layer's colour, and Shift+Cmd/Ctrl+V (also Alt+Cmd/Ctrl+V) pastes it in the style at the caret; crop mode: the layer's sides and corners crop its image in an auto layout frame too, up to the image's edges, change a locked ratio (Shift keeps it), the image's own corners scale freely with Shift proportional as a resize does, and crop mode and vector edit mode end each other; after a click on a layer row the arrow keys nudge the selection, or move a layer in an auto layout flow one place, as in Figma; the rows take the arrows once they have the keyboard (F6); Shift+Cmd/Ctrl+V with several layers selected pastes after the last of them as seen: next in an auto layout frame's flow, else below the lowest or right of the rightmost, at the selection's own gap; Tab and Shift+Tab while editing a text layer go on to the next or previous text layer of its frame, in reading order, with all of its text selected; a file opens again on the page and at the view it was left at; the desktop app reopens the files open when it quit, in their tabs' order with the same one in front, and with nothing to reopen starts on the Home screen instead of in a new file; a dropdown, button menu or context menu in the panels that is taller than the window scrolls, so its last rows can be picked; frames, sections, components and instances move, resize and draw on whole pixels whatever Snap to pixel grid says and whatever they snap to, as Figma's help says; the pixel grid shows on a dark canvas and dark fills as well as on white, its lines one screen pixel wide in a light grey at a fifth of its strength, as measured in Figma; Shift+Cmd/Ctrl+' says at the bottom of the window whether snapping to the pixel grid is now on or off; Paste properties links the copied layer's colour, effect, grid and text styles and binds the variables it follows, and a frame's layout grids come along; links another file lacks paste as values; 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); a dragged layer is drawn from a sprite that moves with its outline (#2033); the Scale tool keeps variable-bound lengths scaled: a scaled instance keeps its bindings and draws them at the variable's value times its scale factor, other scaled layers keep the scaled value and drop the binding (#2090); Type settings ▸ Details ▸ Position sets the selected text layers, or the selected characters while editing, to superscript or subscript, or neither (#2338); Shift with the Pencil, Marker or Highlighter draws one straight segment from where the stroke started, at the nearest 45° step, as the Line tool and the Pen do (#2447); the Design panel's header names a selected component or component set, after its icon, instead of only its type (#2347); dragging near the canvas edge pans the view toward it, as measured in Figma: 40 px/s for each px within about 15 px of the edge, 600 px/s at it, for moving layers, the selection box, drawing and prototype connections (#2015); M8: a Shift-click range in the Layers panel across parents keeps a frame and not its covered children, measured in Figma's web app on 2026-11-12; points align and distribute in vector edit mode as in Figma: the six Align commands, the keys Alt+A/H/D/W/V/S, and Distribute horizontal and vertical spacing act on the selected points, each moving along one axis to their box's edge or centre line, spaced evenly between the outermost for distribute, with the alignment row first in the Design panel (#2109); going back to a page shows it where it was left, not fitted again; Duplicate repeats the last copy's move and its rotation (about the copy's centre, or the selection's centre for several layers), the move turning with it so the copies go round a ring (#2862), not its size, and forgets the step when the selection changes, measured in Figma's web app on 2026-11-12 (#2293); M8: a double-click on a layer's icon zooms to it instead of renaming, measured in Figma's web app on 2026-11-12; Tidy up keeps the order and sizes and evens the gaps, as measured in Figma's web app on 2026-11-12, rounds the gap half up, tidies overlapping rows and packs a grid along its longer axis, and is greyed out for fewer than three layers, a diagonal and an irregular layout (M8); after Crop is chosen in the image fill's colour picker, a drag on the image crops it instead of moving the layer, and no internal gesture message shows (#2307); Align is disabled for a layer in an auto layout frame's flow, as measured in Figma's web app on 2026-11-12, with a tip saying the frame places it; Select layer lists locked layers with a padlock and selects them, and shows only with more than one layer under the pointer (#1560); M8: Scale tool handle drags pivot on the opposite handle whatever the origin, and the origin starts at the centre (measured in Figma's web app, 2026-11-09); M8: a selected polygon or star has a Count handle on the canvas, on its first point clockwise from the top; Zoom to selection leaves a 40 pt margin and clears the bottom toolbar, measured in Figma's web app; M1: Paste over selection puts the pasted layers just above the selected layer; drag modifiers compared in Figma's web app (2026-11-08): Shift locks a move to the dominant axis, Alt copies, Shift keeps a resize's ratio, Alt keeps its centre, all read afresh on every move, and FigCraft matches (Ctrl/Cmd not measurable); a mirror mode (angle, or angle and length) on a sharp point turns it smooth, as in Figma (#2110); M8: Tab while renaming the last layer wraps to the first row, measured in Figma's web app on 2026-11-12; the text caret takes the text's solid fill colour (#2156); the Rotation field shows and sets the rotation on the page, in frames and groups, through node.set absoluteRotation (#2196); the eyedropper picks a magnified image's pixel under the pointer, not a blend with its neighbours (#2189); Selection colors shows from one distinct colour when a selected layer has children, and from two otherwise, measured in Figma's web app on 2026-11-09 on a frame, a group and plain rectangles; the crosshair of the shape and Text tools is drawn dark with a white edge, so it shows on a white frame whatever the system's pointer style (#2198); a boolean group takes a corner radius (and smoothing) that rounds every sharp corner of its result (#2222); the Point section's X and Y in vector edit mode show Mixed and set every selected point of the layer being edited, as in Figma; Preferences ▸ Invert zoom direction reverses wheel zoom, pinch unchanged (#2145); Shift while rotating lands on absolute multiples of 15°, measured in Figma; Flatten bakes a vector's point corner radius into its path (#2195); a click on a fill, stroke or effect row's grip or background highlights it, Cmd/Ctrl+C copies that paint or effect and Cmd/Ctrl+V pastes it onto the selected layers, as the help center's Copy and paste properties between layers says (#1494); wrap style per paragraph and in text styles (#1827); the Annotation tool (Shift+T, `tool.annotation {id?}`): with a layer selected (or an `id`) it asks the UI for that layer's note at once, and in the tool a press on a layer selects it and asks for its note, a press on empty canvas does nothing; the marquee follows Figma's measured rules: a partly covered frame or section gives the layers in it the marquee touches, a rotated shape is touched by its outline, a drag from inside a frame selects that frame only when the marquee also takes another top-level frame (then whole) (`marquee_behaviour_tests`); copy, cut and paste in vector edit mode act on the selected points and segments (#1875); M8, #2146: K focuses the Scale tool's factor field with its text selected, so K, 2, Enter scales the selection by two about the panel's origin (FigCraft's starts at the top left; Figma's grid starts at the centre, left for a follow-up because the origin also sets where a handle drag pivots, which is not measured) in one undo step, after which the tool returns to Move with the selection kept; Escape in the field closes it with the tool back on Move and nothing changed (measured in Figma's web app, 2026-11-09; `pressing_k_focuses_the_scale_field_with_its_text_selected`, `k_two_enter_scales_the_selection_by_two`, `escape_in_the_scale_field_closes_it_and_changes_nothing`); the main menu and its submenus stay inside the window, moving up to fit and scrolling when taller (#2217); locked layers ignore the arrow keys and a locked parent's children can't be locked on their own (#1560); the left rail's and tab strip's icons are larger, 20 pt (#553); pick select: Tab while the keyboard selection box shows (or the chord again) puts a pink outline on a layer and the keys walk the layer tree from it, as Accessibility at Figma says (#1836); scrubbing a field faster or slower by the pointer's height, with a notice of the speed, as the help center's Scrub fields says (#1837); component rows in the Layers panel at AA contrast in the theme's component tint, with the rows inside a selected component in a tone of its row (#1903); Cmd/Ctrl-click on a padding field sets all four sides with the value typed, a documented auto layout shortcut; a fill per region of a vector: with regions selected in edit mode, the Fill section and the fill commands edit those regions' own fills, as Edit vector layers says (#1875); the Fill section of a text whose characters were coloured differently while editing shows mixed content, characters that all share fills the layer doesn't have show those, and a layer-level fill edit reaches every character (#1856); a number field scrubs when dragged with Alt held, as the help center's scrub section says, not only by its label; reuse visible layer selection roots (M8); ; with a shape or frame tool chosen and nothing selected, the arrows show a placement crosshair in the middle of the view and move it, and Enter places there, as Accessibility at Figma says (#1839); text direction per paragraph: Text ▸ Text direction forces a paragraph left to right or right to left, as Add right-to-left text says (#1830), with `text.direction`, `node.set textDirection`, the Type settings control once a right-to-left script is in the text, inspect, the CSS `direction` and the `.fig` lines' `sourceDirectionality`; the boolean operation menu in the Design panel leads each entry with an original icon drawn in code, a filled preview of the result (#2003); a press on the open gradient's handles or stops on the canvas keeps the colour picker open through the drag, as its own control (#1852); a click with the Bend tool on a sharp point curves it, its handles along the line between its neighbours, as Edit vector layers says (#1875); wrap style: Auto, Balance and Pretty on a text layer decide where its lines break, as Explore text properties says (#1827), with the Type settings control, `text.wrapStyle`, `node.set wrapStyle`, inspect and the CSS `text-wrap`; Backspace or Delete at the start of a list item keeps the item's indentation level, as the lists article says; max lines on auto-width text keep it auto width, hugging that many lines, as the text properties article says; superscript and subscript are synthesised where the font has no glyphs for them, from the standard glyphs shrunk and shifted by the font's OS/2 metrics, and a run mixing available and unavailable glyphs is synthesised whole, as Explore text properties says (#1828); Alt+Enter while editing text opens the link at the caret, as the accessibility page documents; Minimize, by its shortcut or the button by the file name, collapses the navigation bar and both sidebars as the help center says, with the right sidebar back while something is selected (#1835); the interface size keys of the help center's accessibility page: Cmd/Ctrl+Shift+Alt with =, - and 0 step the interface through the Preferences sizes and back to the system's size; Cmd/Ctrl+Alt+arrows rotate the selection a degree at a time, 15 with Shift, as the help center's accessibility page says; they resized before; the Layers panel answers Ctrl+1 as well as Alt+1 on Windows and Linux, the two keys the help center gives it; the colour picker's Image tab shows a placeholder and Upload from computer, an asset preview, and a file dropped on it replaces the image, keeping the fill mode, crop and position (#1682); the keyboard's Menu key opens the context menu, as Shift+F10 does; the eyedropper with Cmd/Ctrl+Shift makes a colour style or variable of what it picks; sidebar number and text fields keep their text vertically centered when focused, including typography spacing; with the pen out, Enter or a double-click ends the path and edits the vector with the Move tool instead of drawing on (#1430); the Actions palette offers only commands that run from it, and no second row reading like a menu item: Place image opens the file dialog (#1574); Preferences ▸ Scroll wheel zoom: a mouse wheel zooms the canvas about the pointer and Cmd/Ctrl+wheel scrolls (#1390); boolean operations refuse input past their caps, and a boolean group past them draws without its result (#1104); the selection and hover outlines of rounded rectangles and frames follow their corners (#1506); colour picker review fixes for text undo, fitted sidebars, moving controls and gradient variables; Corner smoothing: an original icon and the shared number-field drag gesture, preserving fractional baselines; guides snap to layers when dragged; Crop image: Object ▸ Crop image, the right-click menu and the image fill row enter crop mode (`image.crop`, #1464); the Design panel's sections on one grid — 16 / 8 margins, 88 + 8 + 88 + 8 + 24 columns, 24 pt rows, 4 pt between a row's buttons (#858); the toolbar on one 32 pt grid, without its Resources button (#1210); colour picker LCH and OKLCH models; an XML (Android Vector Drawable) export format; Context menus: the Menu key reaches egui 0.37 but is unbound (row done → partial); the Text on a path tool; board tool keys pinned; community fixes: the text box by dragging, the font picker keys, the pen path on leaving Design, a still canvas in vector edit mode, a scrolling pages list, colour emoji, readable new text in frames, system theme on first run; the Small caps sample in Type settings drawn from capitals; recent files as cards; vector edit mode: hovering, hatching, selecting and dragging filled regions; home screen: Templates tab, first-run templates and Getting started tips; number fields: scrub rates, arrow steps, arithmetic with brackets, relative edits of mixed values; outline mode's hidden layers and object bounds; Hide when publishing; cursors per tool and modifier; panel widths; dark pages for files made in the dark theme; drag threshold and double-clicks into text in groups; rotation origin on Alt+R and placing with Enter: no documented shortcut missing; keyboard shortcut parity suite and bindings; cursor chat and spotlight in live sessions; layers and assets panels behaviour suite and fixes; vector multi-edit and the vector edit tail; canvas navigation, guides and grids behaviour suite and fixes; shapes and vector behaviour suite and fixes; paint and effects behaviour suite and fixes; frames, groups, sections and masks behaviour suite and fixes; layers panel keyboard: F2 rename, Shift+F10 context menu, F8 box selection; selection and transform behaviour suite and fixes; Display P3: gamut warning and soft-proof (true P3 blocked upstream); several windows; boolean hit testing on the result, group drags, frame outlines and slices; outlines for the selection, mask outlines; arc fields, live boolean editing, shape builder on strokes, one-sided widths; fields select their text on focus; Typography spacing icons support scrubbing (#373); CSS colour names in hex fields; a rename selects the whole name, so typing replaces it; Escape or Enter after a pen path stays on the same vector (#760); IME composition kept on through idle frames of a text edit, candidates at the caret (#747); Selection colors for mixed selections and smart-selection spacing (#753); submenus with a hover delay and a safe triangle; the Actions palette's tabs, ranked search, highlight and recents; menu items that ask for a value; editor fixes from the community batches) · **Target:** Figma Design UI3 (desktop app 126.10.7) Fine canvas control is what Figma users feel first: handles, snapping, nudging, modifier keys, drag behaviour, numeric precision. This checklist covers the tools, gestures and panels. Status: @@ -227,6 +227,7 @@ This audit records candidates for subsequent fixes; their behaviour is unchanged | Date | Change | Summary | |---|---|---| +| 2026-12-03 | patch | M4: a fill or stroke whose colour is bound to a variable showed the variable's name in a chip that only had a tooltip, so changing it to another meant detaching it first or opening the section's Styles menu. A click on the chip now opens a picker to change it: for the only paint of its list the style picker the section's Styles button opens (styles and colour variables), for one of several the variable picker for that paint, and for the page background the variable picker. Both pickers mark the variable in use with a check (a library variable by the copy this file made of it), and open scrolled to it, as the style picker now opens scrolled to the style in use; they marked none before and opened at the top. Tests: `bound_paint_chip_tests` (3), `selection_colors_picker_tests::the_rows_styles_button_opens_the_style_picker_with_search_and_library_names`. | | 2026-12-03 | minor | #1563: a selected text has a font size handle on the middle of its bottom edge with the Move tool. Dragging it down makes the text bigger and up smaller, scaling it about its top-left corner as the Scale tool does, so the line height and letter spacing keep their proportion; the font size lands on whole pixels and a press without a drag changes nothing. One undo step per drag; `inspect_ui` lists it under `tool.shapeHandles` as `{kind: fontSize}`. | | 2026-12-02 | minor | M4, #1680: the corner style menu (Individual corners) has Notched beside Round, Chamfered and Concave: each corner cut out as a square of its radius. Fills, strokes, clipping and the radius fields work as for the other styles; `node.set {cornerStyle: "notch"}` from commands and MCP. | | 2026-12-02 | patch | #1569: moving layers in a heavy file re-rendered the canvas or a sprite of the layers on every pointer move. Preferences ▸ Redraw layers while dragging (`pref.liveDrag {on?}`, on by default; Shift+Cmd/Ctrl+D, which says at the bottom whether it is now on or off; a check mark in the main menu's Preferences) turned off leaves the layers where they were while a move lasts and moves only their selection outline; the canvas asks for no render until the release, when the layers are drawn at their new place. Resizing, rotating and drags that reparent stay live. FigCraft's own (61 undocumented bindings). Tests: `canvas_live_drag_tests::with_redraw_off_a_move_keeps_the_image_of_where_the_layers_were_until_it_ends`, `shift_cmd_d_turns_redrawing_while_dragging_off_and_on_and_says_which`. | From 1ea7ef55e2f2a2f12c7d2d34e667224313fc9084 Mon Sep 17 00:00:00 2001 From: bflatastic Date: Thu, 3 Dec 2026 17:20:32 +0700 Subject: [PATCH 2/4] Binding a paint colour through another key replaces its binding `fill` and `fills/0/color` name the same paint colour, but variable.bind added the new key beside the old one, so after the style picker changed a variable bound through the indexed key, a detach brought the old one back. Test: paint_reorder_tests::binding_a_paint_through_another_key_replaces_its_binding. --- crates/engine/src/cmd/styles.rs | 23 +++++++++++++++++------ crates/engine/src/paint_reorder_tests.rs | 14 ++++++++++++++ docs/ui-parity.md | 2 +- 3 files changed, 32 insertions(+), 7 deletions(-) diff --git a/crates/engine/src/cmd/styles.rs b/crates/engine/src/cmd/styles.rs index 7be329a77..c90a82ce2 100644 --- a/crates/engine/src/cmd/styles.rs +++ b/crates/engine/src/cmd/styles.rs @@ -926,20 +926,31 @@ pub(crate) fn bind_variable(cmd: &str, doc: &mut Document, ids: &[NodeId], field } } } + use super::lists::{BoundList, list_binding, paint_binding_key}; + // `fill` and `fills/0/color` name the same paint colour: binding through one replaces the other. + let slot = match list_binding(field) { + Some((l @ (BoundList::Fills | BoundList::Strokes), i, "color")) => Some((l == BoundList::Fills, i)), + _ => None, + }; for i in ids { let n = doc.get_mut(*i)?; + let prev = match slot { + Some((fills, idx)) => paint_binding_key(n, fills, idx).and_then(|k| n.bound.get(k)).cloned(), + None => n.bound.get(field).cloned(), + }; + let had = match slot { + Some((fills, idx)) => unbind_slot(n, fills, idx), + None => n.bound.remove(field).is_some(), + }; match vid { Some(v) => { - if n.bound.get(field).map(String::as_str) != Some(v) { + if prev.as_deref() != Some(v) { rebind_paint_alpha(&mut n.fills, &mut n.strokes, field, true); } n.bound.insert(field.to_string(), v.to_string()); } - None => { - if n.bound.remove(field).is_some() { - rebind_paint_alpha(&mut n.fills, &mut n.strokes, field, false); - } - } + None if had => rebind_paint_alpha(&mut n.fills, &mut n.strokes, field, false), + None => {} } } Ok(()) diff --git a/crates/engine/src/paint_reorder_tests.rs b/crates/engine/src/paint_reorder_tests.rs index 9db24c8f3..b3b7083ff 100644 --- a/crates/engine/src/paint_reorder_tests.rs +++ b/crates/engine/src/paint_reorder_tests.rs @@ -288,3 +288,17 @@ fn instance_properties_bind_to_boolean_and_string_variables() { ex(&mut s, "component.detach", json!({"ids": [i]})); assert!(node(&s, i).bound.is_empty()); } + +#[test] +fn binding_a_paint_through_another_key_replaces_its_binding() { + let mut s = Session::new(); + vars(&mut s); + ex(&mut s, "variable.create", json!({"collection": "T", "name": "accent", "type": "color", "value": "#00FF00"})); + let r = rect(&mut s); + ex(&mut s, "variable.bind", json!({"ids": [r], "field": "fills/0/color", "variable": "brand"})); + // `fill` names the same paint: the change replaces the indexed binding, and a detach leaves none. + ex(&mut s, "variable.bind", json!({"ids": [r], "field": "fill", "variable": "accent"})); + assert_eq!(node(&s, r).bound.len(), 1); + ex(&mut s, "variable.bind", json!({"ids": [r], "field": "fill", "variable": null})); + assert!(node(&s, r).bound.is_empty(), "the old binding is gone too: {:?}", node(&s, r).bound); +} diff --git a/docs/ui-parity.md b/docs/ui-parity.md index 2b3758870..703407bfd 100644 --- a/docs/ui-parity.md +++ b/docs/ui-parity.md @@ -227,7 +227,7 @@ This audit records candidates for subsequent fixes; their behaviour is unchanged | Date | Change | Summary | |---|---|---| -| 2026-12-03 | patch | M4: a fill or stroke whose colour is bound to a variable showed the variable's name in a chip that only had a tooltip, so changing it to another meant detaching it first or opening the section's Styles menu. A click on the chip now opens a picker to change it: for the only paint of its list the style picker the section's Styles button opens (styles and colour variables), for one of several the variable picker for that paint, and for the page background the variable picker. Both pickers mark the variable in use with a check (a library variable by the copy this file made of it), and open scrolled to it, as the style picker now opens scrolled to the style in use; they marked none before and opened at the top. Tests: `bound_paint_chip_tests` (3), `selection_colors_picker_tests::the_rows_styles_button_opens_the_style_picker_with_search_and_library_names`. | +| 2026-12-03 | patch | M4: a fill or stroke whose colour is bound to a variable showed the variable's name in a chip that only had a tooltip, so changing it to another meant detaching it first or opening the section's Styles menu. A click on the chip now opens a picker to change it: for the only paint of its list the style picker the section's Styles button opens (styles and colour variables), for one of several the variable picker for that paint, and for the page background the variable picker. Both pickers mark the variable in use with a check (a library variable by the copy this file made of it), and open scrolled to it, as the style picker now opens scrolled to the style in use; they marked none before and opened at the top. Binding a paint's colour through `fill` replaces a binding made through `fills/0/color` (and the reverse), so a detach afterwards no longer brings the old variable back. Tests: `bound_paint_chip_tests` (3), `selection_colors_picker_tests::the_rows_styles_button_opens_the_style_picker_with_search_and_library_names`. | | 2026-12-03 | minor | #1563: a selected text has a font size handle on the middle of its bottom edge with the Move tool. Dragging it down makes the text bigger and up smaller, scaling it about its top-left corner as the Scale tool does, so the line height and letter spacing keep their proportion; the font size lands on whole pixels and a press without a drag changes nothing. One undo step per drag; `inspect_ui` lists it under `tool.shapeHandles` as `{kind: fontSize}`. | | 2026-12-02 | minor | M4, #1680: the corner style menu (Individual corners) has Notched beside Round, Chamfered and Concave: each corner cut out as a square of its radius. Fills, strokes, clipping and the radius fields work as for the other styles; `node.set {cornerStyle: "notch"}` from commands and MCP. | | 2026-12-02 | patch | #1569: moving layers in a heavy file re-rendered the canvas or a sprite of the layers on every pointer move. Preferences ▸ Redraw layers while dragging (`pref.liveDrag {on?}`, on by default; Shift+Cmd/Ctrl+D, which says at the bottom whether it is now on or off; a check mark in the main menu's Preferences) turned off leaves the layers where they were while a move lasts and moves only their selection outline; the canvas asks for no render until the release, when the layers are drawn at their new place. Resizing, rotating and drags that reparent stay live. FigCraft's own (61 undocumented bindings). Tests: `canvas_live_drag_tests::with_redraw_off_a_move_keeps_the_image_of_where_the_layers_were_until_it_ends`, `shift_cmd_d_turns_redrawing_while_dragging_off_and_on_and_says_which`. | From 0efa8a6b709c8a4d0f1410b88843fbc1bb099b6c Mon Sep 17 00:00:00 2001 From: bflatastic Date: Thu, 3 Dec 2026 17:22:52 +0700 Subject: [PATCH 3/4] M1: + on a mixed fill or stroke selection replaces it with one shared paint (#2973) fill.add and stroke.add take `replace`: the new paint takes the place of every paint on each layer, their bindings going with them, and every layer gets the same default (the first layer's). The Design panel's + passes it when the selection's paints are mixed and opens the picker on that paint, so it edits the whole selection at once. One undo step restores the old paints. --- crates/engine/src/binding_lists_tests.rs | 14 +++++++ crates/engine/src/cmd/edit.rs | 6 ++- crates/engine/src/cmd/edit/props.rs | 19 +++++++++- crates/ui-egui/src/panel_remove_tests.rs | 42 ++++++++++++++------- crates/ui-egui/src/panels/right/paints.rs | 10 ++--- crates/ui-egui/src/text_mixed_fill_tests.rs | 8 ++-- docs/ui-parity.md | 2 +- 7 files changed, 74 insertions(+), 27 deletions(-) diff --git a/crates/engine/src/binding_lists_tests.rs b/crates/engine/src/binding_lists_tests.rs index 5886a5484..015b3fe86 100644 --- a/crates/engine/src/binding_lists_tests.rs +++ b/crates/engine/src/binding_lists_tests.rs @@ -240,3 +240,17 @@ fn paints_set_with_their_binding_in_the_same_call_keep_it() { assert_eq!(bound(&s, r), [("fill".to_string(), brand)]); assert_eq!(fill_hex(&s, r), ["FF0000"], "the binding given with the paints applies"); } + +/// `fill.add` with `replace` (the panel's + on mixed fills, #2973): the old fills go with their +/// bindings, and a frame and a shape get the same one default, so the selection shares it. +#[test] +fn a_replacing_fill_takes_the_old_fills_and_their_bindings() { + let (mut s, r) = setup(); + let f = id(s.execute("node.create", &json!({"type": "frame", "x": 20, "y": 0, "width": 10, "height": 10})).unwrap()); + ex(&mut s, "variable.bind", json!({"ids": [r], "field": "fill", "variable": "brand"})); + ex(&mut s, "fill.add", json!({"ids": [r, f], "replace": true})); + assert!(bound(&s, r).is_empty(), "the binding goes with its fill"); + let fills = |n| s.doc().unwrap().node(n).unwrap().fills.clone(); + assert_eq!(fills(r).len(), 1); + assert_eq!(fills(r), fills(f), "the frame and the shape share one paint"); +} diff --git a/crates/engine/src/cmd/edit.rs b/crates/engine/src/cmd/edit.rs index 59537faa7..c691e7280 100644 --- a/crates/engine/src/cmd/edit.rs +++ b/crates/engine/src/cmd/edit.rs @@ -384,11 +384,13 @@ pub fn specs() -> Vec { spec!( "fill.add", "Add fill", - "{ids?, paint? | color? (default #D9D9D9 or white for frames), regions? (a vector's regions by index: their own fills, as the regions selected in edit mode)}", + "{ids?, paint? | color? (default #D9D9D9 or white for frames), replace? (true: it replaces every fill), regions? (a vector's regions by index: their own fills, as the regions selected in edit mode)}", true, |s, p| paint_list(s, p, true, true) ), - spec!("stroke.add", "Add stroke", "{ids?, paint? | color? (default black)}", true, |s, p| paint_list(s, p, false, true)), + spec!("stroke.add", "Add stroke", "{ids?, paint? | color? (default black), replace? (true: it replaces every stroke)}", true, |s, p| { + paint_list(s, p, false, true) + }), spec!("fill.remove", "Remove fill", "{ids?, index, regions?}", true, |s, p| paint_list(s, p, true, false)), spec!("stroke.remove", "Remove stroke", "{ids?, index}", true, |s, p| paint_list(s, p, false, false)), spec!( diff --git a/crates/engine/src/cmd/edit/props.rs b/crates/engine/src/cmd/edit/props.rs index c9fc8fcc1..fd3a32019 100644 --- a/crates/engine/src/cmd/edit/props.rs +++ b/crates/engine/src/cmd/edit/props.rs @@ -389,6 +389,8 @@ pub(super) fn paint_list(s: &mut Session, p: &Value, fills: bool, add: bool) -> let cmd = if fills { "fill" } else { "stroke" }; let ids = req_targets(cmd, s, p)?; let index = if add || get(p, "index").is_none() { None } else { Some(req_index(cmd, p, "index")?) }; + // `replace`: the new paint takes the place of every paint (a mixed selection's + in the panel). + let replace = add && boolean(p, "replace").unwrap_or(false); if let Some((id, regions)) = fill_regions(s, cmd, p, &ids)?.filter(|_| fills) { let paint = match get(p, "paint").or_else(|| get(p, "color")) { Some(v) => Some(paint_of(v).ok_or_else(|| bad(cmd, "invalid paint"))?), @@ -396,6 +398,9 @@ pub(super) fn paint_list(s: &mut Session, p: &Value, fills: bool, add: bool) -> }; edit_region_fills(s.doc_mut()?, id, ®ions, |list| { if add { + if replace { + list.clear(); + } list.push(paint.clone().unwrap_or_else(|| figcraft_color::Paint::solid(figcraft_color::Color::DEFAULT_SHAPE))); } else { let idx = index.unwrap_or(list.len().saturating_sub(1)); @@ -408,6 +413,8 @@ pub(super) fn paint_list(s: &mut Session, p: &Value, fills: bool, add: bool) -> return ok(); } let doc = s.doc_mut()?; + // A replacing default is the first layer's, so every layer shares the one paint. + let first_frame = ids.first().and_then(|i| doc.node(*i)).is_some_and(|n| n.kind.is_frame_like()); for i in ids { let n = doc.get_mut(i)?; // A removal that names no paint among the rows shown changes nothing, the characters' own @@ -422,7 +429,12 @@ pub(super) fn paint_list(s: &mut Session, p: &Value, fills: bool, add: bool) -> if fills { crate::cmd::lists::take_character_fills(n); } - let frameish = n.kind.is_frame_like(); + let kind = if fills { crate::cmd::lists::BoundList::Fills } else { crate::cmd::lists::BoundList::Strokes }; + if replace { + // The replaced paints' bindings go with them. + crate::cmd::lists::remap_list_bindings(n, kind, |_| None); + } + let frameish = if replace { first_frame } else { n.kind.is_frame_like() }; let list = if fills { &mut n.fills } else { &mut n.strokes }; if add { let paint = match get(p, "paint").or_else(|| get(p, "color")) { @@ -431,11 +443,14 @@ pub(super) fn paint_list(s: &mut Session, p: &Value, fills: bool, add: bool) -> None if fills => figcraft_color::Paint::solid(figcraft_color::Color::DEFAULT_SHAPE), None => figcraft_color::Paint::solid(figcraft_color::Color::BLACK), }; + if replace { + list.clear(); + } list.push(paint); } else { let idx = index.unwrap_or(list.len().saturating_sub(1)); // The paint's colour binding goes with it; later paints' move down one. - crate::cmd::lists::remove_item(n, if fills { crate::cmd::lists::BoundList::Fills } else { crate::cmd::lists::BoundList::Strokes }, idx); + crate::cmd::lists::remove_item(n, kind, idx); } } ok() diff --git a/crates/ui-egui/src/panel_remove_tests.rs b/crates/ui-egui/src/panel_remove_tests.rs index ac1afdd1b..aeb8ce415 100644 --- a/crates/ui-egui/src/panel_remove_tests.rs +++ b/crates/ui-egui/src/panel_remove_tests.rs @@ -175,21 +175,37 @@ fn an_empty_sections_header_adds_its_item_but_a_full_one_only_adds_from_the_plus assert_eq!(u.app.session.doc().unwrap().node(r).unwrap().strokes.len(), 1); } +/// The + of a mixed selection replaces every layer's paints with one they share, opens its picker, +/// and one undo brings the old paints back (#2973). #[test] -fn adding_a_fill_to_mixed_fills_opens_no_picker() { - let mut s = Session::new(); - let a = id(s.execute("shape.rectangle", &json!({"x": 0, "y": 0, "width": 50, "height": 50})).unwrap()); - let b = id(s.execute("shape.rectangle", &json!({"x": 60, "y": 0, "width": 50, "height": 50})).unwrap()); - s.execute("fill.add", &json!({"ids": [b]})).unwrap(); - s.execute("select.set", &json!({"ids": [a, b]})).unwrap(); - let mut u = Ui::new(s); - u.ctx.enable_accesskit(); +fn adding_a_paint_to_mixed_paints_replaces_them_with_one() { + for (fills, label) in [(true, "Add fill"), (false, "Add stroke")] { + let mut s = Session::new(); + let a = id(s.execute("shape.rectangle", &json!({"x": 0, "y": 0, "width": 50, "height": 50})).unwrap()); + let b = id(s.execute("shape.rectangle", &json!({"x": 60, "y": 0, "width": 50, "height": 50})).unwrap()); + let add = if fills { "fill.add" } else { "stroke.add" }; + s.execute(add, &json!({"ids": [a], "color": "#FF0000"})).unwrap(); + s.execute(add, &json!({"ids": [b], "color": "#00FF00"})).unwrap(); + s.execute(add, &json!({"ids": [b], "color": "#0000FF"})).unwrap(); + s.execute("select.set", &json!({"ids": [a, b]})).unwrap(); + let paints = |s: &Session, n: NodeId| { + let n = s.doc().unwrap().node(n).unwrap(); + if fills { n.fills.clone() } else { n.strokes.clone() } + }; + let before = (paints(&s, a), paints(&s, b)); + let mut u = Ui::new(s); + u.ctx.enable_accesskit(); - let add_fill = button(&mut u, "Add fill"); - click(&mut u, add_fill); - let doc = u.app.session.doc().unwrap(); - assert_eq!((doc.node(a).unwrap().fills.len(), doc.node(b).unwrap().fills.len()), (2, 3)); - assert_eq!(u.app.ui.picker, None); + let add_button = button(&mut u, label); + click(&mut u, add_button); + let (pa, pb) = (paints(&u.app.session, a), paints(&u.app.session, b)); + assert_eq!(pa.len(), 1, "{label}: one paint is left"); + assert_eq!(pa, pb, "{label}: the layers share it"); + assert_eq!(u.app.ui.picker, Some(PickerTarget::Paint { fills, index: 0, ids: vec![a, b] }), "{label}: its picker opens"); + + u.app.run("edit.undo", json!({})); + assert_eq!((paints(&u.app.session, a), paints(&u.app.session, b)), before, "{label}: one undo restores them"); + } } /// The shared popover's closing reaches the colour picker: a press on the canvas closes it. diff --git a/crates/ui-egui/src/panels/right/paints.rs b/crates/ui-egui/src/panels/right/paints.rs index 148a964f3..bde9b22b1 100644 --- a/crates/ui-egui/src/panels/right/paints.rs +++ b/crates/ui-egui/src/panels/right/paints.rs @@ -370,11 +370,11 @@ pub(crate) fn paints(app: &mut FigApp, ui: &mut Ui, doc: &Document, sel: &[NodeI let (clicked, header) = widgets::section_header_resp(ui, title, &buttons, empty); if let Some(i) = clicked { if buttons.get(i).is_some_and(|(icon, _)| *icon == Icon::Plus) { - // The new paint goes on top; open its picker. A mixed selection has no one index to edit. - if app.run(if fills { "fill.add" } else { "stroke.add" }, json!({"ids": ids})).is_some() - && let Some(l) = &list - { - app.open_picker(crate::colorpicker::PickerTarget::Paint { fills, index: l.len(), ids: ids.clone() }, Some(header.rect)); + // The new paint goes on top and its picker opens; on a mixed selection it replaces every + // layer's paints, so the one paint they then share is edited across them all (#2973). + if app.run(if fills { "fill.add" } else { "stroke.add" }, json!({"ids": ids, "replace": list.is_none()})).is_some() { + let index = list.as_ref().map_or(0, |l| l.len()); + app.open_picker(crate::colorpicker::PickerTarget::Paint { fills, index, ids: ids.clone() }, Some(header.rect)); } } else { style_picker::open(app, ui, &ids, slot); diff --git a/crates/ui-egui/src/text_mixed_fill_tests.rs b/crates/ui-egui/src/text_mixed_fill_tests.rs index b494c267d..4a2b89521 100644 --- a/crates/ui-egui/src/text_mixed_fill_tests.rs +++ b/crates/ui-egui/src/text_mixed_fill_tests.rs @@ -78,20 +78,20 @@ fn differently_coloured_characters_show_as_mixed_content_and_plus_replaces_them( let (rows, note, plus) = fill_section(&c); assert!(note, "the Fill section shows the note: {c:?}"); assert!(rows.is_empty(), "no row for the layer's own red: {rows:?}"); - // + adds a fill on top of the layer's: every character shows the layer's fills now. + // + replaces the mixed fills with one the layer and every character share (#2973). let steps = u.app.session.ds().unwrap().history.undo.len(); u.button(plus, true); u.button(plus, false); u.frame(vec![]); let n = u.app.session.doc().unwrap().node(t).unwrap().clone(); - assert_eq!(n.fills.len(), 2, "the new fill on the layer's: {:?}", n.fills); + assert_eq!(n.fills.len(), 1, "one fill replaces them: {:?}", n.fills); assert!(n.kind.text().unwrap().runs.is_empty(), "no character keeps fills of its own"); - assert!(fills_shown(&u, t).iter().all(|f| f == "FF0000+D9D9D9"), "{:?}", fills_shown(&u, t)); + assert!(fills_shown(&u, t).iter().all(|f| f == "D9D9D9"), "{:?}", fills_shown(&u, t)); assert_eq!(u.app.session.ds().unwrap().history.undo.len(), steps + 1, "one undo step"); let c = controls(&mut u); let (rows, note, _) = fill_section(&c); assert!(!note, "no note once the characters agree: {c:?}"); - assert_eq!(rows, ["D9D9D9", "FF0000"], "the new fill above the layer's red: {c:?}"); + assert_eq!(rows, ["D9D9D9"], "only the new fill: {c:?}"); } #[test] diff --git a/docs/ui-parity.md b/docs/ui-parity.md index 36693cd9c..5631dd353 100644 --- a/docs/ui-parity.md +++ b/docs/ui-parity.md @@ -35,7 +35,7 @@ interaction feel only partly compared: the interactions measured so far, case by | Colour picker models | done | Hex, RGB, HSL, HSB, LCH, OKLCH and CSS; LCH and OKLCH keep lightness and hue when a colour leaves sRGB (chroma comes down); the values typed stay while the colour is theirs (a hue typed on a grey, a chroma sRGB can't hold); CSS reads `lch()` and `oklch()` with any hue unit and `none` (`figcraft_color::{Lch, Oklch}`). Values are the stored channels read as sRGB | | Colour picker placement and dismissal | done | Opens 8 pt beside the sidebar at the opening control, lifted to fit the screen; outside presses (including the sidebar), Escape and X close it. Reopening resets a dragged position; eyedropper sampling keeps it open, and so does a drag of the open gradient's handles or stops on the canvas (#1852). | | Colour picker image well | partial | the Image tab shows a checkered placeholder and Upload from computer until there is a file (no dialog at once); an image paint shows its asset preview; a file dropped on the open picker replaces the image, keeping the fill mode, crop, position and adjustments (`image.replace`). Layers' fills and strokes only (text ranges, styles and selection colours keep Upload). The Fill and Stroke swatches take no drop: a dragged file's position isn't known, so a drop with none goes to the open picker | -| Colour picker on a new fill or stroke | done | + opens the picker on the new paint when the selection shares one paint list; on a mixed selection + adds a paint to each layer and no picker opens (#404) | +| Colour picker on a new fill or stroke | done | + opens the picker on the new paint when the selection shares one paint list; on a mixed selection + replaces every layer's paints with one shared default (`replace` on `fill.add` / `stroke.add`, one undo step) and opens its picker, so it edits the whole selection (#404, #2973) | | Colour picker contrast check | done | under the colour values of a layer's fill (or a text range's): the WCAG 2 ratio against the nearest solid colour behind the layer (a layer below it, its frame or the page), the fill composited by its alpha and opacity first; rounded down to one decimal; a check or a cross (not colour alone) for the level chosen beside it, AA by default or AAA, remembered across launches. Text needs 4.5:1 at AA and 7:1 at AAA (large text, 24 px or 18.66 px bold, 3:1 and 4.5:1); other layers 3:1 at both. Over a gradient, image or blend mode it says there is no solid colour behind instead of a number. `inspect.contrast {id, at?}` gives the same for scripts and agents (#2779) | | Fill section on a text with coloured characters | done | a text's Fill section shows what its characters show: characters coloured differently while editing are mixed content ("Click + to replace mixed content", as a mixed selection; the developer documentation's `fills`: "Text nodes can have multiple sets of fills if some characters are colored differently than others"), and characters that all share fills the layer doesn't have show those. Any layer-level fill edit (a row, its picker, +, reordering, `fill.*`, `node.set`) reaches every character, starting from the list they showed; the characters' own fills go in the same undo step; the canvas gradient and crop handles show and edit the paint the row shows, the characters' own, also when their image is already in Crop mode (`text_mixed_fill_tests`, `canvas::handles::character_fill_tests`, engine `text_fill_tests`; #1856). A range selected while editing keeps its own Fill row | | Fill, stroke and effect rows: click to highlight, Cmd/Ctrl+C, Cmd/Ctrl+V | done | a click on a row's reorder grip (left of its fields) or its background between its controls highlights it in the selected-row colour, one row at a time; Cmd/Ctrl+C (or Edit ▸ Copy) then copies that paint or effect instead of the layers (`fill.copy`, `stroke.copy`, `effect.copy`, as the row's menu does; a stroke takes its weight and settings along) and Cmd/Ctrl+V pastes it onto every selected layer (`fill.paste`, `stroke.paste`, `effect.paste`), one undo step: on top of each layer's list, or in place of the highlighted row when it is of the same kind. A copy keeps its kind: a stroke goes to the strokes and an effect to the effects whatever row is highlighted, and the last row copied is the one pasted. A solid colour also goes to the system clipboard as its hex code; a programmatic copy never writes it. A later layer copy, or text or an image copied in another app, is pasted instead; every window pastes the same copy. Escape, a press on the canvas or elsewhere in the Design panel, another selection, file or tab let the highlight go (#1494). The help center says only that a property is highlighted with a click; adding on top follows the forum's accepted answer for adding one fill without replacing the others, not an observation. Delete and Cmd/Ctrl+X still act on the layers; the keyboard alone can't highlight a row | From 96e01e8967b3fda8859a47212bd6d78beec4c6b3 Mon Sep 17 00:00:00 2001 From: bflatastic Date: Thu, 3 Dec 2026 17:32:54 +0700 Subject: [PATCH 4/4] The style picker opens at the variable in use over a linked style A paint with both a style link and a colour variable (a file can have them) opened the style picker at the style, listed above the variables, so the variable whose chip was clicked could stay out of view. The variable is now revealed when it is listed; the style otherwise. Test: bound_paint_chip_tests::with_a_style_linked_too_the_picker_opens_at_the_variable. --- crates/ui-egui/src/bound_paint_chip_tests.rs | 20 ++++++++++++++++++++ crates/ui-egui/src/panels/variable_ui.rs | 5 +++++ crates/ui-egui/src/widgets/style_picker.rs | 17 ++++++++++++++--- 3 files changed, 39 insertions(+), 3 deletions(-) diff --git a/crates/ui-egui/src/bound_paint_chip_tests.rs b/crates/ui-egui/src/bound_paint_chip_tests.rs index 0623126f7..7cd66c9c8 100644 --- a/crates/ui-egui/src/bound_paint_chip_tests.rs +++ b/crates/ui-egui/src/bound_paint_chip_tests.rs @@ -106,3 +106,23 @@ fn the_picker_opens_scrolled_to_the_variable_in_use() { assert!(top > search && bottom < search + 360.0, "the row in use is in view below the search field: {top}..{bottom}, search ends at {search}"); assert!(marked(&mut u, "text/secondary")); } + +#[test] +fn with_a_style_linked_too_the_picker_opens_at_the_variable() { + let (mut u, r) = bound_rect(1); + for i in 0..40 { + u.app.run("style.create", json!({"type": "paint", "name": format!("Swatch {i:02}"), "value": "#00ff00"})); + } + // The first style, at the list's top, links the paint while the variable stays bound to it, + // as a file can have them (the commands keep one or the other). + let v = u.app.session.doc().unwrap().node(r).unwrap().bound["fill"].clone(); + u.app.run("style.apply", json!({"ids": [r], "style": "Swatch 00", "target": "fill"})); + u.app.session.doc_mut().unwrap().get_mut(r).unwrap().bound.insert("fill".into(), v); + let n = u.app.session.doc().unwrap().node(r).unwrap().clone(); + assert!(n.styles.fill.is_some() && !n.bound.is_empty(), "both links: {:?} {:?}", n.styles.fill, n.bound); + let p = chip(&mut u, "text/secondary"); + click(&mut u, p); + u.frame(vec![]); + let (top, bottom, search) = row_under_search(&mut u, "text/secondary"); + assert!(top > search && bottom < search + 360.0, "the variable's row is in view: {top}..{bottom}, search ends at {search}"); +} diff --git a/crates/ui-egui/src/panels/variable_ui.rs b/crates/ui-egui/src/panels/variable_ui.rs index 02e2c06f7..7fd975245 100644 --- a/crates/ui-egui/src/panels/variable_ui.rs +++ b/crates/ui-egui/src/panels/variable_ui.rs @@ -76,6 +76,11 @@ pub fn ask_reveal(ctx: &egui::Context) { ctx.data_mut(|d| d.insert_temp(reveal_id(), true)); } +/// Drop a pending [`ask_reveal`], so rows drawn before the one to reveal don't take it. +pub fn cancel_reveal(ctx: &egui::Context) { + ctx.data_mut(|d| d.remove_temp::(reveal_id())); +} + /// Scroll `rect` (the row in use) to the middle of its list when the picker has just opened, at /// once rather than animated, so the list opens there. A popup's first pass only measures it, so /// the request waits for the pass that is shown. diff --git a/crates/ui-egui/src/widgets/style_picker.rs b/crates/ui-egui/src/widgets/style_picker.rs index e744471cf..2912d423a 100644 --- a/crates/ui-egui/src/widgets/style_picker.rs +++ b/crates/ui-egui/src/widgets/style_picker.rs @@ -733,10 +733,18 @@ fn listing(app: &FigApp, ui: &mut Ui, doc: &Document, p: &mut Picker, out: &mut } else { Vec::new() }; - if p.reveal { + let reveal = p.reveal; + // A popup's first pass only measures it: the shown pass asks again. + p.reveal = reveal && ui.is_sizing_pass(); + // The variable in use is revealed over the style in use (its chip opened the picker), so the + // request waits for its row, after the styles. + let reveal_var = + reveal && colors.iter().any(|(lib, _, vars)| vars.iter().any(|v| crate::variable_ui::is_current(doc, current.as_deref(), *lib, v))); + if reveal_var { + // The measuring pass's request is still pending: the style rows mustn't take it. + crate::variable_ui::cancel_reveal(ui.ctx()); + } else if reveal { crate::variable_ui::ask_reveal(ui.ctx()); - // A popup's first pass only measures it: the shown pass asks again. - p.reveal = ui.is_sizing_pass(); } egui::ScrollArea::vertical().id_salt("style_picker_scroll").max_height(320.0).show(ui, |ui| { ui.spacing_mut().item_spacing.y = 0.0; @@ -803,6 +811,9 @@ fn listing(app: &FigApp, ui: &mut Ui, doc: &Document, p: &mut Picker, out: &mut ui.add_space(6.0); caption(ui, tr("Color variables")); } + if reveal_var { + crate::variable_ui::ask_reveal(ui.ctx()); + } for (lib, c, vars) in &colors { crate::variable_ui::group_caption(ui, *lib, c); let all = lib.map_or(&doc.variables, |l| &l.doc.variables);