Request a fresh still when enabling an input preview

This commit is contained in:
Dandaedre 2026-11-19 08:32:22 +01:00
parent cbbcde2a92
commit a872be4766
6 changed files with 131 additions and 11 deletions

2
Cargo.lock generated
View File

@ -602,7 +602,7 @@ dependencies = [
[[package]]
name = "canvas-pilot"
version = "0.10.0-rc.13"
version = "0.10.0-rc.14"
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.13"
version = "0.10.0-rc.14"
edition = "2024"
license = "MIT"
repository = "https://proxy.dandaedre.com/gitea/idle-org/canvas-pilot"

View File

@ -616,10 +616,19 @@ impl Editor {
return;
};
ui.separator();
ui.checkbox(
&mut preview.enabled,
tr(ui.ctx(), "ui.enable-input-preview"),
);
if ui
.checkbox(
&mut preview.enabled,
tr(ui.ctx(), "ui.enable-input-preview"),
)
.changed()
{
preview.capture_on_selection = preview.enabled && preview.input != 0;
if preview.enabled {
preview.paused = false;
}
ui.ctx().request_repaint();
}
let has_image = preview.enabled
&& preview.texture.is_some()
&& preview.source == self.layout.formats().source_for[i];
@ -834,11 +843,12 @@ impl Editor {
tr(ui.ctx(), "ui.enable-input-preview"),
)
.changed()
&& preview.enabled
&& following
{
preview.capture_on_selection = preview.input != 0;
preview.paused = false;
preview.capture_on_selection = preview.enabled && preview.input != 0;
if preview.enabled {
preview.paused = false;
}
ui.ctx().request_repaint();
}
let mut capture = false;
let mut changed_input = (follow_enabled && chosen != 0).then_some(chosen);
@ -2322,6 +2332,98 @@ mod tests {
assert!(app.capture.error.is_empty());
assert!(app.references.is_empty());
}
#[test]
fn quick_preview_enable_queues_one_still_without_enabling_auto_refresh() {
let ctx = egui::Context::default();
let mut app = Editor::default();
app.capture.test_now = Some(std::time::Instant::now());
app.device.host = "127.0.0.1".into();
app.device.snapshot = Some(canvas_pilot::device::Snapshot {
profile: Default::default(),
identity: "Test".into(),
screens: vec![],
raw: serde_json::json!({"device":{"inputList":{"items":{
"INPUT_3":{"status":{"pp":{"isAvailable":true,"plug":"1"}},"snapshot":{"pp":{"enable":true}}}
}}}}),
});
let i = app.layout.selected().unwrap();
let id = app.layout.layer_info(i).id;
let source = app.layout.formats().source_for[i];
app.capture.layers.insert(
id,
LayerPreview {
input: 3,
host: app.device.host.clone(),
source,
texture: None,
bytes: vec![],
paused: true,
automatic: false,
capture_on_selection: false,
name: String::new(),
enabled: false,
guides: 0.25,
},
);
let draw = |app: &mut Editor, events| {
ctx.run_ui(
egui::RawInput {
screen_rect: Some(Rect::from_min_size(Pos2::ZERO, Vec2::new(600.0, 400.0))),
events,
..Default::default()
},
|ui| app.crop_preview_quick_controls(ui, i),
)
};
let output = draw(&mut app, vec![]);
let pos = output
.shapes
.iter()
.find_map(|shape| match &shape.shape {
egui::Shape::Text(t) if t.galley.text() == "Enable input preview" => {
Some(t.pos + Vec2::splat(4.0))
}
_ => None,
})
.unwrap();
let click = |app: &mut Editor| {
for pressed in [true, false] {
draw(
app,
vec![
egui::Event::PointerMoved(pos),
egui::Event::PointerButton {
pos,
button: egui::PointerButton::Primary,
pressed,
modifiers: Default::default(),
},
],
);
}
};
click(&mut app);
assert!(app.capture.layers[&id].capture_on_selection);
assert!(!app.capture.layers[&id].automatic);
assert!(!app.capture.layers[&id].paused);
assert_eq!(app.capture.layers[&id].guides, 0.25);
app.capture.last_request = Some(app.capture.now());
assert!(app.next_selection_capture().is_none()); // cooldown keeps it queued
app.capture.last_request = None;
assert_eq!(
app.next_selection_capture(),
Some((3, Some((id, source, 3, app.device.host.clone()))))
);
assert!(app.next_selection_capture().is_none()); // one-shot
click(&mut app); // disable
assert!(!app.capture.layers[&id].enabled);
assert!(!app.capture.layers[&id].capture_on_selection);
app.capture.layers.get_mut(&id).unwrap().input = 0; // local picture / unchosen input
click(&mut app);
assert!(app.capture.layers[&id].enabled);
assert!(!app.capture.layers[&id].capture_on_selection);
}
#[test]
fn layer_preview_toggle_keeps_opacity_and_follows_stable_layer_id() {
let ctx = egui::Context::default();

View File

@ -4,6 +4,13 @@
## Unreleased
### v0.10.0-rc.14
- Enabling an input preview from the right-click menu or Preview properties queues
its first still immediately, without requiring auto-refresh. Keep capture
cooldown, single-request scheduling and local-picture behavior. UI regression
coverage checks one-shot scheduling, disabling and the cooldown.
### v0.10.0-rc.13
- Tolerate up to one output pixel of device rounding when importing Centered/Cropped

View File

@ -379,6 +379,12 @@ The old local source pre-crop model and saved input proposals have been removed.
Projects retain processed source dimensions and independent layer framing; legacy
native projects can be opened with a reported best-effort recovery.
Enabling **Enable input preview** in the right-click menu or Preview properties
requests a fresh still for the configured input immediately. It does not enable
recurring auto-refresh. A capture already in progress or the five-second request
cooldown can defer that request; no device request is made for a local picture or
when no capture input is configured.
### Captured picture proportions
Input captures and local reference pictures fit centered inside the source format

View File

@ -16,7 +16,7 @@ The connected snapshot's `/device/inputList/items/INPUT_N` supplies:
- `snapshot.pp.enable`: capture is disabled in the editor when WebRCS snapshots
are disabled. The application does not write this field or snapshot size.
Each input-selection capture, explicit **Capture still**, or automatic timer request issues
Each input-selection capture, preview-enable capture, explicit **Capture still**, or automatic timer request issues
`GET http://<configured-IP>/api/device/snapshots/inputs/N`, with N an integer
1–16 and `Cache-Control: no-cache`. IPv4 and IPv6 literal addresses are accepted;
no proxy or redirect is followed. No immediate retries, WebSocket subscription,
@ -117,6 +117,11 @@ can share the result too, but still requires explicit import. Changed, removed o
disabled targets reject the result; other inputs keep their own requests.
Existing manual stills without a queued capture are never replaced by another
layer's capture.
Enabling a configured input preview from the context menu or Preview properties
also queues a one-shot capture, including when auto-refresh is off. Disabling
clears that queued request; local pictures (input zero) never queue one. The same
connection/source validation, in-flight request and cooldown gates apply.
Selecting an input queues a one-shot capture in either picker, including the first
signal-bearing input selected when opening snapshot import. Selection captures
use the shared five-second minimum rather than waiting the configured refresh