diff --git a/crates/ui-egui/src/canvas/drag_sprite.rs b/crates/ui-egui/src/canvas/drag_sprite.rs index 17f0ab7c3..83efb52e8 100644 --- a/crates/ui-egui/src/canvas/drag_sprite.rs +++ b/crates/ui-egui/src/canvas/drag_sprite.rs @@ -21,7 +21,7 @@ use std::sync::{Arc, Weak}; use egui::{Color32, Rect, pos2}; use figcraft_color::BlendMode; -use figcraft_doc::{Document, NodeId, NodeKind}; +use figcraft_doc::{Document, EffectKind, NodeId, NodeKind}; use web_time::Instant; use super::{CanvasState, FigApp}; @@ -242,11 +242,16 @@ fn ordinary(b: BlendMode) -> bool { } /// Whether layer `id` can be drawn apart from the rest: it blends normally and what it sits in is -/// plain (its own effects are drawn with it). +/// plain (its own effects are drawn with it, unless a shadow of it blends by another mode with +/// what lies beneath, which the sprite doesn't hold). fn plain(doc: &Document, id: NodeId, clip: &mut Option) -> bool { let Some(n) = doc.node(id) else { return false }; // Its own effects are drawn into the sprite (backdrop ones read where it is: see [`Live`]). - if !ordinary(n.blend) || n.is_mask { + let blended_shadow = n + .effects + .iter() + .any(|e| e.visible && matches!(&e.kind, EffectKind::DropShadow(s) | EffectKind::InnerShadow(s) if !ordinary(s.blend) && s.color.a > 0.0)); + if !ordinary(n.blend) || n.is_mask || blended_shadow { return false; } if n.parent.and_then(|p| doc.node(p)).is_none() { @@ -516,6 +521,24 @@ mod plain_tests { assert!(super::plan(&ctx, &base, &[sec], of, 1.0, 1.0, 4096, 1e9).is_none(), "dark: the canvas draws its dark tones"); } + #[test] + fn a_layer_whose_shadow_blends_by_another_mode_is_not_plain() { + // A multiply shadow darkens what lies under it, which the sprite's transparent surface lacks. + let mut s = Session::new(); + let r = rect(&mut s, 0.0); + let mut doc = s.doc().unwrap().clone(); + for e in [figcraft_doc::Effect::drop_shadow(), figcraft_doc::Effect::inner_shadow()] { + doc.node_mut(r).unwrap().effects = vec![e]; + assert!(plain(&doc, r, &mut None), "a normal shadow is drawn with the layer"); + if let figcraft_doc::EffectKind::DropShadow(sh) | figcraft_doc::EffectKind::InnerShadow(sh) = + &mut doc.node_mut(r).unwrap().effects[0].kind + { + sh.blend = figcraft_color::BlendMode::Multiply; + } + assert!(!plain(&doc, r, &mut None), "a multiply shadow keeps the old way"); + } + } + #[test] fn a_glass_drags_as_a_sprite_but_not_over_a_section_on_a_dark_interface() { // #2853: the glass is drawn into the sprite from the page under it, which on a dark diff --git a/docs/ui-parity.md b/docs/ui-parity.md index edc183a08..deb548f83 100644 --- a/docs/ui-parity.md +++ b/docs/ui-parity.md @@ -72,7 +72,7 @@ interaction feel only partly compared: the interactions measured so far, case by | Enter with a shape or frame tool chosen | done | places what a click makes (100×100, lines 100 long, sections 400×300) in the middle of the view, selected (`tool.place`); from the toolbar, Enter on the chosen tool. With nothing selected, the arrows first show a crosshair in the middle of the view and then move it by the nudge amounts (`tool.crosshair`; Shift the large one), and Enter places there; Escape or a tool change takes it away ("Use the arrow keys to activate the crosshair cursor. It will appear in the middle of the viewport indicating where the new object will be placed", Accessibility at Figma; #1839) | | Alt-drag duplicate | done | the copy snaps to the layer it came from too (edges, centres, equal spacing); Duplicate (Cmd+D) then repeats the copy's move and rotation (the move of its centre in the page frame, then the turn about the copy's own centre, or the selection's centre for several layers; not its size), also after a Duplicate whose copy was moved, as long as the copies stay selected and the selection hasn't changed (measured in Figma's web app, 2026-11-12); Alt going down or up mid-drag turns the move into a copy or back to the original, with Shift a copy kept to one axis (`alt_pressed_during_a_drag_turns_the_move_into_a_copy`, `alt_shift_drag_on_a_selected_layer_duplicates_it`; measured in Figma's web app, 2026-11-08) | | Drag threshold; double-click into groups and text | done | a press moves or resizes only once the pointer has travelled 3 px on screen, so a click or double-click made with an unsteady hand drags nothing; a double-click goes one level into a group and the next one edits the text under it, wherever on the text it lands, with all of it selected (a double-click in the text being edited selects the word) (`double_click_tests`); Enter on a selected text does the same (all of it selected, typing replaces it) and Escape leaves editing with the layer still selected (`text_enter_tests`) | -| A dragged layer moves with its outline | partial | #2033: the canvas image is the last render the worker finished, so a drag's content trailed its outline by a render per pointer move (63 ms, about 3.6 frames, and 150 px on screen with drop shadows on 200 layers). While a gesture only translates plain layers (Normal or pass-through blend, no effects above them, not masks, not in a boolean group or beside a mask, no ancestor under 100 percent opacity; their own effects and their children's are drawn into the sprite) the layers are rendered once into a texture of their own (the sprite), the base is rendered once without them from the document the drag started from and then asks for no more renders, and the sprite is drawn each frame at the same shifted place as the selection outline. #2853: a background blur or glass in the sprite reads what lies under it where it is now: a thread of the sprite's own renders it again from the start document for the latest shift, while the sprite keeps moving with the outline every frame and shows the newest of those renders (a glass pane over stripes, 600 × 360 px, debug build: the canvas showed 10 to 20 new images a second during the drag, about 20 ms of render each, and now renders nothing until the drop, the pane following the pointer every frame). On release, Escape or a zoom change the document is rendered whole again and the sprite stays until that image is shown. Desktop only (the browser renders in the same frame). Trade-offs while dragging: the sprite draws above everything (z-order is lost), blends against what is behind are approximated, a backdrop effect's content can trail its pane by the time of one sprite render, ancestors' clips are applied as their bounding boxes, and a sprite wider than the texture limit or over four canvases of pixels, a background blur or glass with a section on the page on a dark interface, outline and focus views, pixel preview and soft proof keep the old way (`canvas/drag_sprite.rs`) | +| A dragged layer moves with its outline | partial | #2033: the canvas image is the last render the worker finished, so a drag's content trailed its outline by a render per pointer move (63 ms, about 3.6 frames, and 150 px on screen with drop shadows on 200 layers). While a gesture only translates plain layers (Normal or pass-through blend, no effects above them, not masks, not in a boolean group or beside a mask, no ancestor under 100 percent opacity, no shadow of their own blending by a mode other than Normal; their own effects and their children's are drawn into the sprite) the layers are rendered once into a texture of their own (the sprite), the base is rendered once without them from the document the drag started from and then asks for no more renders, and the sprite is drawn each frame at the same shifted place as the selection outline. #2853: a background blur or glass in the sprite reads what lies under it where it is now: a thread of the sprite's own renders it again from the start document for the latest shift, while the sprite keeps moving with the outline every frame and shows the newest of those renders (a glass pane over stripes, 600 × 360 px, debug build: the canvas showed 10 to 20 new images a second during the drag, about 20 ms of render each, and now renders nothing until the drop, the pane following the pointer every frame). On release, Escape or a zoom change the document is rendered whole again and the sprite stays until that image is shown. Desktop only (the browser renders in the same frame). Trade-offs while dragging: the sprite draws above everything (z-order is lost), blends against what is behind are approximated, a backdrop effect's content can trail its pane by the time of one sprite render, ancestors' clips are applied as their bounding boxes, and a sprite wider than the texture limit or over four canvases of pixels, a background blur or glass with a section on the page on a dark interface, outline and focus views, pixel preview and soft proof keep the old way (`canvas/drag_sprite.rs`) | | Scale tool (K): handles about the opposite handle, live factor, panel | done | Dragging a handle ignores the origin grid and pivots on the opposite handle's point (the opposite corner, or the opposite edge's middle for an edge, which scales both ways), with Alt on the centre; the origin grid (`tool.scaleAnchor`) starts at the centre and sets only what the Scale field and the W and H fields keep fixed (W and H with a non-centre origin are unmeasured). Measured in Figma's web app, 2026-11-09. Tests: `a_scale_handle_drag_pivots_on_the_opposite_handle_whatever_the_origin`, `the_scale_origin_starts_at_the_centre`. Pressing K opens the Scale section with its factor field focused and its text selected; typing 2 (or 2x, 1.5) then Enter scales the selection by it about the panel's origin, which starts at the centre, as one undo step, then closes the section and returns to Move with the selection kept; Escape in the field closes it, back to Move, nothing changed. Measured in Figma's web app, 2026-11-09. Tests: `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`. | | Nudge 1 / Shift 10 (preference), Cmd+arrows resize | done | arrows reorder auto layout children; the arrow keys move along the canvas axes inside a rotated parent, as in Figma, #2372 | | Smart guides: edges, centres, equal spacing (between two layers or continuing a row's gap, labelled), spacing labels, parent, layout grid, ruler guides | done | red, `snap.rs`; a guide dragged out of a ruler or moved snaps to layer edges and centres too (Snap to Objects; Cmd/Ctrl suspends), on its own axis only; page guides see the page's top-level layers, frame guides the frame's box, layout grids and every layer in it, along a rotated frame's own axes; the object snap threshold is 4.5 screen pixels, measured against Figma (snapped at a gap of 4.4 screen px, not at 4.6, at 100% and 200% zoom, 2026-11-08; the equal-spacing snap shares it), but the ruler-guide and rotation-origin thresholds (5 px), the red guide's look and snapping with Snap to pixel grid off are not yet compared with Figma's (`guide_snap_tests`, `transform_behaviour_tests`) | @@ -226,7 +226,7 @@ This audit records candidates for subsequent fixes; their behaviour is unchanged | Date | Change | Summary | |---|---|---| -| 2026-12-01 | patch | M8, #2853: dragging a layer with effects of its own (a glass, a drop shadow) re-rendered the canvas on every pointer move, so the layer stuttered behind its outline. Its effects are now drawn into the drag sprite with it, a background blur or glass reading the page under it where the drag started, so it moves with the outline; on a dark interface a glass over a section keeps the old way. Tests: `a_frame_with_effects_on_itself_drags_as_a_sprite_with_them`, `a_glass_drags_as_a_sprite_but_not_over_a_section_on_a_dark_interface`. | +| 2026-12-01 | patch | M8, #2853: dragging a layer with effects of its own (a glass, a drop shadow) re-rendered the canvas on every pointer move, so the layer stuttered behind its outline. Its effects are now drawn into the drag sprite with it, a background blur or glass reading the page under it where the drag started, so it moves with the outline; on a dark interface a glass over a section, and a layer whose shadow blends by another mode with what lies beneath, keep the old way. Tests: `a_frame_with_effects_on_itself_drags_as_a_sprite_with_them`, `a_glass_drags_as_a_sprite_but_not_over_a_section_on_a_dark_interface`, `a_layer_whose_shadow_blends_by_another_mode_is_not_plain`. | | 2026-12-01 | patch | M8, #2853: a dragged background blur or glass reads what lies under it where it is now: a thread of the drag sprite's own renders it again for the latest place while the sprite keeps up with the outline every frame, and the glass pixel loop runs its rows in parallel outside a parallel render. Tests: `a_pane_moved_back_shows_what_lies_under_it_where_it_is`, `a_layer_dragged_with_the_pane_shows_through_it`, `glass_drag_tests`. | | 2026-12-01 | minor | M3, #1749: Draw mode in the toolbar's mode switcher only chose the Pencil, and lit up whenever the Pencil was the tool; the drawing tools stayed behind one flyout. Draw mode is now a mode of the toolbar (`UiState::draw_mode`): the Pen and the Pencil get a button each right after Move, one click apart, and picking the Pen keeps Draw mode; Design, Prototype or Inspect leaves it, and the Pencil chosen from Design's flyout or by its key no longer switches the mode. The reference draws its drawing tools as large standing pictures; ours keep the toolbar's own icons. Tests: `draw_mode_toolbar_tests`. | | 2026-12-01 | patch | #649: emoji in layer names, comments and other UI text drew as plain monochrome glyphs; on desktop they now draw in colour from the system's emoji face, loaded once something shows emoji |