Keep the Parameters window height stable when moved (#5078) (#5752)

* claim: #5078

* Keep the Parameters window height stable when moved (#5078)
This commit is contained in:
Colin Faulkingham
2026-10-25 01:25:53 +00:00
committed by GitHub
parent f5a6c8fa51
commit f01ef3c6aa
3 changed files with 73 additions and 1 deletions
+47
View File
@@ -203,6 +203,7 @@ pub fn show(app: &mut SolveApp, ctx: &egui::Context) {
ui_kit::Panel::feature_frame(ctx, app.ui.layout, side),
)
.wide()
.body_rows(16.0)
.reset_scroll(d.reset_scroll);
let panel = if side == crate::frame::Side::Left {
let available = palette.map_or(viewport.width(), |r| (r.left() - viewport.left() - crate::theme::Tokens::get().space_8).max(0.0));
@@ -1241,10 +1242,56 @@ mod tests {
h.app.start("parameters.change");
h.frames(6);
for id in ["fav", "user", "Box1", "Box2"] {
if id.starts_with("Box") {
// The bounded card no longer shows every group at once. Bring each
// model table into view before checking its horizontal layout.
h.app.params.as_mut().unwrap().filter = id.into();
h.frames(6);
}
let viewport = crate::scenario::rect_of(&format!("dialog:table:{id}:viewport")).unwrap();
let content = crate::scenario::count_of(&format!("dialog:table:{id}:content_width")).unwrap();
assert!(content <= f64::from(viewport.width().ceil()), "{id} on {screen_width} screen: {content} outside {viewport:?}");
}
}
}
/// #5078: a long list scrolls in a bounded card; moving the card does not stretch it
/// down to the bottom of the app. A short viewport still keeps the actions visible.
#[test]
fn a_long_parameter_list_keeps_its_height_when_moved() {
for layout in ["floating", "docked"] {
let mut h = crate::scenario::Harness::new();
h.app.home.open = false;
h.call("ui.set", json!({"layout": layout}));
h.call("ui.resize", json!({"width": 1600, "height": 1400}));
for i in 0..60 {
h.app.run("parameters.add", json!({"name": format!("p{i:02}"), "expression": "10 mm"})).unwrap();
}
h.step(&json!({"start": "parameters.change"})).unwrap();
h.frames(6);
let bounds = || crate::scenario::rect_of("dialog:header").unwrap().union(crate::scenario::rect_of("dialog:footer").unwrap());
let before = bounds();
let title = crate::scenario::handle_at("dialog:title").unwrap();
h.step(&json!({"drag": [{"handle": "dialog:title"}, [title.x - 90.0, title.y + 120.0]]})).unwrap();
h.frames(6);
let moved = bounds();
assert!((moved.top() - before.top() - 120.0).abs() < 2.0, "{layout}: the header moved: {before:?} -> {moved:?}");
assert!((moved.height() - before.height()).abs() < 2.0, "{layout}: moving must preserve height: {before:?} -> {moved:?}");
assert!(moved.bottom() < 1300.0, "{layout}: a long list must leave room below the card: {moved:?}");
let viewport = crate::scenario::rect_of("dialog:body:viewport").unwrap();
h.call("ui.scroll", json!({"x": viewport.center().x, "y": viewport.center().y, "delta": -100_000}));
h.frames(40);
let last = crate::scenario::handle_at("param:p59").unwrap();
assert!(crate::scenario::rect_of("dialog:body:viewport").unwrap().contains(last), "{layout}: the last parameter remains reachable");
assert!((bounds().height() - moved.height()).abs() < 2.0, "{layout}: scrolling must preserve height");
h.call("ui.resize", json!({"width": 1600, "height": 600}));
h.frames(6);
let small = bounds();
assert!(small.bottom() <= 600.0, "{layout}: the actions must remain on screen: {small:?}");
assert!(small.contains(crate::scenario::handle_at("dialog:ok").unwrap()));
assert!(crate::scenario::rect_of("dialog:body:viewport").unwrap().height() > 0.0);
}
}
}
+24 -1
View File
@@ -72,6 +72,7 @@ pub(crate) struct Panel<'a> {
side: crate::frame::Side,
frame: egui::Frame,
width: f32,
body_rows: Option<f32>,
ok: &'a str,
cancel: &'a str,
reset_scroll: bool,
@@ -134,7 +135,19 @@ impl<'a> Panel<'a> {
}
pub(crate) fn new(title: &'a str, id: egui::Id, anchor: egui::Pos2, viewport: egui::Rect, side: crate::frame::Side, frame: egui::Frame) -> Self {
Self { title, id, anchor, viewport, side, frame, width: Tokens::get().form_card_width, ok: "OK", cancel: "Cancel", reset_scroll: false }
Self {
title,
id,
anchor,
viewport,
side,
frame,
width: Tokens::get().form_card_width,
body_rows: None,
ok: "OK",
cancel: "Cancel",
reset_scroll: false,
}
}
/// A newly opened manager starts at its first section. Later frames retain user scrolling.
@@ -160,6 +173,15 @@ impl<'a> Panel<'a> {
self.width(Tokens::get().form_card_width * 3.0)
}
/// Cap a manager's scrolling body independently of its position, in control rows.
/// Short viewports still take precedence so the header and actions remain reachable.
pub(crate) fn body_rows(mut self, rows: f32) -> Self {
if rows.is_finite() {
self.body_rows = Some(rows.clamp(1.0, 32.0));
}
self
}
/// The painted anchor also drives dragging, including the shell's edge clearance.
fn bounded_anchor(&self, ctx: &egui::Context) -> egui::Pos2 {
let viewport = self.viewport;
@@ -276,6 +298,7 @@ impl<'a> Panel<'a> {
- self.frame.stroke.width;
let footer_height = t.form_footer_height;
let fields_height = (bottom - ui.cursor().top() - footer_height - ui.spacing().item_spacing.y).max(0.0);
let fields_height = self.body_rows.map_or(fields_height, |rows| fields_height.min(rows * t.control_height + t.space_12 * 2.0));
let fields_rect = egui::Rect::from_min_size(ui.cursor().min, vec2(ui.available_width(), fields_height));
let state = if collapsed.as_deref().copied().unwrap_or(false) {
scenario::publish_count("dialog:body:content_height", 0.0);
+2
View File
@@ -29,6 +29,8 @@ preferences, manager cards, prompts, context menus and the sketch palette. Impor
pinned actions, compute status and keyboard routing. `wide()` uses three card
widths. `feature_frame` and `palette_frame` retain docked/floating surfaces.
`FeatureOptions::apply_label` adds Apply; `Panel::actions` supplies custom labels.
`body_rows` caps a manager's scrolling body independently of its position; short
viewports still keep the header and actions visible.
- `Window` composes the shared Panel frame with a 40 pt icon/title/close header,
padded content and optional 48 pt footer. `show_with_left` pins a left action beside
the right-aligned buttons. `show_pages` accepts declarative `WindowPage` entries