M3: the Local variables window resizes from its edges and corners (#2354)

The window was fixed at 880 x 480. It now resizes from every edge and corner, down to 480 x 240 and up to the screen less a margin, and its header, sidebar and table follow its current size. Egui's memory keeps the size and place while the app runs.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Model-Effort: Opus 5.5 drove; Opus 5.5 briefed; Sonnet 5.5 wrote at medium
This commit is contained in:
Trevor BrownandClaude Sonnet 5.5 committed 2026-11-14 00:41:10 -05:00
1 parent 24613d3fa6
commit c59dc0fdcb
4 files changed
+107 -3

No files matched your search

+14 -2
View File
@@ -239,6 +239,14 @@ impl<'a> View<'a> {
}
}
/// The smallest the window can be dragged to.
const MIN_SIZE: egui::Vec2 = vec2(480.0, 240.0);
/// The largest the window can be dragged to: the screen less a margin.
fn max_size(screen: Rect) -> egui::Vec2 {
(screen.size() - vec2(16.0, 16.0)).max(MIN_SIZE)
}
/// Show the editor while it's open (call once per frame).
pub fn show(app: &mut FigApp, ctx: &Context) {
let Some(mut st) = app.ui.variables.take() else { return };
@@ -267,12 +275,16 @@ pub fn show(app: &mut FigApp, ctx: &Context) {
.id(Id::unique("variables_window"))
.title_bar(false)
.collapsible(false)
.resizable(false)
.fixed_size(size)
.resizable(true)
.default_size(size)
.min_size(MIN_SIZE)
.max_size(max_size(screen))
.pivot(Align2::CENTER_CENTER)
.default_pos(screen.center())
.frame(egui::Frame::window(&ctx.global_style()).fill(t.panel).inner_margin(egui::Margin::same(0)))
.show(ctx, |ui| {
// The window's current size (its default until the user drags an edge or corner).
let size = ui.available_size().max(MIN_SIZE);
ui.set_min_size(size);
ui.spacing_mut().item_spacing = vec2(0.0, 0.0);
header(app, ui, &mut open);
+2
View File
@@ -294,6 +294,8 @@ mod variables_rename_tests;
#[cfg(test)]
mod variables_select_tests;
#[cfg(test)]
mod variables_window_resize_tests;
#[cfg(test)]
mod variants_discovery_tests;
#[cfg(test)]
mod vector_keys_tests;
@@ -0,0 +1,89 @@
//! The Local variables window resizes from its edges and corners, height as well as width, stops at
//! a minimum size, and keeps its size when it is closed and opened again (#2354).
use egui::{Event, Id, Pos2, Rect, vec2};
use figcraft_engine::Session;
use serde_json::json;
use crate::layers_drag_tests::Ui;
use crate::live_tests::{flat, texts};
const COUNT: usize = 60;
/// The window open on a collection of many number variables.
fn window() -> Ui {
let mut s = Session::new();
s.execute("variable.createCollection", &json!({"name": "Theme"})).unwrap();
for k in 0..COUNT {
s.execute("variable.create", &json!({"collection": "Theme", "name": format!("v{k:02}"), "type": "number", "value": 1})).unwrap();
}
let mut u = Ui::new(s);
u.app.ui.variables = Some(Default::default());
for _ in 0..10 {
u.frame(vec![]);
}
u
}
fn rect(u: &Ui) -> Rect {
u.ctx.memory(|m| m.area_rect(Id::unique("variables_window"))).expect("the variables window has an area")
}
/// How many variable rows are drawn inside the window (the table clips the rest).
fn rows(u: &mut Ui) -> usize {
let window = rect(u);
let shapes = flat(&u.frame_output(vec![]).shapes);
texts(&shapes).iter().filter(|(t, p, _)| t.len() == 3 && t.starts_with('v') && window.contains(*p)).count()
}
/// Drag the bottom-right corner by `by` and let go.
fn drag_corner(u: &mut Ui, by: egui::Vec2) {
let from = rect(u).right_bottom();
u.drag_to(from, from + by);
let to: Pos2 = from + by;
u.frame(vec![Event::PointerButton { pos: to, button: egui::PointerButton::Primary, pressed: false, modifiers: Default::default() }]);
for _ in 0..5 {
u.frame(vec![]);
}
}
#[test]
fn the_variables_window_grows_when_dragged_taller() {
let mut u = window();
let before = rect(&u);
let rows_before = rows(&mut u);
drag_corner(&mut u, vec2(0.0, 200.0));
let after = rect(&u);
assert!((after.height() - before.height() - 200.0).abs() < 2.0, "height {} -> {}", before.height(), after.height());
let rows_after = rows(&mut u);
assert!(rows_after > rows_before, "the table shows more rows: {rows_before} -> {rows_after}");
}
#[test]
fn the_variables_window_keeps_a_minimum_size() {
let mut u = window();
drag_corner(&mut u, vec2(-2000.0, -2000.0));
let r = rect(&u);
assert!((r.width() - 480.0).abs() < 3.0, "width {}", r.width());
assert!((r.height() - 240.0).abs() < 3.0, "height {}", r.height());
}
#[test]
fn a_resized_variables_window_keeps_its_size_when_reopened() {
let mut u = window();
drag_corner(&mut u, vec2(0.0, 150.0));
let resized = rect(&u);
let close = resized.right_top() + vec2(-22.0, 22.0);
u.button(close, true);
u.button(close, false);
for _ in 0..5 {
u.frame(vec![]);
}
assert!(u.app.ui.variables.is_none(), "the Close button closed the window");
u.app.ui.variables = Some(Default::default());
for _ in 0..10 {
u.frame(vec![]);
}
let again = rect(&u);
assert!((again.width() - resized.width()).abs() < 1.0 && (again.height() - resized.height()).abs() < 1.0, "{resized:?} -> {again:?}");
}
+2 -1
View File
@@ -66,7 +66,7 @@ updates with overrides kept: `library_tests.rs`, `components_scale_tests.rs`.
| Editing a style updates its layers; detach and delete keep values; editing a styled property unlinks that style | done | an edited fill/stroke/effect/grid list or text chars unlink; applying a style replaces variables bound to what it sets; text styles on text layers only |
| Organising styles: folders by `/` names, order, duplicate, rename folder, Local styles list | done | `style.move` (into a folder renames), `style.duplicate` (right below), `style.renameFolder`; the page's Local styles list by type and folder (drag to reorder, right-click) |
| Variables inside styles (paint, effect, grid and text styles; each user resolves them in its own modes) | done | `style.bind`, `style_vars_tests`; the editor binds paint colours, shadow colours, blur radii, grid sizes and a text style's font, font style (a face name from a string variable, or a numeric weight from a number variable, which picks the nearest face and a variable font's `wght` axis), size, line height and letter spacing, the rest through the command; a bound line height is applied in pixels, as the reference tool does (measured 2026-11-10) |
| Variables: colour, number, string, boolean; collections, modes, aliases, scopes, groups | done | behaviour suite: `variables_behaviour_tests.rs`; aliases same type, no loops (also on create); colour calculations per mode (`{alpha}`: a colour variable with its alpha replaced, `{mix}`: a per-channel blend of two colour variables or literals; they compose, can't loop, and bound layers, modes and undo follow them; REST, CSS, Penpot and `.fig` exports write the colour they show in each of their collection's modes, other collections in their default modes; read-only in the panel, which can swap one for an alias or detach it; `variables_colour_tests.rs`), beyond the incumbent, whose variables only alias; scopes filter pickers only; several variables can be selected in the editor (Shift and Cmd/Ctrl click) and deleted, moved to a group or rescoped at once; a group can be duplicated from its row's menu (Duplicate group, one undo step) |
| Variables: colour, number, string, boolean; collections, modes, aliases, scopes, groups | done | behaviour suite: `variables_behaviour_tests.rs`; aliases same type, no loops (also on create); colour calculations per mode (`{alpha}`: a colour variable with its alpha replaced, `{mix}`: a per-channel blend of two colour variables or literals; they compose, can't loop, and bound layers, modes and undo follow them; REST, CSS, Penpot and `.fig` exports write the colour they show in each of their collection's modes, other collections in their default modes; read-only in the panel, which can swap one for an alias or detach it; `variables_colour_tests.rs`), beyond the incumbent, whose variables only alias; scopes filter pickers only; several variables can be selected in the editor (Shift and Cmd/Ctrl click) and deleted, moved to a group or rescoped at once; a group can be duplicated from its row's menu (Duplicate group, one undo step); the window resizes from its edges and corners (minimum 480 x 240) and keeps its size and place while the app runs, #2354 |
| Modes: add, duplicate, rename, delete, set as default / reorder | done | layers on Auto follow a new default; explicit modes stay |
| Deleting a bound variable or its collection | done | layers keep their last value and are unbound; aliases to it take its values and colour calculations reading it keep the colour they show |
| Code syntax per platform (Web, iOS, Android) | done | generated CSS uses the Web name, SwiftUI the iOS one and Compose the Android one (a variable without one keeps its value there); in the variables JSON; ArkUI and Flutter have no platform of their own and write values |
@@ -81,6 +81,7 @@ updates with overrides kept: `library_tests.rs`, `components_scale_tests.rs`.
| Date | Change | Summary |
|---|---|---|
| 2026-11-14 | patch | M3, #2354: the Local variables window resizes from its edges and corners, width and height (minimum 480 x 240), and keeps its size and place while the app runs. |
| 2026-11-07 | minor | M3, #2084: a group's context menu in the Local variables window has Duplicate group (after Rename group, before Delete group). It adds a group named after the original plus " 2" (the next free number when taken: " 3"), whose variables are copies of the originals with the same leaf names, values in every mode, description, scopes, hidden-from-publishing and code syntax, each sent as `variable.duplicate` plus a rename in one `command.batch` labelled Duplicate group, so one undo step. Measured in the incumbent with one mode; an alias to a variable of the same group keeps pointing at the original. Ungroup is not built. Tests: `variables_select_tests` (headless UI). Grade unchanged |
| 2026-11-07 | minor | M3, #2082: Edit variables in the context menu of a selection of several local variables opens the reference's compact editor with two tabs: Details holds only Hide from publishing, Scope the scopes every selected variable's type has (All supported properties and one box per scope; a selection that shares none says so). Each box is checked when all selected variables have it, empty when none, and shows a dash when they differ; a click sets it on all (or clears it when checked on all), each change one `command.batch`, so one undo step. Names, descriptions and code syntax stay single-variable, as in the reference. The Scope: menu entries stay. A tri-state `widgets::checkbox_tri` draws the dash. Tests: `variables_select_tests` (headless UI). Grade unchanged |
| 2026-11-12 | minor | M7, #2215: 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). The same section the frames' Variable modes use (`variable.setMode` without layers sets the page's mode), one undo step per pick. Binding the page background to a variable is not in the reference and is not offered |