From c59dc0fdcbab6b1659495c13ed351847d3bccf30 Mon Sep 17 00:00:00 2001 From: Trevor Brown Date: Sat, 14 Nov 2026 00:41:10 -0500 Subject: [PATCH 1/4] 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 Model-Effort: Opus 5.5 drove; Opus 5.5 briefed; Sonnet 5.5 wrote at medium --- crates/ui-egui/src/dialogs/variables_panel.rs | 16 +++- crates/ui-egui/src/lib.rs | 2 + .../src/variables_window_resize_tests.rs | 89 +++++++++++++++++++ docs/components-parity.md | 3 +- 4 files changed, 107 insertions(+), 3 deletions(-) create mode 100644 crates/ui-egui/src/variables_window_resize_tests.rs diff --git a/crates/ui-egui/src/dialogs/variables_panel.rs b/crates/ui-egui/src/dialogs/variables_panel.rs index 067d54ea9..f4eff6639 100644 --- a/crates/ui-egui/src/dialogs/variables_panel.rs +++ b/crates/ui-egui/src/dialogs/variables_panel.rs @@ -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); diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs index 4a0b38768..bfb2ab216 100644 --- a/crates/ui-egui/src/lib.rs +++ b/crates/ui-egui/src/lib.rs @@ -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; diff --git a/crates/ui-egui/src/variables_window_resize_tests.rs b/crates/ui-egui/src/variables_window_resize_tests.rs new file mode 100644 index 000000000..67ed7faa9 --- /dev/null +++ b/crates/ui-egui/src/variables_window_resize_tests.rs @@ -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:?}"); +} diff --git a/docs/components-parity.md b/docs/components-parity.md index 3d23800b0..3420f1bcf 100644 --- a/docs/components-parity.md +++ b/docs/components-parity.md @@ -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 | From 4b9e900f89f99f8086c967776b3d9c2a364d00d4 Mon Sep 17 00:00:00 2001 From: Trevor Brown Date: Sat, 14 Nov 2026 02:49:35 -0500 Subject: [PATCH 2/4] M3: the Local variables window's minimum width fits the table's header row (#2354) At 480 points the table was 279 wide, leaving 11 points next to the 220-point search field for a library collection's Extend collection button. The minimum is now 600 x 240 (table 399 wide); the default size's clamp uses the same minimum. variables 43 passed, clippy clean (CodeRabbit on #2363). Co-Authored-By: Claude Opus 5.5 --- crates/ui-egui/src/dialogs/variables_panel.rs | 7 ++++--- crates/ui-egui/src/variables_window_resize_tests.rs | 2 +- docs/components-parity.md | 4 ++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/crates/ui-egui/src/dialogs/variables_panel.rs b/crates/ui-egui/src/dialogs/variables_panel.rs index f4eff6639..4e3b1e541 100644 --- a/crates/ui-egui/src/dialogs/variables_panel.rs +++ b/crates/ui-egui/src/dialogs/variables_panel.rs @@ -239,8 +239,9 @@ impl<'a> View<'a> { } } -/// The smallest the window can be dragged to. -const MIN_SIZE: egui::Vec2 = vec2(480.0, 240.0); +/// The smallest the window can be dragged to: wide enough that the table's header row holds the +/// search field and a library collection's "Extend collection" button side by side. +const MIN_SIZE: egui::Vec2 = vec2(600.0, 240.0); /// The largest the window can be dragged to: the screen less a margin. fn max_size(screen: Rect) -> egui::Vec2 { @@ -269,7 +270,7 @@ pub fn show(app: &mut FigApp, ctx: &Context) { st.collection = coll.map(|c| c.id.clone()); let t = Tokens::get(ctx); let screen = ctx.content_rect(); - let size = vec2(880.0_f32.min(screen.width() - 80.0).max(480.0), 480.0_f32.min(screen.height() - 120.0).max(240.0)); + let size = vec2(880.0_f32.min(screen.width() - 80.0).max(MIN_SIZE.x), 480.0_f32.min(screen.height() - 120.0).max(MIN_SIZE.y)); let mut open = true; egui::Window::new(tr("Local variables")) .id(Id::unique("variables_window")) diff --git a/crates/ui-egui/src/variables_window_resize_tests.rs b/crates/ui-egui/src/variables_window_resize_tests.rs index 67ed7faa9..b08d2ace1 100644 --- a/crates/ui-egui/src/variables_window_resize_tests.rs +++ b/crates/ui-egui/src/variables_window_resize_tests.rs @@ -64,7 +64,7 @@ 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.width() - 600.0).abs() < 3.0, "width {}", r.width()); assert!((r.height() - 240.0).abs() < 3.0, "height {}", r.height()); } diff --git a/docs/components-parity.md b/docs/components-parity.md index 3420f1bcf..e910c511a 100644 --- a/docs/components-parity.md +++ b/docs/components-parity.md @@ -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); the window resizes from its edges and corners (minimum 480 x 240) and keeps its size and place while the app runs, #2354 | +| 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 600 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,7 +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-14 | patch | M3, #2354: the Local variables window resizes from its edges and corners, width and height (minimum 600 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 | From 5a482af812cbab55c01cbc440cbf627903aaa3e1 Mon Sep 17 00:00:00 2001 From: Trevor Brown Date: Sat, 14 Nov 2026 03:38:02 -0500 Subject: [PATCH 3/4] M3: the Local variables window fits a narrow screen and resizes from a fixed corner (#2354) The minimum (600 x 240) is capped at the screen less its margin, so on a screen narrower than that the window stays inside it. The window is pinned at its top-left corner and opens centred, so dragging one edge leaves the opposite one in place (the centre pivot moved both). Tests on_a_narrow_screen_the_variables_window_fits_inside_it (red before: the window ran from x -26 to 576 on a 550-wide screen) and the top-edge check in the_variables_window_grows_when_dragged_taller (red before: 210 -> 190); variables 44 passed, clippy clean (CodeRabbit on #2363). Co-Authored-By: Claude Opus 5.5 --- crates/ui-egui/src/dialogs/variables_panel.rs | 23 +++++++++++-------- .../src/variables_window_resize_tests.rs | 17 ++++++++++++++ 2 files changed, 31 insertions(+), 9 deletions(-) diff --git a/crates/ui-egui/src/dialogs/variables_panel.rs b/crates/ui-egui/src/dialogs/variables_panel.rs index 4e3b1e541..d018e7f2f 100644 --- a/crates/ui-egui/src/dialogs/variables_panel.rs +++ b/crates/ui-egui/src/dialogs/variables_panel.rs @@ -243,9 +243,11 @@ impl<'a> View<'a> { /// search field and a library collection's "Extend collection" button side by side. const MIN_SIZE: egui::Vec2 = vec2(600.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) +/// The smallest and largest the window can be: at most the screen less a margin, and at least +/// [`MIN_SIZE`] unless the screen is smaller than that (then the screen less the margin). +fn limits(screen: Rect) -> (egui::Vec2, egui::Vec2) { + let max = (screen.size() - vec2(16.0, 16.0)).max(vec2(1.0, 1.0)); + (MIN_SIZE.min(max), max) } /// Show the editor while it's open (call once per frame). @@ -270,7 +272,8 @@ pub fn show(app: &mut FigApp, ctx: &Context) { st.collection = coll.map(|c| c.id.clone()); let t = Tokens::get(ctx); let screen = ctx.content_rect(); - let size = vec2(880.0_f32.min(screen.width() - 80.0).max(MIN_SIZE.x), 480.0_f32.min(screen.height() - 120.0).max(MIN_SIZE.y)); + let (min, max) = limits(screen); + let size = vec2(880.0_f32.min(screen.width() - 80.0), 480.0_f32.min(screen.height() - 120.0)).clamp(min, max); let mut open = true; egui::Window::new(tr("Local variables")) .id(Id::unique("variables_window")) @@ -278,14 +281,16 @@ pub fn show(app: &mut FigApp, ctx: &Context) { .collapsible(false) .resizable(true) .default_size(size) - .min_size(MIN_SIZE) - .max_size(max_size(screen)) - .pivot(Align2::CENTER_CENTER) - .default_pos(screen.center()) + .min_size(min) + .max_size(max) + // Pinned at its top-left corner, so dragging one edge leaves the opposite one in place; + // it opens centred. + .pivot(Align2::LEFT_TOP) + .default_pos((screen.center() - size / 2.0).max(screen.min)) .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); + let size = ui.available_size().max(min); ui.set_min_size(size); ui.spacing_mut().item_spacing = vec2(0.0, 0.0); header(app, ui, &mut open); diff --git a/crates/ui-egui/src/variables_window_resize_tests.rs b/crates/ui-egui/src/variables_window_resize_tests.rs index b08d2ace1..e2dedae75 100644 --- a/crates/ui-egui/src/variables_window_resize_tests.rs +++ b/crates/ui-egui/src/variables_window_resize_tests.rs @@ -55,10 +55,27 @@ fn the_variables_window_grows_when_dragged_taller() { 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()); + assert!((after.min.y - before.min.y).abs() < 2.0, "the top edge stays where it was: {} -> {}", before.min.y, after.min.y); let rows_after = rows(&mut u); assert!(rows_after > rows_before, "the table shows more rows: {rows_before} -> {rows_after}"); } +#[test] +fn on_a_narrow_screen_the_variables_window_fits_inside_it() { + // Narrower than the minimum (600): the window takes the screen less its margin instead. + let mut s = Session::new(); + s.execute("variable.createCollection", &json!({"name": "Theme"})).unwrap(); + let mut u = Ui::new(s); + u.screen = vec2(550.0, 700.0); + u.app.ui.variables = Some(Default::default()); + for _ in 0..10 { + u.frame(vec![]); + } + let r = rect(&u); + let screen = Rect::from_min_size(Pos2::ZERO, u.screen); + assert!(screen.contains_rect(r), "the window {r:?} is inside the screen {screen:?}"); +} + #[test] fn the_variables_window_keeps_a_minimum_size() { let mut u = window(); From 29fe911dd937cb963b4d144606f06bda280318f3 Mon Sep 17 00:00:00 2001 From: Trevor Brown Date: Sat, 14 Nov 2026 04:37:56 -0500 Subject: [PATCH 4/4] M3: on a short screen the Local variables window's body takes what is left (#2354) The body below the header had a 160-point floor, so with the minimum capped by a screen lower than 220 points the content ran past the window. It now takes the height left below the header (the table scrolls). Test on_a_short_screen_the_variables_window_fits_inside_it (red before: the window ran to y 206 on a 180-high screen); variables 45 passed, clippy clean (CodeRabbit on #2363). Co-Authored-By: Claude Opus 5.5 --- crates/ui-egui/src/dialogs/variables_panel.rs | 3 ++- .../src/variables_window_resize_tests.rs | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/crates/ui-egui/src/dialogs/variables_panel.rs b/crates/ui-egui/src/dialogs/variables_panel.rs index d018e7f2f..233181fb7 100644 --- a/crates/ui-egui/src/dialogs/variables_panel.rs +++ b/crates/ui-egui/src/dialogs/variables_panel.rs @@ -294,7 +294,8 @@ pub fn show(app: &mut FigApp, ctx: &Context) { ui.set_min_size(size); ui.spacing_mut().item_spacing = vec2(0.0, 0.0); header(app, ui, &mut open); - let h = (size.y - 44.0).max(160.0); + // The body below the 44-point header: what is left of the window (the table scrolls). + let h = (size.y - 44.0).max(0.0); let top_down = egui::Layout::top_down(egui::Align::Min); ui.horizontal_top(|ui| { ui.allocate_ui_with_layout(vec2(SIDEBAR_W, h), top_down, |ui| sidebar(app, ui, &views, &doc.variables, &mut st)); diff --git a/crates/ui-egui/src/variables_window_resize_tests.rs b/crates/ui-egui/src/variables_window_resize_tests.rs index e2dedae75..8ec2c4113 100644 --- a/crates/ui-egui/src/variables_window_resize_tests.rs +++ b/crates/ui-egui/src/variables_window_resize_tests.rs @@ -76,6 +76,25 @@ fn on_a_narrow_screen_the_variables_window_fits_inside_it() { assert!(screen.contains_rect(r), "the window {r:?} is inside the screen {screen:?}"); } +#[test] +fn on_a_short_screen_the_variables_window_fits_inside_it() { + // Lower than the minimum (240): the body takes what is left below the header and scrolls. + 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.screen = vec2(800.0, 180.0); + u.app.ui.variables = Some(Default::default()); + for _ in 0..10 { + u.frame(vec![]); + } + let r = rect(&u); + let screen = Rect::from_min_size(Pos2::ZERO, u.screen); + assert!(screen.contains_rect(r), "the window {r:?} is inside the screen {screen:?}"); +} + #[test] fn the_variables_window_keeps_a_minimum_size() { let mut u = window();