Merge pull request #2465 from storytold/fix/component-name-header-2347

M3: the Design panel's header names the selected component or set (#2347)
This commit is contained in:
BFlat authored and GitHub committed 2026-11-19 04:21:09 +07:00
commit 202b748083
4 files changed
+101 -7

No files matched your search

@@ -0,0 +1,46 @@
//! The Design panel's header with one component or component set selected, driven through egui
//! headless: it names the selected one ("Knapp"), not only its type (#2347). Other layers keep their
//! type ("Rectangle").
use figcraft_doc::NodeId;
use figcraft_engine::Session;
use serde_json::json;
use crate::export_preview_tests::labelled;
use crate::layers_drag_tests::Ui;
fn id(v: serde_json::Value) -> NodeId {
NodeId(v["id"].as_u64().unwrap())
}
/// The text painted in the right panel's header strip (the top of the Design tab).
fn header(u: &mut Ui) -> Vec<String> {
let right = 1440.0 - u.app.ui.right_width;
labelled(u).into_iter().filter(|(_, at)| at.x > right && at.y < 190.0).map(|(t, _)| t).collect()
}
#[test]
fn the_header_names_the_selected_component_or_set() {
let mut s = Session::new();
let f = id(s.execute("frame.create", &json!({"x": 0, "y": 0, "width": 80, "height": 40, "name": "Knapp"})).unwrap());
let c = id(s.execute("component.create", &json!({"ids": [f]})).unwrap());
let r = id(s.execute("shape.rectangle", &json!({"x": 200, "y": 0, "width": 40, "height": 40})).unwrap());
s.execute("select.set", &json!({"ids": [c]})).unwrap();
let mut u = Ui::new(s);
let shown = header(&mut u);
assert!(shown.iter().any(|t| t == "Knapp"), "the component's name: {shown:?}");
assert!(!shown.iter().any(|t| t == "Component"), "not only its type: {shown:?}");
// As a set (Add variant), it is the set's name.
u.app.run("component.addVariant", json!({"id": c}));
let set = u.app.session.doc().unwrap().node(c).unwrap().parent.unwrap();
u.app.run("node.set", json!({"ids": [set], "props": {"name": "Knappar"}}));
u.app.run("select.set", json!({"ids": [set]}));
let shown = header(&mut u);
assert!(shown.iter().any(|t| t == "Knappar"), "the set's name: {shown:?}");
// Another layer still shows its type.
u.app.run("select.set", json!({"ids": [r]}));
let shown = header(&mut u);
assert!(shown.iter().any(|t| t == "Rectangle"), "{shown:?}");
}
+2
View File
@@ -78,6 +78,8 @@ mod colorpicker_selection_tests;
#[cfg(test)]
mod comments_tests;
#[cfg(test)]
mod component_header_tests;
#[cfg(test)]
mod component_props_reorder_tests;
#[cfg(test)]
mod component_set_narrow_tests;
+51 -6
View File
@@ -17,7 +17,7 @@ use crate::i18n::{tr, trf, trn};
use crate::icons::{self, Icon};
use crate::list_drag::{ListDrag, move_flags, remove_flags};
use crate::style_picker::{self, StyleSlot};
use crate::theme::{Tokens, regular, semibold};
use crate::theme::{COMPONENT, Tokens, regular, semibold};
use crate::widgets::{self, Edit, FIELD_H, FieldEdit, Lead, PAD};
use crate::{FigApp, RightTab};
@@ -410,11 +410,36 @@ fn page_section(app: &mut FigApp, ui: &mut Ui, doc: &Document) {
crate::export_panel::page_section(app, ui, doc, page);
}
/// One component or component set selected: it goes by its name, after its icon, in the header;
/// its type shows on hover (#2347).
fn named_component<'a>(doc: &'a Document, sel: &[NodeId]) -> Option<(&'a Node, Icon)> {
let [id] = sel else { return None };
let n = doc.node(*id)?;
match n.kind {
NodeKind::Component { .. } => Some((n, Icon::Component)),
NodeKind::ComponentSet { .. } => Some((n, Icon::ComponentSet)),
_ => None,
}
}
/// The header label's hover: a component's type (and its name when cut short), else the whole
/// label when cut short.
fn label_hover(resp: egui::Response, named: Option<&Node>, shown: &str, label: &str) -> egui::Response {
match named {
Some(n) if shown != label => resp.on_hover_text(format!("{} · {label}", tr(n.kind.label()))),
Some(n) => resp.on_hover_text(tr(n.kind.label())),
None if shown != label => resp.on_hover_text(label),
None => resp,
}
}
/// Draw the selection header: type name (or Mixed), frame/group conversion, orientation
/// swap and frame presets, component/mask/boolean quick actions, and instance details.
fn header(app: &mut FigApp, ui: &mut Ui, doc: &Document, sel: &[NodeId]) {
let t = Tokens::get(ui.ctx());
let named = named_component(doc, sel);
let label = match common(doc, sel, |n| n.kind.label()) {
_ if named.is_some() => named.map(|(n, _)| n.name.clone()).unwrap_or_default(),
Some(l) if sel.len() == 1 => tr(l).to_string(),
// The plural ("Frames") is a key of its own.
Some(l) => tr(&format!("{l}s")).to_string(),
@@ -438,16 +463,36 @@ fn header(app: &mut FigApp, ui: &mut Ui, doc: &Document, sel: &[NodeId]) {
// Keep the type menu and frame actions together. A short label must not leave
// the orientation icon floating in the middle of the header.
// The handoff icon also fits beside the frame controls at the panel minimum.
let max_label_width = if is_frame { (w - 202.0).clamp(40.0, 120.0) } else { 92.0 };
let shown = if is_frame || is_group { widgets::elide_font(ui, &label, max_label_width, semibold(13.0)) } else { label.clone() };
let label_width = if is_frame || is_group { ui.painter().layout_no_wrap(shown.clone(), semibold(13.0), t.text).size().x + 28.0 } else { 120.0 };
// A name keeps clear of the three quick actions on the right.
let max_label_width = if is_frame {
(w - 202.0).clamp(40.0, 120.0)
} else if named.is_some() {
(w - 132.0).clamp(40.0, 200.0)
} else {
92.0
};
let elided = is_frame || is_group || named.is_some();
let shown = if elided { widgets::elide_font(ui, &label, max_label_width, semibold(13.0)) } else { label.clone() };
let text_width = || ui.painter().layout_no_wrap(shown.clone(), semibold(13.0), t.text).size().x;
let label_width = match named {
Some(_) => text_width() + 38.0,
None if elided => text_width() + 28.0,
None => 120.0,
};
let lr = Rect::from_min_size(pos2(r.min.x + 8.0, r.center().y - 12.0), vec2(label_width, 24.0));
let resp = ui.interact(lr, ui.scope_id().with("typedd"), Sense::click());
if resp.hovered() {
ui.painter().rect_filled(lr, CornerRadius::same(5), t.hover);
}
let resp = if shown == label { resp } else { resp.on_hover_text(&label) };
let label_rect = ui.painter().text(pos2(lr.min.x + 8.0, lr.center().y), Align2::LEFT_CENTER, &shown, semibold(13.0), t.text);
let resp = label_hover(resp, named.map(|(n, _)| n), &shown, &label);
let text_x = match named {
Some((_, icon)) => {
icons::paint(ui.painter(), Rect::from_center_size(pos2(lr.min.x + 14.0, lr.center().y), vec2(14.0, 14.0)), icon, COMPONENT);
lr.min.x + 26.0
}
None => lr.min.x + 8.0,
};
let label_rect = ui.painter().text(pos2(text_x, lr.center().y), Align2::LEFT_CENTER, &shown, semibold(13.0), t.text);
if is_frame || is_group {
icons::paint(
ui.painter(),
+2 -1
View File
@@ -1,6 +1,6 @@
# UI and interaction parity
> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-11-19 · **Change:** minor (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), 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 aLine truncated
> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-11-19 · **Change:** minor (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), 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)Line truncated
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:
@@ -211,6 +211,7 @@ This audit records candidates for subsequent fixes; their behaviour is unchanged
| Date | Change | Summary |
|---|---|---|
| 2026-11-19 | patch | M3, #2347: with one component or component set selected, the Design panel's header said only "Component" or "Component set", so the selected one's name was only in the Layers panel. It now shows the name after a component icon (cut short with an ellipsis clear of the quick actions), with the type, and the whole name when cut, on hover. Other layers keep their type. Test: `component_header_tests::the_header_names_the_selected_component_or_set`. |
| 2026-11-19 | patch | M8, #2015: dragging near the canvas edge pans the view, as measured in Figma: while a drag holds the pointer within about 15 px of the edge (or past it) the view pans toward it at 40 px/s for each px closer, up to 600 px/s at the edge, steadily while the pointer stays still; moving layers, the selection box, drawing a shape and dragging a prototype connection (a link can now reach a frame off screen). Resizing, rotating and other drags don't pan. Tests: `view_autopan_tests`, `canvas_autopan_tests`, `proto_canvas::tests`. |
| 2026-11-19 | patch | M8: a Shift-click range in the Layers panel keeps a frame and not its covered children: a range across parents selects a frame whose row is inside it, and drops the rows under that frame, as measured in Figma's web app on 2026-11-12 (Rect 4 in one frame, Shift-click Rect 2 in another: Rect 4 and the second frame, 2 selected); a range among siblings is unchanged; Cmd with Shift reduces the combined set the same way, not measured |
| 2026-11-19 | patch | M5, #2360: with a frame selected, a drag that starts on one of its children moves the frame and a click selects the child (a press on a layer inside a selected one drags the selection), as in Figma; Cmd/Ctrl, Shift and layers outside the frame are unchanged. |