mirror of
https://github.com/storytold/figcraft.git
synced 2026-11-19 00:27:49 +00:00
Merge pull request #2462 from storytold/fix/variant-own-value-2349
M3: a selected variant's property dropdown shows and sets its own value (#2349)
This commit is contained in:
5 files changed
+83
-9
No files matched your search
@@ -449,6 +449,7 @@ name = "English"
|
||||
"Default" = "Default"
|
||||
"Default content" = "Default content"
|
||||
"Default value (the top-left variant)" = "Default value (the top-left variant)"
|
||||
"This variant's value" = "This variant's value"
|
||||
"Delay" = "Delay"
|
||||
"Delete" = "Delete"
|
||||
"Delete category (its annotations stay)" = "Delete category (its annotations stay)"
|
||||
|
||||
@@ -304,6 +304,8 @@ mod variables_select_tests;
|
||||
#[cfg(test)]
|
||||
mod variables_window_resize_tests;
|
||||
#[cfg(test)]
|
||||
mod variant_own_value_tests;
|
||||
#[cfg(test)]
|
||||
mod variants_discovery_tests;
|
||||
#[cfg(test)]
|
||||
mod vector_align_tests;
|
||||
|
||||
@@ -15,7 +15,7 @@ use figcraft_doc::{Document, Node, NodeId, NodeKind, PropDef, VariableType};
|
||||
use figcraft_engine::cmd::component::{can_add_variant, can_combine_variants};
|
||||
use figcraft_engine::components::{
|
||||
PROP_BINDING, default_variant, inside_instance, instance_prop_list, owning_component, owning_instance, prop_list, slot_def, slot_edited,
|
||||
slots_of, variant_conflicts, variant_options, variant_props, variant_set,
|
||||
slots_of, variant_conflicts, variant_name, variant_options, variant_props, variant_set,
|
||||
};
|
||||
use serde_json::{Value, json};
|
||||
|
||||
@@ -37,11 +37,12 @@ pub fn instance_section(app: &mut FigApp, ui: &mut Ui, doc: &Document, sel: &[No
|
||||
match &n.kind {
|
||||
NodeKind::Instance { .. } => instance_ui(app, ui, doc, n),
|
||||
NodeKind::ComponentSet { description } => {
|
||||
properties_ui(app, ui, doc, n.id);
|
||||
properties_ui(app, ui, doc, n.id, None);
|
||||
description_ui(app, ui, n.id, description);
|
||||
}
|
||||
NodeKind::Component { description, .. } => {
|
||||
properties_ui(app, ui, doc, variant_set(doc, n.id).unwrap_or(n.id));
|
||||
let set = variant_set(doc, n.id);
|
||||
properties_ui(app, ui, doc, set.unwrap_or(n.id), set.map(|_| n.id));
|
||||
description_ui(app, ui, n.id, description);
|
||||
}
|
||||
_ => {}
|
||||
@@ -224,8 +225,8 @@ fn name_width(ui: &Ui, default_w: f32, max: f32) -> f32 {
|
||||
(ui.available_width() - default_w - BUTTON - 2.0 * widgets::GUTTER).clamp(48.0, max)
|
||||
}
|
||||
|
||||
/// Properties of a component or component set.
|
||||
fn properties_ui(app: &mut FigApp, ui: &mut Ui, doc: &Document, owner: NodeId) {
|
||||
/// Properties of a component or component set (`variant`: the set's variant that is selected).
|
||||
fn properties_ui(app: &mut FigApp, ui: &mut Ui, doc: &Document, owner: NodeId, variant: Option<NodeId>) {
|
||||
let t = Tokens::get(ui.ctx());
|
||||
let is_set = matches!(doc.node(owner).map(|n| &n.kind), Some(NodeKind::ComponentSet { .. }));
|
||||
// Shared (non-variant) properties live on every variant; read them from the first.
|
||||
@@ -271,6 +272,9 @@ fn properties_ui(app: &mut FigApp, ui: &mut Ui, doc: &Document, owner: NodeId) {
|
||||
} else {
|
||||
Default::default()
|
||||
};
|
||||
// A selected variant's dropdowns show and set its own values (#2349); the set's, its default.
|
||||
let own = variant.and_then(|v| doc.node(v)).map(|n| (n.id, variant_props(&n.name)));
|
||||
let order: Vec<String> = variants.iter().map(|(k, _)| k.clone()).collect();
|
||||
// Variant properties: name, values (the matrix), add value, delete. Dragged by their left
|
||||
// margin to reorder them (only among themselves: the shared ones keep the engine's order).
|
||||
let mut drag = ListDrag::in_order(ui, ("variant_props", owner));
|
||||
@@ -286,12 +290,22 @@ fn properties_ui(app: &mut FigApp, ui: &mut Ui, doc: &Document, owner: NodeId) {
|
||||
if let Some(nn) = widgets::text_field(ui, Id::unique(("vprop_name", owner, k.as_str())), k, name_w, tr("Name")) {
|
||||
app.run("component.editProperty", json!({"id": owner, "name": k, "newName": nn}));
|
||||
}
|
||||
let def = defaults.get(k).or(vals.first()).cloned().unwrap_or_default();
|
||||
let resp = widgets::dropdown(ui, &def, DEFAULT_W, None).on_hover_text(tr("Default value (the top-left variant)"));
|
||||
let def = own.as_ref().map_or(&defaults, |(_, pairs)| pairs).get(k).or(vals.first()).cloned().unwrap_or_default();
|
||||
let hint = if own.is_some() { tr("This variant's value") } else { tr("Default value (the top-left variant)") };
|
||||
let resp = widgets::dropdown(ui, &def, DEFAULT_W, None).on_hover_text(hint);
|
||||
menu_popup(&resp).show(|ui| {
|
||||
for v in vals {
|
||||
if menu_item(ui, v, "") {
|
||||
app.run("component.editProperty", json!({"id": owner, "name": k, "default": v}));
|
||||
match &own {
|
||||
Some((id, pairs)) => {
|
||||
let mut pairs = pairs.clone();
|
||||
pairs.insert(k.clone(), v.clone());
|
||||
app.run("node.set", json!({"ids": [id], "props": {"name": variant_name(&pairs, &order)}}));
|
||||
}
|
||||
None => {
|
||||
app.run("component.editProperty", json!({"id": owner, "name": k, "default": v}));
|
||||
}
|
||||
}
|
||||
ui.close();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
//! A selected variant's property dropdowns in the Design panel, driven through egui headless: they
|
||||
//! show the variant's own values, and choosing one renames that variant only. The set's default
|
||||
//! (and so the variants' places) stays (#2349).
|
||||
|
||||
use egui::accesskit::{Node, Role};
|
||||
use figcraft_doc::NodeId;
|
||||
use figcraft_engine::Session;
|
||||
use serde_json::json;
|
||||
|
||||
use crate::component_swap_default_tests::{centre, click, tree};
|
||||
use crate::layers_drag_tests::Ui;
|
||||
|
||||
fn id(v: serde_json::Value) -> NodeId {
|
||||
NodeId(v["id"].as_u64().unwrap())
|
||||
}
|
||||
|
||||
fn combos(nodes: &[Node]) -> Vec<String> {
|
||||
nodes.iter().filter(|n| n.role() == Role::ComboBox).filter_map(|n| n.value().map(str::to_string)).collect()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_selected_variants_dropdown_shows_and_sets_its_own_value() {
|
||||
let mut s = Session::new();
|
||||
let mut variants = Vec::new();
|
||||
for (k, name) in ["Looking=Top right, Size=S", "Looking=Down left, Size=S", "Looking=Top right, Size=L"].iter().enumerate() {
|
||||
let f = id(s.execute("frame.create", &json!({"x": 0, "y": 20 + k * 44, "width": 80, "height": 30, "name": name})).unwrap());
|
||||
variants.push(id(s.execute("component.create", &json!({"ids": [f]})).unwrap()));
|
||||
}
|
||||
id(s.execute("component.combineVariants", &json!({"ids": variants})).unwrap());
|
||||
let down = variants[1];
|
||||
s.execute("select.set", &json!({"ids": [down]})).unwrap();
|
||||
let mut u = Ui::new(s);
|
||||
u.ctx.enable_accesskit();
|
||||
let place = |u: &Ui| variants.iter().map(|v| u.app.session.doc().unwrap().world_bounds(*v).unwrap().y0).collect::<Vec<_>>();
|
||||
let before = place(&u);
|
||||
|
||||
// The dropdowns show this variant's values, not the default's (Top right, S).
|
||||
let nodes = tree(&mut u);
|
||||
let shown = combos(&nodes);
|
||||
assert!(shown.contains(&"Down left".to_string()) && shown.contains(&"S".to_string()), "the variant's own values: {shown:?}");
|
||||
assert!(!shown.contains(&"Top right".to_string()), "not the set's default: {shown:?}");
|
||||
|
||||
// Choosing L for Size renames this variant; the others and every place stay.
|
||||
let size = nodes.iter().find(|n| n.role() == Role::ComboBox && n.value() == Some("S")).expect("the Size dropdown");
|
||||
click(&mut u, centre(size));
|
||||
let nodes = tree(&mut u);
|
||||
let l = nodes
|
||||
.iter()
|
||||
.find(|n| n.label() == Some("L") && !matches!(n.role(), Role::ComboBox | Role::TextInput) && n.bounds().is_some())
|
||||
.expect("L in the menu");
|
||||
click(&mut u, centre(l));
|
||||
let doc = u.app.session.doc().unwrap();
|
||||
let names: Vec<&str> = variants.iter().map(|v| doc.node(*v).unwrap().name.as_str()).collect();
|
||||
assert_eq!(names, ["Looking=Top right, Size=S", "Looking=Down left, Size=L", "Looking=Top right, Size=L"]);
|
||||
assert_eq!(place(&u), before, "no variant moves");
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
# Components, variants, styles and variables parity
|
||||
|
||||
> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-11-18 · **Change:** minor (library analytics count insertions and detachments of styles and variables; combining components gives every variant the properties any of them had; renaming a variable group to a path with `/` nests it under a parent group instead of turning the slash into a hyphen (#2353); a group's context menu in the Local variables window has Duplicate group, a copy named after it plus " 2" holding a copy of every variable, in one undo step (#2084); pages take a variable mode: with nothing selected the Design panel's Page section shows a Variable modes section, Auto or a mode of each collection that has more than one, as the help center says ("Apply variable mode" in the Page section of the right sidebar) (#2215); a text style binds a number variable to its weight (#2174); an instance lists only the properties its variant's layers use and long property names are cut to one line (#2022); with several layers selected the Design panel header's component button offers Create multiple components (#2088); the Local variables window selects several variables (click, Shift+click for a range, Cmd/Ctrl+click to toggle, Escape to clear) and delete, move to a group and scope act on the selected local variables in one undo step (#2002); text styles carry paragraph spacing and indent, the list style and the OpenType features, as the Supported in text styles table of Create and apply text styles says (#1829); a layer's effect binding takes only a field its effect has; Go to main component on an instance of a library component opens the library file in a tab and selects the main there; glass effects take variables; Delete on a layer inside an instance hides it as an override instead of being refused, as the help center says: "Figma will only toggle the layer's visibility instead of removing it"; library analytics list how many layers and files use each style and variable; SwiftUI and Compose code names a bound variable by its iOS or Android code syntax; library analytics count insertions and show insertions and detachments over the past 30 days, 90 days or year; a collection of this file can be extended (Extend collection on its row, `variable.extendCollection`), its extension following its edits at once, and extended collections extend again in the file; a typed or stored variable, collection or mode id names only the object with that id (#1613); colour variables can be calculated from other colours per mode — `{alpha}` replaces a colour's alpha, `{mix}` blends two — and follow them (#1280); stored variable and collection references keep their identity when another object is named like their id (follow-up to #1542); a component set's property rows fit the 240 px right panel: variant values wrap two to a line there and every + and − stays in view; opening a file contacts no team library server it names until you check it (#1097); an explicit variables file path (`variable.import`, the `variables` of `file.open` and `file.import`) is refused past 256 MiB or when it isn't a regular file, as the sibling `variables.json` already was (part of #1114); component properties keep the order they were made in when one is renamed, and Make slot asks for the slot's name first (#1536, #1537); components can't contain their own instances, directly or through others (#1084); the instance-swap menus have a search field (#1338); an instance-swap property's default menu scrolls (#1338); variables on a text style's fields from the style editor; instance-swap properties in the component playground; duplicating or Alt-dragging a main component makes an instance of it (#892); a bound colour variable's alpha applies once (#802); variables import reads `variables` outside `meta` and warns when it imports none (#790); variant properties reorder by drag; library files saved right after a read are read again; Hide when publishing note corrected; size and resizing overrides of layers inside instances (#731); variables export in the browser as a download; core editor leftovers: component playground, variables inside styles; layers and assets panels behaviour suite and fixes; extended collections tail; styles and variables behaviour suite and fixes; components behaviour suite and fixes; team libraries on the server, library usage and swapping a library; extended collections, variables import/export, gradient stops and variant properties bound to variables) · **Target:** Figma Design (desktop app 126.10.7)
|
||||
> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-11-19 · **Change:** minor (with a variant selected, its property dropdowns show its own values and choosing one renames only that variant, instead of setting the set's default and moving the variants (#2349); library analytics count insertions and detachments of styles and variables; combining components gives every variant the properties any of them had; renaming a variable group to a path with `/` nests it under a parent group instead of turning the slash into a hyphen (#2353); a group's context menu in the Local variables window has Duplicate group, a copy named after it plus " 2" holding a copy of every variable, in one undo step (#2084); pages take a variable mode: with nothing selected the Design panel's Page section shows a Variable modes section, Auto or a mode of each collection that has more than one, as the help center says ("Apply variable mode" in the Page section of the right sidebar) (#2215); a text style binds a number variable to its weight (#2174); an instance lists only the properties its variant's layers use and long property names are cut to one line (#2022); with several layers selected the Design panel header's component button offers Create multiple components (#2088); the Local variables window selects several variables (click, Shift+click for a range, Cmd/Ctrl+click to toggle, Escape to clear) and delete, move to a group and scope act on the selected local variables in one undo step (#2002); text styles carry paragraph spacing and indent, the list style and the OpenType features, as the Supported in text styles table of Create and apply text styles says (#1829); a layer's effect binding takes only a field its effect has; Go to main component on an instance of a library component opens the library file in a tab and selects the main there; glass effects take variables; Delete on a layer inside an instance hides it as an override instead of being refused, as the help center says: "Figma will only toggle the layer's visibility instead of removing it"; library analytics list how many layers and files use each style and variable; SwiftUI and Compose code names a bound variable by its iOS or Android code syntax; library analytics count insertions and show insertions and detachments over the past 30 days, 90 days or year; a collection of this file can be extended (Extend collection on its row, `variable.extendCollection`), its extension following its edits at once, and extended collections extend again in the file; a typed or stored variable, collection or mode id names only the object with that id (#1613); colour variables can be calculated from other colours per mode — `{alpha}` replaces a colour's alpha, `{mix}` blends two — and follow them (#1280); stored variable and collection references keep their identity when another object is named like their id (follow-up to #1542); a component set's property rows fit the 240 px right panel: variant values wrap two to a line there and every + and − stays in view; opening a file contacts no team library server it names until you check it (#1097); an explicit variables file path (`variable.import`, the `variables` of `file.open` and `file.import`) is refused past 256 MiB or when it isn't a regular file, as the sibling `variables.json` already was (part of #1114); component properties keep the order they were made in when one is renamed, and Make slot asks for the slot's name first (#1536, #1537); components can't contain their own instances, directly or through others (#1084); the instance-swap menus have a search field (#1338); an instance-swap property's default menu scrolls (#1338); variables on a text style's fields from the style editor; instance-swap properties in the component playground; duplicating or Alt-dragging a main component makes an instance of it (#892); a bound colour variable's alpha applies once (#802); variables import reads `variables` outside `meta` and warns when it imports none (#790); variant properties reorder by drag; library files saved right after a read are read again; Hide when publishing note corrected; size and resizing overrides of layers inside instances (#731); variables export in the browser as a download; core editor leftovers: component playground, variables inside styles; layers and assets panels behaviour suite and fixes; extended collections tail; styles and variables behaviour suite and fixes; components behaviour suite and fixes; team libraries on the server, library usage and swapping a library; extended collections, variables import/export, gradient stops and variant properties bound to variables) · **Target:** Figma Design (desktop app 126.10.7)
|
||||
|
||||
Design systems are why teams adopt Figma. **Components: breadth ~96%, ready ~72%. Styles and
|
||||
variables: breadth ~95%, ready ~76% (estimated).** QA'd with a synthetic design system of ~300
|
||||
@@ -80,6 +80,7 @@ updates with overrides kept: `library_tests.rs`, `components_scale_tests.rs`.
|
||||
|
||||
| Date | Change | Summary |
|
||||
|---|---|---|
|
||||
| 2026-11-19 | patch | M3, #2349: with one variant of a set selected, the Design panel's variant property dropdowns showed the set's default values, and choosing a value set the default, so the variants swapped places. They now show the selected variant's own values (hover: "This variant's value"), and choosing one renames that variant only; with the set selected they still set its default. Test: `variant_own_value_tests::a_selected_variants_dropdown_shows_and_sets_its_own_value`. Grade unchanged. |
|
||||
| 2026-11-18 | minor | M3, gap 10: library analytics count insertions and detachments of styles and variables. Applying one, or copying or duplicating content that uses it, inserts it; the Detach button detaches it; an instance counts as its component alone. Show usage and `library.usage` give them per style and variable over the chosen period. Modes aren't counted. Numbers unchanged. Tests: `library_asset_counts_tests`, `library_assets_tests`. |
|
||||
| 2026-11-18 | patch | M3: Combine as variants gives every variant the component properties any of the components had (as a property added to a set goes to all its variants); a property made on one component before combining was missing from the others, so their layers couldn't be bound to it and an instance switched to them dropped its value. A variant with a property of the same name keeps its own. Tests: `variant_shared_props_tests`. |
|
||||
| 2026-11-18 | patch | M3, #2368: a text field that isn't being edited ends a value too long for it with an ellipsis and shows the whole value on hover (a secret field shows none), so the variant value "Down left" no longer reads "Down lef"; screen readers and editing keep the whole value (`field_ellipsis_tests`). Grade unchanged. |
|
||||
|
||||
Reference in new issue
Block a user