Test visible dock chrome in narrow windows; name panel body minimum

- The narrow-window dockWidth test now checks the docking controls craft-ui drew:
  hit_rects are full widget rects (before clipping), so the visible part of each,
  intersected with the dock, must stay inside the dock and off the canvas and
  the toolbox, with at least one control visible.
- Name the 200-point guard for drawing a panel's body PANEL_BODY_MIN_WIDTH,
  separate from CANVAS_MIN_WIDTH; no value change.
This commit is contained in:
Triwarr committed 2026-11-09 09:57:01 +01:00
1 parent 7d101315b3
commit ff14ff4f1f
2 files changed
+21 -1

No files matched your search

+5 -1
View File
@@ -154,6 +154,10 @@ fn display_width(column: &Column<String>) -> f32 {
/// The canvas panel's least width in points, for the docking layout and the dock-edge layout.
pub(crate) const CANVAS_MIN_WIDTH: f32 = 200.0;
/// The narrowest column, in points, that still draws a panel's body; a narrower one shows only
/// its chrome. Deliberately independent of [`CANVAS_MIN_WIDTH`], although both are 200.
const PANEL_BODY_MIN_WIDTH: f32 = 200.0;
/// The least displayed width of a column: the app's 220-point panel minimum, unless the column is
/// iconic (its icons fit in the narrow width) or has no panels.
const MIN_COLUMN_WIDTH: f32 = 220.0;
@@ -1578,7 +1582,7 @@ impl craft_ui::docking::DockContent<String> for PanelContent<'_> {
}
// A window too small for the dock squeezes its column below the panels' minimum width,
// which their layouts do not take.
if !self.collapsed.contains(id) && ui.available_width() >= 200.0 {
if !self.collapsed.contains(id) && ui.available_width() >= PANEL_BODY_MIN_WIDTH {
let pro = crate::theme::Tokens::get(ui.ctx()).pro;
ui.spacing_mut().item_spacing.y = if pro { 0.0 } else { 6.0 };
egui::Frame::NONE.inner_margin(crate::widgets::body_margin(pro)).show(ui, |ui| body(self.app, ui, id));
@@ -1917,6 +1917,22 @@ fn a_narrow_window_draws_a_stored_dock_width_narrower_without_losing_it() {
assert!(dock.width() - 36.0 <= 364.5, "the drawn dock column fits beside the toolbox and canvas, got {dock:?}");
assert!(canvas.width() >= 199.5, "the canvas keeps its 200-point minimum, got {canvas:?} beside {dock:?}");
assert!(!canvas.intersect(dock).is_positive(), "the dock never overlaps the canvas: {canvas:?}, {dock:?}");
// `hit_rects` reports each control's full widget rect (`Response::rect`), not its clipped
// `interact_rect`, so a squeezed column may report chrome past the panel edge; what is drawn
// is that rect inside the panel's clip. No visible part may reach the toolbox, which sits
// between the canvas and the dock, or the canvas.
let toolbox = egui::Rect::from_x_y_ranges(canvas.right()..=dock.left(), dock.y_range());
let hits = craft_ui::docking::DockArea::<String>::hit_rects(&h.ctx, area_id());
assert!(hits.iter().any(|(_, rect)| rect.intersect(dock).is_positive()), "the dock drew visible controls: {hits:?}");
for (hit, rect) in &hits {
let visible = rect.intersect(dock);
if !visible.is_positive() {
continue;
}
assert!(dock.contains_rect(visible), "{hit:?}: {visible:?} outside {dock:?}");
assert!(!visible.intersect(canvas).is_positive(), "{hit:?}: {visible:?} reaches the canvas {canvas:?}");
assert!(!visible.intersect(toolbox).is_positive(), "{hit:?}: {visible:?} reaches the toolbox {toolbox:?}");
}
h.set_size(vec2(1280.0, 600.0));
h.run_steps(3);
assert!((dock_width(h.state()) - 520.0).abs() < 0.5, "growing the window keeps the stored width");