Collapse viewport help when canvas space is constrained

This commit is contained in:
Dandaedre 2026-11-14 12:35:02 +01:00
parent a977e70311
commit 07380b0a9d
Signed by: Dandaedre
GPG Key ID: 440C6592E8A26D99
2 changed files with 89 additions and 6 deletions

View File

@ -2264,10 +2264,6 @@ impl Editor {
ui.painter()
.galley(ink.point(16.0, 64.0 + extra_height), status, color);
}
let area = Rect::from_min_max(
r.min + Vec2::new(8.0, canvas_top),
r.max - Vec2::new(8.0, 48.0),
);
// Artwork uses half-screen coordinates at twice the camera scale. Since
// the output stays centered, allow the label's overhang on both sides.
let label_margin = if self.reference.is_none() && output == [1920, 1080] {
@ -2275,6 +2271,15 @@ impl Editor {
} else {
0.0
};
// Help is optional: reclaim its footer when width is tight, or when it
// would reduce the fitted output's scale. Toolbar tooltips remain available.
let width_fitted_height = (r.width() - 40.0) / sw * (sh + label_margin) + 24.0;
let show_hints =
r.width() >= 760.0 && r.height() - canvas_top - 48.0 >= width_fitted_height;
let area = Rect::from_min_max(
r.min + Vec2::new(8.0, canvas_top),
r.max - Vec2::new(8.0, if show_hints { 48.0 } else { 8.0 }),
);
let base = ((area.width() - 24.0) / sw).min((area.height() - 24.0) / (sh + label_margin));
if self.camera_one_to_one {
self.zoom = (1.0 / (base * ui.ctx().pixels_per_point())).clamp(0.0001, 256.0);
@ -2848,7 +2853,8 @@ impl Editor {
);
}
}
ink.text(
if show_hints {
ink.text(
24.0,
r.height() - 40.0,
if self.navigation_tool == NavigationTool::Pan { "Pan tool · Drag to move the view · V: Move · Z: Zoom · Space/middle-drag pans from any tool" } else if self.navigation_tool == NavigationTool::Zoom { "Zoom tool · Click to zoom in · Alt-click to zoom out · Drag right/left to zoom · V: Move · H: Pan" } else if pivot_visible { "Pivot resize · Drag pivot to position · Double-click to center · Ctrl temporarily toggles pivot" } else if self.edit_content { "Crop mode · Drag crop handles to zoom content · Drag image to reposition · Click outside to finish" } else { match self.active_resize_mode() {
@ -2860,11 +2866,13 @@ impl Editor {
12.0,
palette.muted,
);
}
let missing =
self.layout.layers().iter().enumerate().any(|(i, g)| {
self.layout.visible(i) && layer_outside_view(*g, origin, scale, area)
});
ink.text(
if show_hints {
ink.text(
24.0,
r.height() - 22.0,
if missing {
@ -2879,6 +2887,20 @@ impl Editor {
palette.muted
},
);
} else if missing {
let warning = ui.painter().layout(
"Some layers are outside the view · Select them in the list, then Zoom to selection".into(),
FontId::proportional(12.0), palette.amber, (area.width() - 24.0).max(1.0),
);
let pos = Pos2::new(area.left() + 12.0, area.bottom() - warning.size().y - 8.0);
let painter = ui.painter_at(area);
painter.rect_filled(
Rect::from_min_size(pos, warning.size()).expand(4.0),
3.0,
palette.panel,
);
painter.galley(pos, warning, palette.amber);
}
}
}
fn layer_outside_view(g: Geometry, origin: Pos2, scale: f32, view: Rect) -> bool {
@ -3654,6 +3676,65 @@ mod tests {
);
frame(app, ctx, vec![mouse(pos, false)]);
}
#[test]
fn interaction_footer_collapses_and_returns_without_hiding_output_labels_or_warnings() {
let ctx = egui::Context::default();
let mut app = Editor::default();
for (size, hints) in [
(Vec2::new(1440.0, 940.0), true),
(Vec2::new(1440.0, 720.0), false),
(Vec2::new(1000.0, 940.0), false),
(Vec2::new(1440.0, 940.0), true),
] {
let _ = ctx.run(
egui::RawInput {
screen_rect: Some(Rect::from_min_size(Pos2::ZERO, size)),
..Default::default()
},
|ctx| app.ui(ctx),
);
let output = ctx.run(
egui::RawInput {
screen_rect: Some(Rect::from_min_size(Pos2::ZERO, size)),
..Default::default()
},
|ctx| app.ui(ctx),
);
for prefix in ["Corners resize", "Scroll to zoom"] {
assert_eq!(output.shapes.iter().any(|s| matches!(&s.shape, egui::Shape::Text(t) if t.galley.text().starts_with(prefix))), hints);
}
let canvas = ctx.read_response(egui::Id::new("canvas")).unwrap().rect;
assert_eq!(
canvas.bottom(),
size.y - 34.0 - if hints { 48.0 } else { 8.0 }
);
for label in ["SCREEN 1", "1920 × 1080 px"] {
let shape = output
.shapes
.iter()
.find(|s| matches!(&s.shape, egui::Shape::Text(t) if t.galley.text() == label))
.unwrap();
let egui::Shape::Text(text) = &shape.shape else {
unreachable!()
};
assert!(
shape
.clip_rect
.contains_rect(Rect::from_min_size(text.pos, text.galley.size()))
);
}
}
app.pan = Vec2::new(10000.0, 0.0);
let output = ctx.run(
egui::RawInput {
screen_rect: Some(Rect::from_min_size(Pos2::ZERO, Vec2::new(1000.0, 720.0))),
..Default::default()
},
|ctx| app.ui(ctx),
);
assert!(output.shapes.iter().any(|s| matches!(&s.shape, egui::Shape::Text(t) if t.galley.text().starts_with("Some layers are outside the view"))));
}
#[test]
fn fit_screen_keeps_output_labels_inside_the_viewport() {
for size in [

View File

@ -4,6 +4,8 @@
## Unreleased
- Hide bottom interaction hints when viewport space is tight, reclaiming their 40 px footer. Off-view layer warnings remain visible.
- Fit screen now includes the example backdrop’s Screen 1/resolution labels, preventing clipping in shorter/wider viewports.
- Move the reference drag/drop/import hint into the example artwork footer and reclaim its separate viewport status row. Image details and warnings remain above the view.