From 993b0b1b759210ac08de18d7008c2c75efbb8959 Mon Sep 17 00:00:00 2001 From: Dandaedre Date: Sat, 14 Nov 2026 11:57:26 +0100 Subject: [PATCH] Distinguish hidden viewport layers from output overflow --- crates/midra-layout/src/gui.rs | 148 ++++++++++++++++++++++++++--- crates/midra-layout/src/menu_ui.rs | 2 +- docs/midra-layout.md | 2 +- docs/midralayout/changelog.md | 2 + 4 files changed, 138 insertions(+), 16 deletions(-) diff --git a/crates/midra-layout/src/gui.rs b/crates/midra-layout/src/gui.rs index be76a5b..42a680f 100644 --- a/crates/midra-layout/src/gui.rs +++ b/crates/midra-layout/src/gui.rs @@ -877,7 +877,7 @@ impl Editor { let (r, _) = ui.allocate_exact_size( Vec2::new( ui.available_width(), - 1060.0 + (self.layout.layers().len() as f32 - 2.0) * 44.0, + 1084.0 + (self.layout.layers().len() as f32 - 2.0) * 44.0, ), egui::Sense::hover(), ); @@ -1228,15 +1228,14 @@ impl Editor { Rect::from_min_size(ink.point(0.0, 603.0), Vec2::new(w, 55.0)), egui::Label::new(egui::RichText::new(&self.error).color(palette.amber)).wrap(), ); - } else if g.outside_on(self.layout.formats().output) { - ink.text( - 0.0, - 607.0, - "Outside screen · use Fit selected to find it", - 12.0, - palette.amber, + } else if let Some(message) = output_bounds_warning(g, self.layout.formats().output) { + ui.put( + Rect::from_min_size(ink.point(0.0, 603.0), Vec2::new(w, 55.0)), + egui::Label::new(egui::RichText::new(message).size(12.0).color(palette.amber)) + .wrap(), ); } + let ink = Ink::new(ui, r.translate(Vec2::new(0.0, 132.0))); ink.line([0.0, 640.0], [w, 640.0], palette.line); ink.text( 0.0, @@ -1730,7 +1729,7 @@ impl Editor { ink.line([separator, 28.0], [separator, 48.0], palette.line); for (x, text, icon) in [ (positions[0], "Fit screen", ToolbarIcon::Screen), - (positions[1], "Fit selected", ToolbarIcon::Selection), + (positions[1], "Zoom to selection", ToolbarIcon::Selection), (positions[2], "Undo", ToolbarIcon::Undo), (positions[3], "Redo", ToolbarIcon::Redo), ] { @@ -1738,7 +1737,7 @@ impl Editor { if toolbar_icon(ui, rect, text, icon).clicked() { match text { "Fit screen" => self.fit_screen(), - "Fit selected" => self.fit_selection(), + "Zoom to selection" => self.fit_selection(), "Undo" => { self.layout.undo(); self.sync(); @@ -1891,7 +1890,7 @@ impl Editor { for (x, label) in [ (42.0, "Output"), (positions[0] + 16.0, "Fit screen"), - (positions[1] + 16.0, "Fit selected"), + (positions[1] + 16.0, "Zoom to selection"), (positions[2] + 16.0, "Undo"), (positions[3] + 16.0, "Redo"), (align_x + 18.0, "Align"), @@ -2418,15 +2417,53 @@ 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( 24.0, r.height() - 22.0, - "Scroll to zoom · Space-drag to pan · Reference image stays fixed", + if missing { + "Some layers are outside the view · Select them in the list, then Zoom to selection" + } else { + "Scroll to zoom · Space-drag to pan · Reference image stays fixed" + }, 12.0, - palette.muted, + if missing { + palette.amber + } else { + palette.muted + }, ); } } +fn layer_outside_view(g: Geometry, origin: Pos2, scale: f32, view: Rect) -> bool { + let rect = Rect::from_min_size( + origin + Vec2::new(g.x as f32, g.y as f32) * scale, + Vec2::new(g.width as f32, g.height as f32) * scale, + ); + !rect.intersect(view).is_positive() +} + +fn output_bounds_warning(g: Geometry, output: [u32; 2]) -> Option<&'static str> { + if !g.outside_on(output) { + None + } else if g.x + g.width <= 0.0 + || g.y + g.height <= 0.0 + || g.x >= output[0] as f64 + || g.y >= output[1] as f64 + { + Some( + "Layer is entirely outside the output screen. If unintended, use alignment tools or edit its position.", + ) + } else { + Some( + "Layer is partially outside the output screen. If unintended, use alignment tools or edit its position.", + ) + } +} + fn crop_handle_positions(rect: Rect) -> [(ResizeHandle, Pos2); 8] { ResizeHandle::positions(Geometry { x: rect.min.x as f64, @@ -3000,7 +3037,7 @@ fn toolbar_icon(ui: &mut egui::Ui, rect: Rect, label: &str, icon: ToolbarIcon) - response.on_hover_text(match icon { ToolbarIcon::Output => "Output format — screen ratio and resolution", ToolbarIcon::Screen => "Fit screen — show the entire output", - ToolbarIcon::Selection => "Fit selected — frame the selected layers", + ToolbarIcon::Selection => "Zoom to selection — frame the selected layers", ToolbarIcon::Undo => "Undo (Ctrl/Cmd+Z)", ToolbarIcon::Redo => "Redo (Ctrl/Cmd+Shift+Z)", }) @@ -3050,6 +3087,89 @@ mod tests { ); frame(app, ctx, vec![mouse(pos, false)]); } + #[test] + fn viewport_visibility_and_output_overflow_are_independent() { + let inside = Geometry { + x: 100.0, + y: 100.0, + width: 200.0, + height: 100.0, + }; + let partial = Geometry { + x: -100.0, + ..inside + }; + let outside = Geometry { + x: -200.0, + ..inside + }; + let view = Rect::from_min_size(Pos2::ZERO, Vec2::new(1920.0, 1080.0)); + assert!(output_bounds_warning(inside, [1920, 1080]).is_none()); + assert!( + output_bounds_warning(partial, [1920, 1080]) + .unwrap() + .contains("partially") + ); + assert!( + output_bounds_warning(outside, [1920, 1080]) + .unwrap() + .contains("entirely") + ); + assert!(!layer_outside_view(partial, Pos2::ZERO, 1.0, view)); + assert!(layer_outside_view(outside, Pos2::ZERO, 1.0, view)); + // A pan can hide an in-bounds layer or reveal an out-of-bounds layer. + assert!(layer_outside_view( + inside, + Pos2::new(2000.0, 0.0), + 1.0, + view + )); + assert!(!layer_outside_view( + outside, + Pos2::new(500.0, 0.0), + 0.5, + view + )); + let right = Geometry { + x: 1920.0, + ..inside + }; + let bottom = Geometry { + y: 1080.0, + ..inside + }; + for g in [right, bottom] { + assert!(layer_outside_view(g, Pos2::ZERO, 1.0, view)); + assert!( + output_bounds_warning(g, [1920, 1080]) + .unwrap() + .contains("entirely") + ); + } + } + + #[test] + fn viewport_warning_only_counts_visible_fully_missing_layers() { + let ctx = egui::Context::default(); + let mut app = Editor::default(); + let warning = |out: &egui::FullOutput| { + out.shapes.iter().any(|shape| matches!( + &shape.shape, egui::Shape::Text(text) if text.galley.text().starts_with("Some layers are outside the view") + )) + }; + assert!(!warning(&frame(&mut app, &ctx, vec![]))); + let g = Geometry { + x: -10000.0, + ..app.layout.layers()[0] + }; + app.layout.apply(0, g).unwrap(); + assert!(warning(&frame(&mut app, &ctx, vec![]))); + app.layout.set_visible(0, false); + assert!(!warning(&frame(&mut app, &ctx, vec![]))); + app.pan = Vec2::new(10000.0, 0.0); + assert!(warning(&frame(&mut app, &ctx, vec![]))); + } + #[test] fn center_marker_switches_reference_without_moving_and_resizes_about_center() { let ctx = egui::Context::default(); diff --git a/crates/midra-layout/src/menu_ui.rs b/crates/midra-layout/src/menu_ui.rs index 904a175..a0c0103 100644 --- a/crates/midra-layout/src/menu_ui.rs +++ b/crates/midra-layout/src/menu_ui.rs @@ -250,7 +250,7 @@ impl Editor { if ui .add_enabled( self.layout.selection_bounds().is_some(), - egui::Button::new("Fit selected"), + egui::Button::new("Zoom to selection"), ) .clicked() { diff --git a/docs/midra-layout.md b/docs/midra-layout.md index 1cacf12..78bd41a 100644 --- a/docs/midra-layout.md +++ b/docs/midra-layout.md @@ -135,7 +135,7 @@ clipboard testing against a running draw.io instance remains to be done. records. View changes and selection are not document edits. - Scroll over the viewport to zoom around the pointer. Space-drag or middle-drag pans. In the compact toolbar’s view group, **Fit screen** resets the view and - **Fit selected** frames the entire selection. A divider separates view tools from Undo/Redo. Hover an icon for its label. + **Zoom to selection** frames the entire selection. A view warning appears only when a visible layer is completely out of view; select it in the layer list to frame it. The inspector separately flags layers partly or entirely beyond the output screen and suggests alignment or position edits. A divider separates view tools from Undo/Redo. Hover an icon for its label. Camera changes do not modify coordinates. Off-screen layers retain their exact coordinates, display a warning and remain selectable through the layer list. - **Copy position values** (or **Copy selected positions** for multiple layers) diff --git a/docs/midralayout/changelog.md b/docs/midralayout/changelog.md index 45c8921..519129e 100644 --- a/docs/midralayout/changelog.md +++ b/docs/midralayout/changelog.md @@ -4,6 +4,8 @@ ## Unreleased +- Distinguish completely out-of-view layers from partial/complete output-screen overflow; give navigation versus positioning advice. Rename Fit selected to Zoom to selection. + - Give the canvas more space: compact reference hint/status, tighter viewport margins and footer. Warnings still wrap. Fix resize edge snapping at fractional viewport scales. - Add center to “Measure position from”; numeric resizing preserves center offsets. Project v6 saves the reference and migrates v1–5 corners.