From 093922340595ce261895a6aa28ebde2b9874957a Mon Sep 17 00:00:00 2001 From: Dandaedre Date: Sat, 14 Nov 2026 13:11:58 +0100 Subject: [PATCH] Preserve example presentation across output formats --- crates/midra-layout/src/gui.rs | 58 ++++++++++++++++++--------------- crates/midra-layout/src/main.rs | 56 ++++++++++++++++++++----------- docs/midra-layout.md | 2 +- docs/midralayout/changelog.md | 2 ++ 4 files changed, 71 insertions(+), 47 deletions(-) diff --git a/crates/midra-layout/src/gui.rs b/crates/midra-layout/src/gui.rs index b831fbb..63489b5 100644 --- a/crates/midra-layout/src/gui.rs +++ b/crates/midra-layout/src/gui.rs @@ -2401,8 +2401,8 @@ impl Editor { } // 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 + let label_margin = if self.reference.is_none() { + SCREEN_LABEL_TOP * 4.0 * artwork_scale(output) } else { 0.0 }; @@ -2744,31 +2744,8 @@ impl Editor { Rect::from_min_size(origin, Vec2::new(sw, sh) * scale), output, ); - } else if output == [1920, 1080] { - screen_artwork(&screen, &self.backdrop_title); } else { - let rect = Rect::from_min_size(origin, Vec2::new(sw, sh) * scale); - screen.painter.rect_filled(rect, 0.0, palette.canvas); - for n in 0..=10 { - let t = n as f32 / 10.0; - screen.painter.line_segment( - [ - rect.left_top() + Vec2::new(rect.width() * t, 0.0), - rect.left_bottom() + Vec2::new(rect.width() * t, 0.0), - ], - Stroke::new(1.0_f32, palette.grid), - ); - screen.painter.line_segment( - [ - rect.left_top() + Vec2::new(0.0, rect.height() * t), - rect.right_top() + Vec2::new(0.0, rect.height() * t), - ], - Stroke::new(1.0_f32, palette.grid), - ); - } - } - if self.reference.is_none() && output != [1920, 1080] { - screen_title(&screen, &self.backdrop_title, output); + screen_artwork(&screen, &self.backdrop_title, output); } if self.reference.is_none() { screen_reference_hint(&screen, output); @@ -4075,7 +4052,14 @@ mod tests { #[test] fn example_title_renders_custom_and_blank_text_at_different_output_sizes() { - for output in [[1920, 1080], [1280, 720]] { + for output in [ + [1920, 1080], + [1280, 720], + [3840, 2160], + [1080, 1920], + [1024, 1024], + [3840, 1080], + ] { let ctx = egui::Context::default(); let mut app = Editor::default(); app.layout.set_output(output).unwrap(); @@ -4094,6 +4078,26 @@ mod tests { let custom = frame(&mut app, &ctx, vec![]); assert!(contains(&custom, "My conference")); assert!(!contains(&custom, "Example Conference Name")); + for label in [ + "Ideas worth sharing.".to_string(), + "SCREEN 1".to_string(), + format!("{} × {} px", output[0], output[1]), + ] { + let shape = custom + .shapes + .iter() + .find(|s| matches!(&s.shape, egui::Shape::Text(t) if t.galley.text() == label)) + .expect("example artwork remains visible"); + let egui::Shape::Text(text) = &shape.shape else { + unreachable!() + }; + assert!( + shape + .clip_rect + .contains_rect(Rect::from_min_size(text.pos, text.galley.size())), + "clipped {label} at {output:?}" + ); + } app.backdrop_title.clear(); assert!(!contains(&frame(&mut app, &ctx, vec![]), "My conference")); assert_eq!(app.layout.layers(), &before); diff --git a/crates/midra-layout/src/main.rs b/crates/midra-layout/src/main.rs index 6d29213..1639c7c 100644 --- a/crates/midra-layout/src/main.rs +++ b/crates/midra-layout/src/main.rs @@ -121,35 +121,53 @@ impl Ink { const SCREEN_LABEL_TOP: f32 = 24.0; -fn screen_artwork(ink: &Ink, title: &str) { +fn artwork_scale(output: [u32; 2]) -> f32 { + (output[0] as f32 / 1920.0).min(output[1] as f32 / 1080.0) +} + +fn screen_artwork(ink: &Ink, title: &str, output: [u32; 2]) { let palette = theme::palette(ink.painter.ctx()); - ink.text(0.0, -SCREEN_LABEL_TOP, "SCREEN 1", 12.0, palette.muted); + let width = output[0] as f32 / 2.0; + let height = output[1] as f32 / 2.0; + let k = artwork_scale(output); ink.text( - 790.0, - -SCREEN_LABEL_TOP, - "1920 × 1080 px", - 13.0, + 0.0, + -SCREEN_LABEL_TOP * k, + "SCREEN 1", + 12.0 * k, 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) { - ink.line( - [x as f32 / 2.0, 36.0], - [x as f32 / 2.0, 540.0], - palette.grid, - ); + ink.painter.text( + ink.point(width, -SCREEN_LABEL_TOP * k), + Align2::RIGHT_TOP, + format!("{} × {} px", output[0], output[1]), + FontId::proportional(13.0 * k * ink.scale), + palette.muted, + ); + ink.rect(0.0, 0.0, width, height, palette.canvas); + screen_title(ink, title, output); + for n in 0..=8 { + let x = width * n as f32 / 8.0; + ink.line([x, 36.0 * k], [x, height], palette.grid); } - for y in (180..=1080).step_by(180) { - ink.line([0.0, y as f32 / 2.0], [960.0, y as f32 / 2.0], palette.grid); + for n in 1..=6 { + let y = height * n as f32 / 6.0; + ink.line([0.0, y], [width, y], palette.grid); } - ink.text(24.0, 462.0, "Ideas worth sharing.", 27.0, palette.muted); + ink.text( + 24.0 * k, + height - 78.0 * k, + "Ideas worth sharing.", + 27.0 * k, + palette.muted, + ); } fn screen_title(ink: &Ink, title: &str, output: [u32; 2]) { let palette = theme::palette(ink.painter.ctx()); + let k = artwork_scale(output); let width = output[0] as f32 / 2.0; - let height = (output[1] as f32 / 2.0).min(36.0); + let height = 36.0 * k; let rect = Rect::from_min_max(ink.point(0.0, 0.0), ink.point(width, height)); let banner = Ink { painter: ink @@ -159,7 +177,7 @@ fn screen_title(ink: &Ink, title: &str, output: [u32; 2]) { scale: ink.scale, }; banner.rect(0.0, 0.0, width, height, palette.banner); - banner.text(24.0, 10.0, title, 13.0, palette.muted); + banner.text(24.0 * k, 10.0 * k, title, 13.0 * k, palette.muted); } fn screen_reference_hint(ink: &Ink, output: [u32; 2]) { diff --git a/docs/midra-layout.md b/docs/midra-layout.md index 6d9659c..3732d00 100644 --- a/docs/midra-layout.md +++ b/docs/midra-layout.md @@ -225,7 +225,7 @@ or use **Reset example title**. Up to 128 single-line characters are allowed. The title is clipped to the banner and appears only without an imported reference image, at any output resolution. It is not exported to SVG or sent to Midra. -The initial backdrop is illustrative; importing a reference picture replaces it. +The initial backdrop is illustrative and adapts to every output resolution/aspect ratio; importing a reference picture replaces it. Live video and verified hardware container/crop conversion remain future work. Project JSON save/load and SVG geometry export are implemented (see below). diff --git a/docs/midralayout/changelog.md b/docs/midralayout/changelog.md index c1b6c36..4e5f6ff 100644 --- a/docs/midralayout/changelog.md +++ b/docs/midralayout/changelog.md @@ -4,6 +4,8 @@ ## Unreleased +- Keep the example presentation visible for every output format, adapting its title, grid, tagline and screen labels to the new dimensions. + - Right-click a layer in the viewport or layer list to rename/delete it; list menus stay compact. Delete supports Undo and respects locked/hidden/last-layer protection. - Swap new-project default labels: top layer is 01 / Presenter, lower layer is 02 / Slides. Geometry, draw order and existing projects are unchanged.