Panels: a panel is never resized narrower than the 220 pt panel minimum

The dock's panel specs set no size limits, so a floating panel's side
could be dragged in to any width and a docked column saved narrower than
PANEL_MIN_WIDTH was drawn at that width, cutting the panel's rows. Every
panel other than the canvas and the toolbars now gives PANEL_MIN_WIDTH
as its least body width, as the app did before the move to the craft UI
framework.

A float placed narrower by window.panel.float or by a saved workspace is
still drawn at the width it was given: the framework's floating window
places that rect without its limits.
This commit is contained in:
dotCooCoo committed 2026-11-25 12:06:31 -08:00
1 parent 694f66a7bd
commit 575f12bffa
2 files changed
+44 -2

No files matched your search

+3 -2
View File
@@ -20,7 +20,7 @@ use std::sync::Arc;
use craft::behavior::{Axis, DockSide, IconId};
use craft::ui::buttons::IconButton;
use craft::ui::contract::{Bind, BodyCx, PlainData, Show as _, Tracked};
use craft::ui::contract::{Bind, BodyCx, PlainData, Show as _, SizeLimits, Tracked};
use craft::ui::docking::{
ColumnCards, DockCommands, DockConfig, DockEvent, DockGrid, DockPanels, DockScene, DockSizes, DockTo, DragUnit, FloatSpace, GroupAt, HidePanels,
PanelKey, PanelSpec, PanelSpecs, actions as command_actions, move_actions, request_actions,
@@ -1192,9 +1192,10 @@ impl PanelSpecs<String> for Specs {
if panel == CANVAS {
return spec.canvas();
}
// A toolbar's column is as wide as its grid's steps; every other panel is at least PANEL_MIN_WIDTH wide.
let spec = match self.grids.iter().find(|(rail, _)| rail == panel) {
Some((_, grid)) => spec.grid(*grid),
None => spec,
None => spec.limits(SizeLimits::at_least(egui::vec2(PANEL_MIN_WIDTH, 0.0))),
};
let icon = crate::state::rail_panel(panel).map(|p| p.2).or_else(|| crate::panels::library_panel::parse(panel).map(|_| "library"));
match icon {
+41
View File
@@ -970,3 +970,44 @@ fn cycle_options_rejects_panels_without_sizes() {
}
assert_eq!(h.layout(), before, "a refusal changes nothing");
}
/// The width of the body of the panel titled `title` as the last frame drew it.
fn body_width(h: &Harness, title: &str) -> f32 {
h.nodes
.iter()
.find(|(_, node)| node.role() == egui::accesskit::Role::TabPanel && node.label() == Some(title))
.and_then(|(_, node)| node.bounds())
.map(|b| (b.x1 - b.x0) as f32)
.unwrap_or_else(|| panic!("{title}'s body is drawn"))
}
/// A floating panel's side dragged in past `PANEL_MIN_WIDTH` stops at the minimum.
#[test]
fn a_floating_panel_resized_past_the_panel_minimum_stops_at_it() {
let mut h = Harness::new();
h.app.run("window.panel.float", json!({"panel": "stroke", "x": 300, "y": 200, "width": 400, "height": 300})).unwrap();
h.frames(3);
let before = body_width(&h, "Stroke");
assert!((before - 400.0).abs() < 1.0, "a float wider than the minimum keeps its width: {before}");
let rect = floating_window(&h.layout(), "stroke").expect("Stroke floats").rect;
// The window's right side is its resize grip; the drag goes 300 pt in, well past the minimum.
let grip = pos2(rect.right() - 1.0, rect.center().y);
h.drag(grip, grip - vec2(300.0, 0.0));
let after = body_width(&h, "Stroke");
assert!(after < before - 1.0, "the drag narrowed the window: {before} to {after}");
assert!(after >= PANEL_MIN_WIDTH - 0.5, "dragged in past the minimum: {after}");
}
/// A docked column saved narrower than `PANEL_MIN_WIDTH` is drawn at the minimum.
#[test]
fn a_docked_column_is_never_narrower_than_the_panel_minimum() {
let mut h = Harness::new();
let mut layout = h.layout();
let columns = end_dock_mut(&mut layout).expect("the default layout has an end dock");
for column in columns.iter_mut().filter(|column| !column.iconic) {
column.width = Some(100.0);
}
h.set_layout(layout);
h.frames(3);
assert!(body_width(&h, "Properties") >= PANEL_MIN_WIDTH - 0.5, "saved 100 pt wide: {}", body_width(&h, "Properties"));
}