From 2388d9e4c08bf3230e7c33bf2d528337f3448ecd Mon Sep 17 00:00:00 2001 From: Dandaedre Date: Sat, 14 Nov 2026 18:48:36 +0100 Subject: [PATCH] Hide no-signal preview inputs by default --- crates/midra-layout/src/capture_ui.rs | 140 ++++++++++++++++++++++--- docs/interfaces/midra-input-preview.md | 13 +++ docs/midra-layout/README.md | 5 +- docs/midra-layout/changelog.md | 2 + 4 files changed, 142 insertions(+), 18 deletions(-) diff --git a/crates/midra-layout/src/capture_ui.rs b/crates/midra-layout/src/capture_ui.rs index d9297c3..0730525 100644 --- a/crates/midra-layout/src/capture_ui.rs +++ b/crates/midra-layout/src/capture_ui.rs @@ -2,6 +2,51 @@ use super::*; use midra_layout::device_capture; type CaptureJob = std::sync::mpsc::Receiver>; +fn input_label(inputs: &[device_capture::Input], selected: u32) -> String { + if selected == 0 { + return "Choose input…".into(); + } + let suffix = match inputs.iter().find(|input| input.id == selected) { + Some(input) if !input.signal => " · No signal", + Some(_) => "", + None => " · Unavailable", + }; + format!("Input {selected}{suffix}") +} +fn input_picker( + ui: &mut egui::Ui, + salt: impl std::hash::Hash, + selected: &mut u32, + inputs: &[device_capture::Input], + show_empty: &mut bool, +) { + egui::ComboBox::from_id_salt(salt) + .close_behavior(egui::PopupCloseBehavior::CloseOnClickOutside) + .selected_text(input_label(inputs, *selected)) + .show_ui(ui, |ui| { + ui.checkbox(show_empty, "Show inputs without signal") + .on_hover_text("Signal status comes from the last connection refresh."); + ui.separator(); + let mut any = false; + for input in inputs.iter().filter(|input| *show_empty || input.signal) { + any = true; + if ui + .selectable_value(selected, input.id, input_label(inputs, input.id)) + .clicked() + { + ui.memory_mut(|memory| memory.close_popup()); + } + } + if !any { + ui.small(if *show_empty { + "No available inputs." + } else { + "No inputs with signal. Enable the toggle above to see empty inputs." + }); + } + }); +} + struct LayerPreview { input: u32, host: String, @@ -33,6 +78,7 @@ pub(super) struct CaptureUi { input: u32, target_layer: Option, keep_refreshing: bool, + show_empty_inputs: bool, layers: std::collections::BTreeMap, host: String, pending: Option, @@ -176,13 +222,7 @@ impl Editor { let mut capture = false; ui.add_enabled_ui(preview.enabled, |ui| { let before = preview.input; - egui::ComboBox::from_id_salt(("layer-preview-input", id)) - .selected_text(if preview.input == 0 { "Choose input…".into() } else { format!("Input {}", preview.input) }) - .show_ui(ui, |ui| { - for input in &inputs { - ui.selectable_value(&mut preview.input, input.id, format!("Input {}", input.id)); - } - }); + input_picker(ui, ("layer-preview-input", id), &mut preview.input, &inputs, &mut self.capture.show_empty_inputs); if before != preview.input { preview.texture = None; preview.name.clear(); @@ -299,7 +339,11 @@ impl Editor { self.capture.input = inputs .iter() .find(|i| i.signal && i.enabled) - .or(inputs.first()) + .or_else(|| { + inputs + .iter() + .find(|i| self.capture.show_empty_inputs || i.signal) + }) .map(|i| i.id) .unwrap_or(0); } @@ -317,11 +361,7 @@ impl Editor { ui.small("Snapshots are reduced-resolution images, not a live feed. Their size depends on the device's snapshot settings."); let before = self.capture.input; ui.add_enabled_ui(self.capture.pending.is_none(), |ui| { - egui::ComboBox::from_label("Input").selected_text(format!("Input {}", self.capture.input)).show_ui(ui, |ui| { - for input in &inputs { - ui.selectable_value(&mut self.capture.input, input.id, format!("Input {}{}", input.id, if input.signal { "" } else { " · no signal at last refresh" })); - } - }); + input_picker(ui, "import-snapshot-input", &mut self.capture.input, &inputs, &mut self.capture.show_empty_inputs); }); if before != self.capture.input { self.capture.preview = None; self.capture.pending = None; self.capture.error.clear(); } let input = inputs.iter().find(|i| i.id == self.capture.input); @@ -448,7 +488,7 @@ mod tests { identity: "Test".into(), screens: vec![], raw: serde_json::json!({"device":{"inputList":{"items":{ - "INPUT_3":{"status":{"pp":{"isAvailable":true,"plug":"1"}},"snapshot":{"pp":{"enable":true}}}, + "INPUT_3":{"status":{"pp":{"isAvailable":true,"plug":"1"}},"snapshot":{"pp":{"enable":true}},"plugList":{"items":{"1":{"status":{"signal":{"pp":{"isValid":true}}}}}}}, "INPUT_7":{"status":{"pp":{"isAvailable":true,"plug":"1"}},"snapshot":{"pp":{"enable":true}}} }}}}), }); @@ -567,7 +607,7 @@ mod tests { identity: "Test".into(), screens: vec![], raw: serde_json::json!({"device":{"inputList":{"items":{ - "INPUT_3":{"status":{"pp":{"isAvailable":true,"plug":"1"}},"snapshot":{"pp":{"enable":true}}} + "INPUT_3":{"status":{"pp":{"isAvailable":true,"plug":"1"}},"snapshot":{"pp":{"enable":true}},"plugList":{"items":{"1":{"status":{"signal":{"pp":{"isValid":true}}}}}}} }}}}), }); app.layout.select(None); @@ -601,6 +641,72 @@ mod tests { assert_eq!(app.capture.layers.len(), 2); } #[test] + fn both_input_pickers_hide_empty_inputs_and_preserve_explicit_selection() { + let ctx = egui::Context::default(); + let mut app = Editor::default(); + app.device.snapshot = Some(midra_layout::device::Snapshot { + identity: "Test".into(), + screens: vec![], + raw: serde_json::json!({"device":{"inputList":{"items":{ + "INPUT_3":{"status":{"pp":{"isAvailable":true,"plug":"1"}},"snapshot":{"pp":{"enable":true}},"plugList":{"items":{"1":{"status":{"signal":{"pp":{"isValid":true}}}}}}}, + "INPUT_7":{"status":{"pp":{"isAvailable":true,"plug":"1"}},"snapshot":{"pp":{"enable":true}}} + }}}}), + }); + app.capture.host = app.device.host.clone(); + app.capture.last_request = Some(std::time::Instant::now()); + let i = app.layout.selected().unwrap(); + let id = app.layout.layer_info(i).id; + app.format_draft = Some(FormatDraft::new(&app.layout, i)); + app.property_tab = PropertyTab::Preview; + let contains = |output: &egui::FullOutput, label: &str| { + output + .shapes + .iter() + .any(|s| matches!(&s.shape, egui::Shape::Text(t) if t.galley.text() == label)) + }; + click_text(&mut app, &ctx, "Enable input preview"); + click_text(&mut app, &ctx, "Choose input…"); + let output = frame(&mut app, &ctx, vec![]); + assert!(contains(&output, "Input 3")); + assert!(!contains(&output, "Input 7 · No signal")); + click_text(&mut app, &ctx, "Show inputs without signal"); + assert!(app.capture.show_empty_inputs); + click_text(&mut app, &ctx, "Input 7 · No signal"); + assert_eq!(app.capture.layers[&id].input, 7); + assert!(contains( + &frame(&mut app, &ctx, vec![]), + "Input 7 · No signal" + )); + app.capture.show_empty_inputs = false; + frame(&mut app, &ctx, vec![]); + assert_eq!(app.capture.layers[&id].input, 7); // filtering never changes a target + app.format_draft = None; + app.open_snapshot_import(); + frame(&mut app, &ctx, vec![]); + assert_eq!(app.capture.input, 3); + click_text(&mut app, &ctx, "Input 3"); + assert!(!contains( + &frame(&mut app, &ctx, vec![]), + "Input 7 · No signal" + )); + click_text(&mut app, &ctx, "Show inputs without signal"); + click_text(&mut app, &ctx, "Input 7 · No signal"); + assert_eq!(app.capture.input, 7); + app.capture.show_empty_inputs = false; + frame(&mut app, &ctx, vec![]); + assert_eq!(app.capture.input, 7); + app.capture.input = 0; + app.device.snapshot.as_mut().unwrap().raw["device"]["inputList"]["items"]["INPUT_3"]["plugList"] + ["items"]["1"]["status"]["signal"]["pp"]["isValid"] = serde_json::json!(false); + frame(&mut app, &ctx, vec![]); + assert_eq!(app.capture.input, 0); // never silently select an empty input + click_text(&mut app, &ctx, "Choose input…"); + assert!(contains( + &frame(&mut app, &ctx, vec![]), + "No inputs with signal. Enable the toggle above to see empty inputs." + )); + } + #[test] fn capture_is_manual_throttled_and_only_adds_on_request() { let ctx = egui::Context::default(); let mut app = Editor::default(); @@ -608,7 +714,7 @@ mod tests { app.device.snapshot = Some(midra_layout::device::Snapshot { identity: "Test".into(), screens: vec![], - raw: serde_json::json!({"device":{"inputList":{"items":{"INPUT_3":{"status":{"pp":{"isAvailable":true,"plug":"1"}},"snapshot":{"pp":{"enable":true}}}}}}}), + raw: serde_json::json!({"device":{"inputList":{"items":{"INPUT_3":{"status":{"pp":{"isAvailable":true,"plug":"1"}},"snapshot":{"pp":{"enable":true}},"plugList":{"items":{"1":{"status":{"signal":{"pp":{"isValid":true}}}}}}}}}}}), }); app.capture.host = app.device.host.clone(); app.open_snapshot_import(); @@ -722,7 +828,7 @@ mod tests { identity: "Test".into(), screens: vec![], raw: serde_json::json!({"device":{"inputList":{"items":{ - "INPUT_3":{"status":{"pp":{"isAvailable":true,"plug":"1"}},"snapshot":{"pp":{"enable":true}}}, + "INPUT_3":{"status":{"pp":{"isAvailable":true,"plug":"1"}},"snapshot":{"pp":{"enable":true}},"plugList":{"items":{"1":{"status":{"signal":{"pp":{"isValid":true}}}}}}}, "INPUT_7":{"status":{"pp":{"isAvailable":true,"plug":"1"}},"snapshot":{"pp":{"enable":true}}} }}}}), }); diff --git a/docs/interfaces/midra-input-preview.md b/docs/interfaces/midra-input-preview.md index e1e596e..a643c22 100644 --- a/docs/interfaces/midra-input-preview.md +++ b/docs/interfaces/midra-input-preview.md @@ -37,6 +37,19 @@ blank 128 × 128 PNG. The device controls image freshness (Last-Modified) and resolution; GET fetches the latest available snapshot, not a guaranteed new full-resolution frame. Signal indicators may be stale until reconnect/refresh. +## Input picker filtering + +Both the per-layer Preview picker and Import input snapshot picker hide inputs +whose last-read active plug reports no valid signal. **Show inputs without +signal**, inside each dropdown, reveals those available hardware inputs with a +**No signal** label. The toggle is shared for the session and defaults off; it is +not persisted. Unavailable hardware inputs remain excluded. An explicitly chosen +input is retained and labelled if it loses signal or is hidden by this filter; +filtering does not change assignments, capture availability or refresh eligibility. +With no signal-bearing inputs, initial selection remains empty until the user +reveals and chooses one. Signal status comes from the connection snapshot and +updates when the connection is refreshed, not from PNG polling. + ## Editor and persistence **Import input snapshot…** displays the image and its actual pixel dimensions. diff --git a/docs/midra-layout/README.md b/docs/midra-layout/README.md index 2d27bfb..4ac116f 100644 --- a/docs/midra-layout/README.md +++ b/docs/midra-layout/README.md @@ -1006,7 +1006,10 @@ For a layer, open **Layer properties → Preview** (or right-click → **Input p & crop guides**): 1. Check **Enable input preview**. -2. Choose the physical input to preview. This only chooses an image source; it +2. Choose the physical input to preview. Inputs without signal are hidden by + default; **Show inputs without signal** inside the dropdown reveals them with + a **No signal** label. The same filter applies to the snapshot-import picker. + Signal indicators reflect the last connection refresh. This only chooses an image source; it does not change Midra input routing or the editor's source-format identity. 3. Click **Capture still**, directly below the input selector. The image loads straight into this layer. Click it again to replace the still. diff --git a/docs/midra-layout/changelog.md b/docs/midra-layout/changelog.md index 9c92329..33f56f9 100644 --- a/docs/midra-layout/changelog.md +++ b/docs/midra-layout/changelog.md @@ -4,6 +4,8 @@ ## Unreleased +- Hide no-signal inputs by default in both preview pickers; add a shared session-only Show inputs without signal toggle and explicit No signal labels. Preserve existing choices when filtering or signal loss occurs, and leave initial selection empty when no input has signal. UI tests cover both pickers and the empty state. + - Add Import input snapshot… with an explicit destination picker for any editor layer or a fixed reference image. Layer imports optionally keep refreshing; references never auto-refresh. Preserve selection/geometry and existing snapshot limits; regression tests cover both destinations without a selection. - Simplify layer previews to Enable → Input → Capture still → Auto-refresh. Capture directly replaces that layer's image; auto-refresh is per layer and can fetch the first image. Preserve serialized low-rate requests, bind manual results to their original target, and keep manual stills unchanged by other layers' refreshes. Regression tests cover control order, recapture, stale results and automatic first capture.