From a977e703110f479c3568d3e7bdaa669000980fda Mon Sep 17 00:00:00 2001 From: Dandaedre Date: Sat, 14 Nov 2026 12:32:58 +0100 Subject: [PATCH] Include backdrop labels when fitting the output screen --- crates/midra-layout/src/gui.rs | 48 ++++++++++++++++++++++++++++++++- crates/midra-layout/src/main.rs | 12 +++++++-- docs/midralayout/changelog.md | 2 ++ 3 files changed, 59 insertions(+), 3 deletions(-) diff --git a/crates/midra-layout/src/gui.rs b/crates/midra-layout/src/gui.rs index 2098191..e566c46 100644 --- a/crates/midra-layout/src/gui.rs +++ b/crates/midra-layout/src/gui.rs @@ -2268,7 +2268,14 @@ impl Editor { r.min + Vec2::new(8.0, canvas_top), r.max - Vec2::new(8.0, 48.0), ); - let base = ((area.width() - 24.0) / sw).min((area.height() - 24.0) / sh); + // 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] { + SCREEN_LABEL_TOP * 4.0 + } else { + 0.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); self.camera_one_to_one = false; @@ -3647,6 +3654,45 @@ mod tests { ); frame(app, ctx, vec![mouse(pos, false)]); } + #[test] + fn fit_screen_keeps_output_labels_inside_the_viewport() { + for size in [ + Vec2::new(1000.0, 720.0), + Vec2::new(1440.0, 940.0), + Vec2::new(2000.0, 720.0), + ] { + for captions in [false, true] { + let ctx = egui::Context::default(); + let mut app = Editor { + show_toolbar_icon_names: captions, + zoom: 3.0, + pan: Vec2::new(100.0, -200.0), + ..Default::default() + }; + app.fit_screen(); + let output = ctx.run( + egui::RawInput { + screen_rect: Some(Rect::from_min_size(Pos2::ZERO, size)), + ..Default::default() + }, + |ctx| app.ui(ctx), + ); + 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!() + }; + let bounds = Rect::from_min_size(text.pos, text.galley.size()); + assert!( + shape.clip_rect.contains_rect(bounds), + "{label} at {size:?}: {bounds:?} clipped by {:?}", + shape.clip_rect + ); + } + } + } + } + #[test] fn example_title_renders_custom_and_blank_text_at_different_output_sizes() { for output in [[1920, 1080], [1280, 720]] { diff --git a/crates/midra-layout/src/main.rs b/crates/midra-layout/src/main.rs index fe81a19..6d29213 100644 --- a/crates/midra-layout/src/main.rs +++ b/crates/midra-layout/src/main.rs @@ -119,10 +119,18 @@ impl Ink { } } +const SCREEN_LABEL_TOP: f32 = 24.0; + fn screen_artwork(ink: &Ink, title: &str) { let palette = theme::palette(ink.painter.ctx()); - ink.text(0.0, -24.0, "SCREEN 1", 12.0, palette.muted); - ink.text(790.0, -24.0, "1920 × 1080 px", 13.0, palette.muted); + ink.text(0.0, -SCREEN_LABEL_TOP, "SCREEN 1", 12.0, palette.muted); + ink.text( + 790.0, + -SCREEN_LABEL_TOP, + "1920 × 1080 px", + 13.0, + palette.muted, + ); ink.rect(0.0, 0.0, 960.0, 540.0, palette.canvas); screen_title(ink, title, [1920, 1080]); for x in (0..=1920).step_by(240) { diff --git a/docs/midralayout/changelog.md b/docs/midralayout/changelog.md index e1f74cc..519db54 100644 --- a/docs/midralayout/changelog.md +++ b/docs/midralayout/changelog.md @@ -4,6 +4,8 @@ ## Unreleased +- 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. - Default backdrop title is “Example Conference Name”; edit/reset it in Options → Example backdrop or Settings → Reference images. Project v7 saves the title and migrates v1–6.