mirror of
https://github.com/storytold/figcraft.git
synced 2026-11-29 01:34:37 +01:00
Merge pull request #2618 from denisg0mes/pixel-grid-on-dark
M3: the pixel grid shows on dark as well as on white
This commit is contained in:
5 files changed
+81
-7
No files matched your search
@@ -21,7 +21,7 @@ mod drag_sprite;
|
||||
mod input;
|
||||
pub(crate) use input::release_fields_for_press;
|
||||
mod outline;
|
||||
mod overlays;
|
||||
pub(crate) mod overlays;
|
||||
mod render;
|
||||
mod rulers;
|
||||
|
||||
|
||||
@@ -174,22 +174,27 @@ pub(super) fn overlays(app: &FigApp, painter: &egui::Painter, t: &Tokens) -> Vec
|
||||
labels
|
||||
}
|
||||
|
||||
/// The pixel grid's lines: one screen pixel wide, a light grey at a fifth of its strength, so
|
||||
/// they darken white and lighten a dark canvas or fill alike. Measured in Figma (2026-11-24):
|
||||
/// 242 on white and 78 on a grey of 50, which this grey gives.
|
||||
pub(crate) const PIXEL_GRID: Color32 = Color32::from_rgba_unmultiplied_const(190, 190, 190, 51);
|
||||
|
||||
/// Pixel grid at high zoom.
|
||||
fn pixel_grid(app: &FigApp, painter: &egui::Painter) {
|
||||
let r = app.canvas.rect;
|
||||
let p0 = app.to_page(r.min);
|
||||
let p1 = app.to_page(r.max);
|
||||
let col = Color32::from_black_alpha(18);
|
||||
let line = stroke(PIXEL_GRID, 1.0 / painter.pixels_per_point());
|
||||
let mut x = p0.x.floor();
|
||||
while x <= p1.x {
|
||||
let s = app.to_screen(x, 0.0).x;
|
||||
painter.line_segment([pos2(s, r.min.y), pos2(s, r.max.y)], stroke(col, 1.0));
|
||||
let s = painter.round_to_pixel_center(app.to_screen(x, 0.0).x);
|
||||
painter.line_segment([pos2(s, r.min.y), pos2(s, r.max.y)], line);
|
||||
x += 1.0;
|
||||
}
|
||||
let mut y = p0.y.floor();
|
||||
while y <= p1.y {
|
||||
let s = app.to_screen(0.0, y).y;
|
||||
painter.line_segment([pos2(r.min.x, s), pos2(r.max.x, s)], stroke(col, 1.0));
|
||||
let s = painter.round_to_pixel_center(app.to_screen(0.0, y).y);
|
||||
painter.line_segment([pos2(r.min.x, s), pos2(r.max.x, s)], line);
|
||||
y += 1.0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -232,6 +232,8 @@ mod pen_mode_tests;
|
||||
#[cfg(test)]
|
||||
mod perf_tests;
|
||||
#[cfg(test)]
|
||||
mod pixel_grid_tests;
|
||||
#[cfg(test)]
|
||||
mod plugin_panel_tests;
|
||||
#[cfg(test)]
|
||||
mod plugin_save_ui_tests;
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
//! The pixel grid, drawn headless: from 400% its lines are one screen pixel wide and a grey that
|
||||
//! shows on a white frame and on the dark canvas alike, as in Figma.
|
||||
|
||||
use egui::{Color32, RawInput, Shape, ViewportId, ViewportInfo};
|
||||
use figcraft_engine::Session;
|
||||
use serde_json::json;
|
||||
|
||||
use crate::canvas::overlays::PIXEL_GRID;
|
||||
use crate::layers_drag_tests::Ui;
|
||||
use crate::live_tests::flat;
|
||||
|
||||
/// Each grid line drawn in a frame on a screen of `native` pixels per point (the last of a few,
|
||||
/// for a new scale to take effect): its width and the coordinate it runs along, its x if
|
||||
/// vertical and its y if horizontal.
|
||||
fn grid_lines(u: &mut Ui, native: f32) -> Vec<(f32, f32)> {
|
||||
let mut out = None;
|
||||
for _ in 0..4 {
|
||||
let mut raw = RawInput::default();
|
||||
raw.viewports.insert(ViewportId::ROOT, ViewportInfo { native_pixels_per_point: Some(native), ..Default::default() });
|
||||
out = Some(u.frame_raw(raw));
|
||||
}
|
||||
let shapes = flat(&out.map(|o| o.shapes).unwrap_or_default());
|
||||
shapes
|
||||
.iter()
|
||||
.filter_map(|s| match s {
|
||||
Shape::LineSegment { points: [a, b], stroke } if stroke.color == PIXEL_GRID => Some((stroke.width, if a.x == b.x { a.x } else { a.y })),
|
||||
_ => None,
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Whether every line in `lines` sits on the middle of a row or column of pixels of a screen of
|
||||
/// `native` pixels per point, so it covers that one pixel and no half of two.
|
||||
fn on_pixel_centres(lines: &[(f32, f32)], native: f32) -> bool {
|
||||
lines.iter().all(|(_, at)| ((at * native - 0.5) - (at * native - 0.5).round()).abs() < 1e-3)
|
||||
}
|
||||
|
||||
/// `c` drawn over a grey of `bg`, as the canvas blends it.
|
||||
fn over(c: Color32, bg: u8) -> f32 {
|
||||
let [r, _, _, a] = c.to_srgba_unmultiplied();
|
||||
let a = f32::from(a) / 255.0;
|
||||
f32::from(bg) * (1.0 - a) + f32::from(r) * a
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_pixel_grid_shows_on_white_and_on_dark_one_screen_pixel_wide() {
|
||||
let mut s = Session::new();
|
||||
s.execute("frame.create", &json!({"x": 0, "y": 0, "width": 100, "height": 100})).unwrap();
|
||||
let mut u = Ui::new(s);
|
||||
let view = &mut u.app.session.ds_mut().unwrap().view;
|
||||
view.zoom = 8.0;
|
||||
// A view between whole points, so the page's pixels fall between the screen's.
|
||||
(view.cx, view.cy) = (50.03, 50.07);
|
||||
let lines = grid_lines(&mut u, 1.0);
|
||||
assert!(!lines.is_empty(), "the grid draws at 800%");
|
||||
assert!(lines.iter().all(|(w, _)| *w == 1.0), "one screen pixel: {lines:?}");
|
||||
assert!(on_pixel_centres(&lines, 1.0), "on the screen's pixels: {lines:?}");
|
||||
// Measured in Figma (2026-11-24): a grid line is 242 on white and 78 on a grey of 50.
|
||||
assert_eq!((over(PIXEL_GRID, 255).round(), over(PIXEL_GRID, 50).round()), (242.0, 78.0));
|
||||
// On a 2x screen the lines stay one of its pixels wide.
|
||||
let lines = grid_lines(&mut u, 2.0);
|
||||
assert!(!lines.is_empty() && lines.iter().all(|(w, _)| *w == 0.5), "{lines:?}");
|
||||
assert!(on_pixel_centres(&lines, 2.0), "on the 2x screen's pixels: {lines:?}");
|
||||
u.app.session.ds_mut().unwrap().view.zoom = 3.0;
|
||||
assert!(grid_lines(&mut u, 2.0).is_empty(), "no grid below 400%");
|
||||
}
|
||||
+2
-1
@@ -1,6 +1,6 @@
|
||||
# UI and interaction parity
|
||||
|
||||
> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-11-24 · **Change:** minor (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 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), 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); ShLine truncated
|
||||
> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-11-24 · **Change:** minor (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 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), 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 editLine 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:
|
||||
@@ -216,6 +216,7 @@ This audit records candidates for subsequent fixes; their behaviour is unchanged
|
||||
| 2026-11-09 | patch | M3, #2090: the Scale tool no longer snaps variable-bound lengths back to the variable's value. An instance multiplies its new `scale_factor` and keeps its bindings, drawn at the variable's value times the factor (modes and variable edits stay live); every other scaled layer outside an instance keeps the scaled value and drops the binding of the length fields it scaled, and so does a scaled instance's own layer when the instance is detached (the instances inside it take its factor on). Measured in the incumbent for the gap only (an instance keeps the binding at value x factor, a plain frame bakes it, and detaching a scaled instance bakes it); the other lengths are assumed to follow, and a main component is unmeasured; a scale that would take an instance past 0.001 to 1000 times is refused. Tests: `scale_bound_values_tests`. |
|
||||
| 2026-11-24 | patch | M4: Copy properties (Alt+Cmd/Ctrl+C) took a layer's values and left behind what they come from: a frame filled from a colour variable or a style pasted a plain colour, unlinked, and a pasted layer's own bindings stayed and could hold the old value over the pasted one. It now also carries the fill, stroke, effect, grid and text style links, the variables bound to what it copies (not size, auto layout spacing, visibility or text content) and a frame's layout grids; the pasted layer's bindings on what the copy carries give way, others stay. Pasted into another file (the copy came from another tab), or after its style was deleted, a link is left out, its values pasted and the layer's own link on them dropped. Tests: `paste_properties_tests` (4). |
|
||||
| 2026-11-24 | patch | M3: Shift+Cmd/Ctrl+' turned Snap to pixel grid on or off without a sign, since nothing on the canvas changes until the next drag. A notice at the bottom now says "Snap to pixel grid on" or "off", from the shortcut, the menu and the Preferences row alike. Test: `shortcut_keys_tests::shift_cmd_quote_says_whether_snapping_to_the_pixel_grid_is_on`. |
|
||||
| 2026-11-24 | patch | M3: the pixel grid was drawn in black at 7% and two pixels wide on a Retina screen, so it showed on white and hardly at all on the dark canvas or a dark fill. Its lines are now a light grey (190) at 20%, one screen pixel wide and on the screen's pixels: 242 on white and 78 on a grey of 50, as measured on Figma's grid (2026-11-24), so they darken a light colour and lighten a dark one. Test: `pixel_grid_tests` (800%, a 1x and a 2x screen, none below 400%). |
|
||||
| 2026-11-19 | patch | M4, #2338: superscript and subscript were drawn (#1868) but nothing in the interface set them. Type settings ▸ Details now starts with Position: None, Superscript (X²) or Subscript (X₂), for the selected text layers, through `text.setFeatures` (`sups`, `subs`; choosing one clears the other). It shows the layers' current position, none when they differ. Raising a range of characters on its own needs per-run features and is left for a separate change. Test: `typography::variable_tests::details_position_sets_superscript_subscript_or_neither`. |
|
||||
| 2026-11-19 | patch | M1, #2447: Shift did nothing with the Pencil: a stroke stayed freehand while the Line tool and the Pen keep theirs to 45° steps. With Shift held, the Pencil (and the Marker and Highlighter) now draws one straight segment from where the stroke started to the pointer, at the nearest 45° step; the preview shows it. A Shift-click without a move draws nothing, as before. Tests: `pencil_shift_tests`. |
|
||||
| 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`. |
|
||||
|
||||
Reference in new issue
Block a user