Include backdrop labels when fitting the output screen

This commit is contained in:
Dandaedre 2026-11-14 12:32:58 +01:00
parent 9feec20019
commit a977e70311
Signed by: Dandaedre
GPG Key ID: 440C6592E8A26D99
3 changed files with 59 additions and 3 deletions

View File

@ -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]] {

View File

@ -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) {

View File

@ -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.