Default previews to follow input and warn about mismatched ratios

This commit is contained in:
Dandaedre 2026-11-18 19:10:27 +01:00
parent 5a574686a3
commit 36f841abe5
21 changed files with 253 additions and 9 deletions

2
Cargo.lock generated
View File

@ -602,7 +602,7 @@ dependencies = [
[[package]]
name = "canvas-pilot"
version = "0.10.0-rc.8"
version = "0.10.0-rc.9"
dependencies = [
"base64 0.22.1",
"craft-dwg",

View File

@ -4,7 +4,7 @@ default-members = ["crates/canvas-pilot"]
resolver = "3"
[workspace.package]
version = "0.10.0-rc.8"
version = "0.10.0-rc.9"
edition = "2024"
license = "MIT"
repository = "https://proxy.dandaedre.com/gitea/idle-org/canvas-pilot"

View File

@ -1,4 +1,7 @@
{
"ui.preview-ratio-mismatch": "Preview ratio mismatch",
"ui.preview-ratio-warning": "Preview has a different aspect ratio. Framing may be misleading; enable Follow input.",
"ui.preview-size-warning": "Preview has a different resolution. Enable Follow input to use the selected source.",
"ui.change-input": "Change input",
"ui.follow-input": "Follow input",
"ui.device-input": "Device input",

View File

@ -1,4 +1,7 @@
{
"ui.preview-ratio-mismatch": "Malsama bildformato de antaŭvido",
"ui.preview-ratio-warning": "La antaŭvido havas alian bildformaton. La enkadrigo povas misgvidi; ŝaltu Sekvi enigon.",
"ui.preview-size-warning": "La antaŭvido havas alian distingivon. Ŝaltu Sekvi enigon por uzi la elektitan fonton.",
"ui.change-input": "Change input",
"ui.follow-input": "Follow input",
"ui.device-input": "Device input",

View File

@ -1,4 +1,7 @@
{
"ui.preview-ratio-mismatch": "Relación de vista previa distinta",
"ui.preview-ratio-warning": "La vista previa tiene otra relación de aspecto. El encuadre puede ser engañoso; active Seguir entrada.",
"ui.preview-size-warning": "La vista previa tiene otra resolución. Active Seguir entrada para usar la fuente seleccionada.",
"ui.change-input": "Change input",
"ui.follow-input": "Follow input",
"ui.device-input": "Device input",

View File

@ -1,4 +1,7 @@
{
"ui.preview-ratio-mismatch": "Ratio de prévisualisation différent",
"ui.preview-ratio-warning": "Le ratio de la prévisualisation est différent. Le cadrage peut être trompeur ; activez Suivre l’entrée.",
"ui.preview-size-warning": "La résolution de la prévisualisation est différente. Activez Suivre l’entrée pour utiliser la source sélectionnée.",
"ui.change-input": "Changer l’entrée",
"ui.follow-input": "Suivre l’entrée",
"ui.device-input": "Entrée de l’appareil",

View File

@ -1,4 +1,7 @@
{
"ui.preview-ratio-mismatch": "Ἀνόμοιος λόγος προθεωρίας",
"ui.preview-ratio-warning": "Ἡ προθεωρία ἕτερον λόγον ἔχει· τὸ σχῆμα πλανᾶν δύναται. Τῇ εἰσόδῳ ἀκολούθει.",
"ui.preview-size-warning": "Ἡ προθεωρία ἕτερον μέγεθος ἔχει. Τῇ εἰσόδῳ ἀκολούθει, ἵνα τῇ ᾑρημένῃ πηγῇ χρῇ.",
"ui.change-input": "Change input",
"ui.follow-input": "Follow input",
"ui.device-input": "Device input",

View File

@ -1,4 +1,7 @@
{
"ui.preview-ratio-mismatch": "पूर्वावलोकन का अनुपात अलग है",
"ui.preview-ratio-warning": "पूर्वावलोकन का पहलू अनुपात अलग है। फ़्रेमिंग भ्रामक हो सकती है; इनपुट का अनुसरण सक्षम करें।",
"ui.preview-size-warning": "पूर्वावलोकन का रिज़ॉल्यूशन अलग है। चयनित स्रोत के लिए इनपुट का अनुसरण सक्षम करें।",
"ui.change-input": "Change input",
"ui.follow-input": "Follow input",
"ui.device-input": "Device input",

View File

@ -1,4 +1,7 @@
{
"ui.preview-ratio-mismatch": "プレビューの縦横比が異なります",
"ui.preview-ratio-warning": "プレビューの縦横比が異なるため、構図が正確でない場合があります。入力に追従を有効にしてください。",
"ui.preview-size-warning": "プレビューの解像度が異なります。選択したソースを使うには入力に追従を有効にしてください。",
"ui.change-input": "Change input",
"ui.follow-input": "Follow input",
"ui.device-input": "Device input",

View File

@ -1,4 +1,7 @@
{
"ui.preview-ratio-mismatch": "पूर्वावलोकनको अनुपात फरक छ",
"ui.preview-ratio-warning": "पूर्वावलोकनको पक्ष अनुपात फरक छ। फ्रेमिङ भ्रामक हुन सक्छ; इनपुट पछ्याउनुहोस् सक्षम गर्नुहोस्।",
"ui.preview-size-warning": "पूर्वावलोकनको रिजोलुसन फरक छ। चयन गरिएको स्रोत प्रयोग गर्न इनपुट पछ्याउनुहोस् सक्षम गर्नुहोस्।",
"ui.change-input": "Change input",
"ui.follow-input": "Follow input",
"ui.device-input": "Device input",

View File

@ -1,4 +1,7 @@
{
"ui.preview-ratio-mismatch": "Proporção da pré-visualização diferente",
"ui.preview-ratio-warning": "A pré-visualização tem outra proporção. O enquadramento pode ser enganador; ative Seguir entrada.",
"ui.preview-size-warning": "A pré-visualização tem outra resolução. Ative Seguir entrada para usar a fonte selecionada.",
"ui.change-input": "Change input",
"ui.follow-input": "Follow input",
"ui.device-input": "Device input",

View File

@ -1,4 +1,7 @@
{
"ui.preview-ratio-mismatch": "อัตราส่วนภาพตัวอย่างไม่ตรงกัน",
"ui.preview-ratio-warning": "ภาพตัวอย่างมีอัตราส่วนต่างกัน การจัดกรอบอาจทำให้เข้าใจผิด โปรดเปิดติดตามอินพุต",
"ui.preview-size-warning": "ภาพตัวอย่างมีความละเอียดต่างกัน เปิดติดตามอินพุตเพื่อใช้แหล่งสัญญาณที่เลือก",
"ui.change-input": "Change input",
"ui.follow-input": "Follow input",
"ui.device-input": "Device input",

View File

@ -1,4 +1,7 @@
{
"ui.preview-ratio-mismatch": "suli pi sitelen lukin li ante",
"ui.preview-ratio-warning": "nasin suli pi sitelen lukin li ante. sitelen li ken pana e sona ike. o kepeken sitelen pi tomo Follow input.",
"ui.preview-size-warning": "suli pi sitelen lukin li ante. o kepeken tomo Follow input tawa sitelen tan wile.",
"ui.change-input": "Change input",
"ui.follow-input": "Follow input",
"ui.device-input": "Device input",

View File

@ -1,4 +1,7 @@
{
"ui.preview-ratio-mismatch": "预览宽高比不匹配",
"ui.preview-ratio-warning": "预览宽高比不同,构图可能产生误导。请启用跟随输入。",
"ui.preview-size-warning": "预览分辨率不同。请启用跟随输入以使用所选信号源。",
"ui.change-input": "Change input",
"ui.follow-input": "Follow input",
"ui.device-input": "Device input",

View File

@ -1,5 +1,5 @@
use super::*;
use canvas_pilot::device_capture;
use canvas_pilot::{device, device_capture};
pub(super) const INPUT_REFERENCE_ROW_HEIGHT: f32 = 32.0;
type CaptureTarget = (usize, usize, u32, String);
type CaptureJob = std::sync::mpsc::Receiver<Result<super::super::reference::Reference, String>>;
@ -53,6 +53,28 @@ fn input_picker(
});
}
#[derive(Debug, PartialEq)]
struct PreviewMismatch {
expected: [u32; 2],
picture: [u32; 2],
ratio: bool,
}
impl PreviewMismatch {
fn compare(expected: [u32; 2], picture: [u32; 2]) -> Option<Self> {
if expected.contains(&0) || picture.contains(&0) || expected == picture {
return None;
}
let a = expected[0] as f64 / expected[1] as f64;
let b = picture[0] as f64 / picture[1] as f64;
// Ignore tiny ratio differences caused by integer pixel rounding.
Some(Self {
expected,
picture,
ratio: (a / b - 1.).abs() > 0.005,
})
}
}
struct LayerPreview {
input: u32,
host: String,
@ -389,6 +411,14 @@ impl Editor {
});
}
pub(super) fn default_preview_follow(&self, i: usize, input: u32) -> bool {
self.capture
.layers
.get(&self.layout.layer_info(i).id)
.is_none_or(|p| {
(p.input != 0 || p.bytes.is_empty()) && (p.input == 0 || p.input == input)
})
}
pub(super) fn layer_preview(&self, i: usize) -> Option<(egui::TextureId, f32)> {
self.capture
.layers
@ -396,6 +426,48 @@ impl Editor {
.filter(|p| p.enabled && p.source == self.layout.formats().source_for[i])
.and_then(|p| p.texture.as_ref().map(|t| (t.id(), p.guides)))
}
fn preview_mismatch(&self, i: usize) -> Option<PreviewMismatch> {
let preview = self.capture.layers.get(&self.layout.layer_info(i).id)?;
if !preview.enabled || preview.source != self.layout.formats().source_for[i] {
return None;
}
let snapshot = self.device.snapshot.as_ref();
let expected = snapshot
.and_then(|s| device::input_content_resolution(s, self.selected_physical_input(i)).ok())
.or_else(|| {
self.layout
.formats()
.input(i)
.ok()
.map(|size| size.map(|v| v.round() as u32))
})?;
let picture = if preview.input == 0 {
preview.texture.as_ref()?.size().map(|v| v as u32)
} else {
// Never mistake thumbnail resolution for the signal's dimensions,
// or compare a saved capture from another connection with this one.
if preview.host != self.device.host {
return None;
}
device::input_content_resolution(snapshot?, preview.input).ok()?
};
PreviewMismatch::compare(expected, picture)
}
pub(super) fn paint_preview_warning(&self, painter: &egui::Painter, rect: Rect, i: usize) {
if self.layer_preview(i).is_none() || !self.preview_mismatch(i).is_some_and(|m| m.ratio) {
return;
}
let painter = painter.with_clip_rect(painter.clip_rect().intersect(rect));
let label = tr(painter.ctx(), "ui.preview-ratio-mismatch");
let galley = painter.layout_no_wrap(label, FontId::proportional(12.), Color32::WHITE);
let pos = rect.left_top() + Vec2::new(8., 34.);
painter.rect_filled(
Rect::from_min_size(pos - Vec2::splat(3.), galley.size() + Vec2::splat(6.)),
3.,
Color32::from_rgb(130, 35, 35),
);
painter.galley(pos, galley, Color32::WHITE);
}
pub(super) fn preselect_linked_capture_inputs(&mut self) {
let Some(snapshot) = self.device.snapshot.as_ref() else {
return;
@ -633,12 +705,14 @@ impl Editor {
let idle = self.capture.pending.is_none();
let cooling = self.capture.cooling_down();
let chosen = self.selected_physical_input(i);
let follow = self.default_preview_follow(i, chosen);
let choice =
self.device
.source_choices
.entry(id)
.or_insert(super::device_ui::SourceChoice {
input: chosen,
follow,
..Default::default()
});
ui.checkbox(&mut choice.follow,tr(ui.ctx(), "ui.follow-input")).on_hover_text("Use the input selected in Source properties for this preview. This does not route the device layer.");
@ -727,6 +801,26 @@ impl Editor {
if let Some(input) = changed_input {
self.adapt_layer_to_input(i, input);
}
if let Some(mismatch) = self.preview_mismatch(i) {
let color = if mismatch.ratio {
ui.visuals().error_fg_color
} else {
theme::palette(ui.ctx()).amber
};
let key = if mismatch.ratio {
"ui.preview-ratio-warning"
} else {
"ui.preview-size-warning"
};
ui.colored_label(color, tr(ui.ctx(), key));
ui.small(format!(
"{} × {} → {} × {} px",
mismatch.picture[0],
mismatch.picture[1],
mismatch.expected[0],
mismatch.expected[1]
));
}
if !self.capture.error.is_empty() {
ui.colored_label(ui.visuals().error_fg_color, &self.capture.error);
}
@ -1144,6 +1238,76 @@ mod tests {
assert!(app.capture.pending.is_none());
}
#[test]
fn preview_mismatch_distinguishes_size_ratio_and_rounding() {
assert!(PreviewMismatch::compare([1920, 1080], [1920, 1080]).is_none());
assert!(
!PreviewMismatch::compare([1920, 1080], [1280, 720])
.unwrap()
.ratio
);
assert!(
!PreviewMismatch::compare([942, 1029], [468, 512])
.unwrap()
.ratio
);
assert!(
PreviewMismatch::compare([942, 1029], [1920, 1080])
.unwrap()
.ratio
);
assert!(PreviewMismatch::compare([0, 1080], [1920, 1080]).is_none());
}
#[test]
fn mismatch_uses_signal_sizes_not_capture_thumbnail_and_never_changes_layout() {
let ctx = egui::Context::default();
let mut app = Editor::default();
app.set_reference_picture(0, tiny_reference(&ctx, "thumbnail"));
let id = app.layout.layer_info(0).id;
app.device.source_choices.entry(id).or_default().input = 1;
let plug = |w, h| {
serde_json::json!({
"status":{"pp":{"plug":"HDMI"}},
"plugList":{"items":{"HDMI":{
"status":{"signal":{"pp":{"isValid":true,"imageWidth":w,"imageHeight":h}}},
"settings":{"cropping":{"control":{"pp":{"left":0,"right":0,"top":0,"bottom":0}}}}
}}}
})
};
app.device.snapshot = Some(device::Snapshot {
identity: "test".into(),
profile: device::Profile::Midra4k,
screens: vec![],
raw: serde_json::json!({"device":{"inputList":{"items":{"INPUT_1":plug(1920,1080),"INPUT_2":plug(1280,720)}}}}),
});
let preview = app.capture.layers.get_mut(&id).unwrap();
preview.input = 2;
preview.host = app.device.host.clone();
let before = app.layout.formats().clone();
assert!(!app.preview_mismatch(0).unwrap().ratio);
app.device.snapshot.as_mut().unwrap().raw["device"]["inputList"]["items"]["INPUT_2"] =
plug(942, 1029);
assert!(app.preview_mismatch(0).unwrap().ratio);
let _ = ctx.run_ui(Default::default(), |ui| {
app.paint_preview_warning(
ui.painter(),
Rect::from_min_size(Pos2::ZERO, Vec2::new(300., 300.)),
0,
);
});
assert_eq!(app.layout.formats(), &before);
app.capture.layers.get_mut(&id).unwrap().input = 1;
assert!(
app.preview_mismatch(0).is_none(),
"matching signals ignore thumbnail dimensions"
);
app.capture.layers.get_mut(&id).unwrap().input = 2;
app.capture.layers.get_mut(&id).unwrap().host = "other-device".into();
assert!(app.preview_mismatch(0).is_none());
app.capture.layers.get_mut(&id).unwrap().host = app.device.host.clone();
app.capture.layers.get_mut(&id).unwrap().enabled = false;
assert!(app.preview_mismatch(0).is_none());
}
#[test]
fn following_source_invalidates_old_capture_without_routing() {
let mut app = Editor::default();
@ -1157,7 +1321,7 @@ mod tests {
preview.bytes = vec![1, 2, 3];
let choice = app.device.source_choices.get_mut(&id).unwrap();
choice.input = 5;
choice.follow = true;
assert!(choice.follow, "new previews follow the source by default");
app.sync_followed_inputs();
let preview = &app.capture.layers[&id];
assert_eq!(preview.input, 5);
@ -1380,6 +1544,8 @@ mod tests {
frame(&mut app, &ctx, vec![]);
assert!(!app.capture.layers[&id].enabled);
click_text(&mut app, &ctx, "Enable input preview");
assert!(app.device.source_choices[&id].follow);
click_text(&mut app, &ctx, "Follow input");
click_text(&mut app, &ctx, "Choose input…");
click_text(&mut app, &ctx, "Input 3");
assert!(app.capture.layers[&id].enabled);
@ -1780,6 +1946,8 @@ mod tests {
.any(|s| matches!(&s.shape, egui::Shape::Text(t) if t.galley.text() == label))
};
click_text(&mut app, &ctx, "Enable input preview");
assert!(app.device.source_choices[&id].follow);
click_text(&mut app, &ctx, "Follow input");
click_text(&mut app, &ctx, "Choose input…");
let output = frame(&mut app, &ctx, vec![]);
assert!(contains(&output, "Input 3"));

View File

@ -42,12 +42,21 @@ impl DeviceFailure {
}
}
#[derive(Clone, Copy, Default)]
#[derive(Clone, Copy)]
pub(super) struct SourceChoice {
pub input: u32,
pub change: bool,
pub follow: bool,
}
impl Default for SourceChoice {
fn default() -> Self {
Self {
input: 0,
change: false,
follow: true,
}
}
}
#[derive(Clone)]
struct SendConflict {
host: String,
@ -714,6 +723,7 @@ impl Editor {
}
pub(super) fn source_input_controls(&mut self, ui: &mut egui::Ui, i: usize) {
let input = self.selected_physical_input(i);
let follow = self.default_preview_follow(i, input);
let available = self
.device
.snapshot
@ -726,6 +736,7 @@ impl Editor {
.entry(self.layout.layer_info(i).id)
.or_insert(SourceChoice {
input,
follow,
..Default::default()
});
let previous = (choice.input, choice.change);

View File

@ -517,6 +517,7 @@ impl Editor {
let (_,rect)=ui.allocate_space(Vec2::new(ui.available_width(),170.0));
let preview_rect=fit_rect(rect,[current.width,current.height]);
paint_layer_source(ui.painter(),preview_rect,&self.layout,i,self.layer_preview(i));
self.paint_preview_warning(ui.painter(), preview_rect, i);
ui.label(tr(ui.ctx(), "ui.captured-stills-follow-this-layer-s-input-and-dynamic-crops-guides-are-drawn-above-th"));
}
if !d.error.is_empty() {ui.colored_label(theme::palette(ui.ctx()).amber,&d.error);}

View File

@ -3894,6 +3894,7 @@ impl Editor {
(texture, if show_guides { opacity } else { 0.0 })
}),
);
self.paint_preview_warning(p, rect, i);
p.rect_stroke(rect, 0.0, border, StrokeKind::Inside);
}
if rect.width() > 85.0 && rect.height() > 40.0 {

View File

@ -4,6 +4,13 @@
## Unreleased
### v0.10.0-rc.9
- New preview controls default to Follow input. Independent preview inputs show
resolution warnings and stronger ratio warnings, including a canvas/preview
overlay. Compare processed signal dimensions, not reduced capture thumbnails;
existing image framing and explicit reference-picture choices are preserved.
### v0.10.0-rc.8
- Support switching to cropped Midra inputs using their processed image dimensions,

View File

@ -256,17 +256,26 @@ to route the mapped destination layer to that input on the next explicit **Send*
Selecting an input alone does not change the device. Leave the checkbox off to
send geometry without changing its source.
In **Preview**, enable **Follow input** to capture the input selected in Source.
In **Preview**, **Follow input** is enabled by default for new controls and captures the input selected in Source.
Enable input preview as usual; automatic refresh remains a separate option.
Following an input does not route it, and changing the selection clears the old
picture before requesting a new capture.
An independently selected preview with a different processed resolution shows an
amber notice. A different aspect ratio shows a stronger warning and a **Preview
ratio mismatch** overlay on the canvas and Preview tab. Enable **Follow input**
to match the selected source. These notices do not alter crop, fit or device
routing. Reduced-resolution capture thumbnails do not trigger size warnings;
intentional differences between the layer box and its source are not mismatches.
Discarding local changes in the send conflict dialog also clears these choices for the reloaded layers.
These selections are session-only and reset when a project or connection is
replaced; they are not saved in projects or exchange files. Input switching requires
a valid signal with native dimensions matching the editor source format and no
input crop/aspect correction. Unsupported combinations stop preparation with an
error. Sending to Program can visibly change the live source.
a valid signal. Midra inputs with applied crop are supported; framing adapts to
the processed input dimensions using the layer’s fit settings. Input aspect
correction and Aquilon shared input crop remain unsupported. Sending to Program can visibly change the live source.
### Live picture in the input crop editor

View File

@ -211,3 +211,14 @@ checks nonnegative finite crop edges and, for active crop, verifies
blocks the operation. Send conversion uses processed dimensions directly and
observes the input state for preflight; no input crop writes are generated.
Aquilon cropping and aspect-corrected input switching are not enabled by this rule.
New session source choices default to Follow input; Change input remains opt-in.
Loading a local reference picture still disables following. Existing preview
bindings are not rewritten merely by reopening a project. Mismatch notices compare
processed device input dimensions on the current connection (or actual local
picture dimensions) with the selected source, falling back to editor source size.
They never compare a device thumbnail's resolution with the full signal size.
A relative ratio difference above 0.5% receives a stronger notice and viewer overlay;
smaller differences receive only a resolution notice. No schema or image-transform
change is involved.