From fa093538a10aba1374e0ec18094c521a69f88afa Mon Sep 17 00:00:00 2001 From: Dandaedre Date: Fri, 13 Nov 2026 18:35:53 +0100 Subject: [PATCH] Hide empty Midra slots and make Program export opt-in --- crates/midra-layout/src/device.rs | 6 +- crates/midra-layout/src/device_ui.rs | 69 +++++++++++++++++-- crates/midra-layout/src/gui.rs | 6 +- crates/midra-layout/src/preferences_ui.rs | 2 + crates/midra-layout/src/settings.rs | 32 ++++++++- crates/midra-layout/tests/device.rs | 14 ++++ docs/interfaces/midra-device-send.md | 4 +- .../midra-layout-settings-v5.example.json | 18 +++++ docs/interfaces/midra-layout-settings.md | 11 +-- docs/midra-layout.md | 2 + 10 files changed, 150 insertions(+), 14 deletions(-) create mode 100644 docs/interfaces/midra-layout-settings-v5.example.json diff --git a/crates/midra-layout/src/device.rs b/crates/midra-layout/src/device.rs index 63744c7..953517e 100644 --- a/crates/midra-layout/src/device.rs +++ b/crates/midra-layout/src/device.rs @@ -93,6 +93,10 @@ impl Snapshot { .ok_or("Invalid layer list")?; let mut layers = Vec::new(); for (id, layer) in entries { + let source = text(layer, "/source/pp/input")?; + if source == "NONE" || source.is_empty() { + continue; + } let width = number(layer, "/size/pp/sizeH")?; let height = number(layer, "/size/pp/sizeV")?; let geometry = Geometry { @@ -137,7 +141,7 @@ impl Snapshot { } layers.push(Layer { id: id.clone(), - source: text(layer, "/source/pp/input")?, + source, geometry, container, framing, diff --git a/crates/midra-layout/src/device_ui.rs b/crates/midra-layout/src/device_ui.rs index c0c2ed1..fa5de01 100644 --- a/crates/midra-layout/src/device_ui.rs +++ b/crates/midra-layout/src/device_ui.rs @@ -19,6 +19,7 @@ pub(super) struct DeviceUi { pub(super) connection_open: bool, pub(super) prepare_send: bool, target: Target, + pub(super) allow_program: bool, sizing: Sizing, pub(super) sending: bool, message: String, @@ -35,9 +36,10 @@ impl DeviceUi { self.send_targets.clear(); self.destinations.fill(Destination::Skip); } - pub(super) fn with_host(host: String) -> Self { + pub(super) fn with_connection_preferences(host: String, allow_program: bool) -> Self { Self { host, + allow_program, ..Self::default() } } @@ -56,7 +58,11 @@ impl DeviceUi { layout, self.screen, &mappings, - self.target, + if self.allow_program { + self.target + } else { + Target::Preview + }, self.sizing, ) } @@ -206,6 +212,9 @@ impl Editor { } } pub(super) fn device_window(&mut self, ctx: &egui::Context) { + if !self.device.allow_program { + self.device.target = Target::Preview; + } self.device.poll(); self.connection_window(ctx); if !self.device.open { @@ -248,7 +257,7 @@ impl Editor { if !matches { ui.colored_label(ui.visuals().warn_fg_color, format!("Device canvas {} × {}; editor {} × {}. Match output resolution before importing.", screen.resolution[0], screen.resolution[1], self.layout.formats().output[0], self.layout.formats().output[1])); } if self.device.prepare_send { send_plan = send_review(ui, &self.layout, snapshot, self.device.screen, &mut self.device.send_targets, - &mut self.device.target, &mut self.device.sizing, self.device.pending.is_some()); + &mut self.device.target, &mut self.device.sizing, self.device.pending.is_some(), self.device.allow_program); return; } egui::ScrollArea::vertical().max_height(300.0).show(ui, |ui| { @@ -322,12 +331,18 @@ fn send_review( target_mode: &mut Target, sizing: &mut Sizing, busy: bool, + allow_program: bool, ) -> Option { let screen = &snapshot.screens[screen_index]; + if !allow_program { + *target_mode = Target::Preview; + } ui.horizontal(|ui| { ui.label("Target"); ui.selectable_value(target_mode, Target::Preview, "Preview"); - ui.selectable_value(target_mode, Target::Program, "Program"); + if allow_program { + ui.selectable_value(target_mode, Target::Program, "Program"); + } }); ui.horizontal(|ui| { ui.label("Device container"); @@ -453,6 +468,50 @@ fn container_label(geometry: midra_layout::Geometry) -> String { mod tests { use super::*; #[test] + fn program_destination_is_hidden_and_reset_until_enabled() { + for allow in [false, true] { + let ctx = egui::Context::default(); + let layout = midra_layout::Layout::default(); + let snapshot = device::Snapshot { + identity: "Test".into(), + raw: serde_json::Value::Null, + screens: vec![device::Screen { + id: "1".into(), + resolution: [1920, 1080], + preview_bank: "UP".into(), + layers: vec![], + }], + }; + let mut target = Target::Program; + let mut targets = Default::default(); + let output = ctx.run(egui::RawInput::default(), |ctx| { + egui::CentralPanel::default().show(ctx, |ui| { + send_review( + ui, + &layout, + &snapshot, + 0, + &mut targets, + &mut target, + &mut Sizing::OutputBox, + false, + allow, + ); + }); + }); + assert_eq!( + target, + if allow { + Target::Program + } else { + Target::Preview + } + ); + let program_visible = output.shapes.iter().any(|s| matches!(&s.shape, egui::epaint::Shape::Text(t) if t.galley.job.text == "Program")); + assert_eq!(program_visible, allow); + } + } + #[test] fn status_apply_opens_mapping_without_writing_when_unconfigured() { let ctx = egui::Context::default(); let mut app = Editor::default(); @@ -526,6 +585,7 @@ mod tests { &mut Target::Preview, &mut Sizing::OutputBox, false, + false, ) }); }); @@ -546,6 +606,7 @@ mod tests { &mut Target::Preview, &mut Sizing::OutputBox, false, + false, ) }); }); diff --git a/crates/midra-layout/src/gui.rs b/crates/midra-layout/src/gui.rs index 118b281..0932806 100644 --- a/crates/midra-layout/src/gui.rs +++ b/crates/midra-layout/src/gui.rs @@ -276,7 +276,10 @@ impl Editor { theme::Theme::restore_recent(ctx, saved.recent_themes.clone()); saved.theme.apply(ctx); Self { - device: device_ui::DeviceUi::with_host(saved.midra_host), + device: device_ui::DeviceUi::with_connection_preferences( + saved.midra_host, + saved.allow_sending_to_program, + ), settings: store, snapping: saved.snapping, keep_aspect_ratio: saved.keep_aspect_ratio, @@ -288,6 +291,7 @@ impl Editor { fn application_settings(&self, ctx: &egui::Context) -> settings::Settings { settings::Settings { midra_host: self.device.host.clone(), + allow_sending_to_program: self.device.allow_program, theme: theme::Theme::current(ctx), recent_themes: theme::Theme::recent(ctx), snapping: self.snapping, diff --git a/crates/midra-layout/src/preferences_ui.rs b/crates/midra-layout/src/preferences_ui.rs index 647d9c4..bbae210 100644 --- a/crates/midra-layout/src/preferences_ui.rs +++ b/crates/midra-layout/src/preferences_ui.rs @@ -96,6 +96,7 @@ impl Editor { let defaults = settings::Settings::default(); theme::Theme::restore_recent(ctx, defaults.recent_themes); defaults.theme.apply(ctx); + self.device.allow_program = false; self.snapping = defaults.snapping; self.keep_aspect_ratio = defaults.keep_aspect_ratio; self.show_pattern = defaults.show_source_pattern; @@ -104,6 +105,7 @@ impl Editor { } Section::Device => { ui.heading("Midra integration"); + ui.checkbox(&mut self.device.allow_program, "Allow sending to Program"); ui.label("Read Preview layer containers from an Eikos 4K and review their mapping before import."); if ui.button("Open Midra connection…").clicked() { self.device.connection_open = true; } ui.weak("Read snapshots and explicitly send reviewed size, position and crop changes."); diff --git a/crates/midra-layout/src/settings.rs b/crates/midra-layout/src/settings.rs index 32148ea..9777125 100644 --- a/crates/midra-layout/src/settings.rs +++ b/crates/midra-layout/src/settings.rs @@ -8,6 +8,7 @@ use std::{io::Read, path::PathBuf}; pub struct Settings { pub version: u32, pub midra_host: String, + pub allow_sending_to_program: bool, pub theme: Theme, pub recent_themes: Vec, pub snapping: midra_layout::snapping::Snapping, @@ -18,7 +19,8 @@ pub struct Settings { impl Default for Settings { fn default() -> Self { Self { - version: 4, + version: 5, + allow_sending_to_program: false, midra_host: String::new(), theme: Theme::Midra, recent_themes: vec![Theme::Midra], @@ -63,12 +65,19 @@ impl Settings { value["midra_host"] = "".into(); value["version"] = 4.into(); } + if value["version"] == 4 { + if value.get("allow_sending_to_program").is_some() { + return Err("Unexpected allow_sending_to_program in version 4 settings".into()); + } + value["allow_sending_to_program"] = false.into(); + value["version"] = 5.into(); + } let settings: Self = serde_json::from_value(value).map_err(|e| e.to_string())?; settings.validate()?; Ok(settings) } fn validate(&self) -> Result<(), String> { - if self.version != 4 { + if self.version != 5 { return Err(format!("unsupported settings version {}", self.version)); } if self.recent_themes.is_empty() @@ -187,6 +196,7 @@ mod tests { settings.keep_aspect_ratio = false; settings.show_source_pattern = true; settings.midra_host = "192.168.10.143".into(); + settings.allow_sending_to_program = true; store.save(&settings); assert!(store.error.is_none()); assert_eq!(Store::at(path.clone()).1, settings); @@ -206,7 +216,7 @@ mod tests { for text in [ "broken".to_string(), serde_json::to_string(&Settings { - version: 5, + version: 6, ..Default::default() }) .unwrap(), @@ -231,6 +241,22 @@ mod tests { assert_eq!(Store::at(blocker.join("settings.json")).1, settings); } #[test] + fn version_five_disables_program_for_legacy_settings() { + let example = + include_str!("../../../docs/interfaces/midra-layout-settings-v5.example.json"); + assert_eq!(Settings::parse(example).unwrap(), Settings::default()); + let mut legacy: serde_json::Value = serde_json::from_str(include_str!( + "../../../docs/interfaces/midra-layout-settings-v4.example.json" + )) + .unwrap(); + legacy["midra_host"] = "192.168.10.143".into(); + let migrated = Settings::parse(&legacy.to_string()).unwrap(); + assert!(!migrated.allow_sending_to_program); + assert_eq!(migrated.midra_host, "192.168.10.143"); + legacy["allow_sending_to_program"] = true.into(); + assert!(Settings::parse(&legacy.to_string()).is_err()); + } + #[test] fn version_four_remembers_address_and_migrates_legacy_without_it() { let example = include_str!("../../../docs/interfaces/midra-layout-settings-v4.example.json"); diff --git a/crates/midra-layout/tests/device.rs b/crates/midra-layout/tests/device.rs index 020428f..f19d762 100644 --- a/crates/midra-layout/tests/device.rs +++ b/crates/midra-layout/tests/device.rs @@ -139,3 +139,17 @@ fn invalid_mapping_never_partially_imports() { .is_err() ); } + +#[test] +fn empty_source_slots_are_omitted_but_assigned_off_layers_remain() { + let (identity, mut raw) = fixture(); + let entries = raw + .pointer_mut("/device/screenList/items/2/presetList/items/UP/liveLayerList/items") + .unwrap(); + entries["1"]["status"] = json!({"pp": {"state": "OFF"}}); + entries["2"] = json!({"source": {"pp": {"input": "NONE"}}}); + entries["3"] = json!({"source": {"pp": {"input": ""}}}); + let snapshot = Snapshot::parse(&identity, &raw).unwrap(); + assert_eq!(snapshot.screens[0].layers.len(), 1); + assert_eq!(snapshot.screens[0].layers[0].id, "1"); +} diff --git a/docs/interfaces/midra-device-send.md b/docs/interfaces/midra-device-send.md index e32d1e0..69e573f 100644 --- a/docs/interfaces/midra-device-send.md +++ b/docs/interfaces/midra-device-send.md @@ -70,8 +70,10 @@ to avoid temporarily exhausting the retained area while moving a crop. Readback checks every changed field. No-op plans are disabled. Failure reports partial/uncertain outcomes without blind retries or automatic rollback. -Program selection is explicit. The application defaults to Preview. Mappings, +Program selection is explicit. The application defaults to Preview and hides Program unless the persisted `allow_sending_to_program` preference is enabled. Turning it off resets the exporter to Preview, including quick Apply. Mappings, plans and raw snapshots are not saved in projects or preferences. The device address is saved in [application settings](midra-layout-settings.md), never in projects. Refresh and screen changes reset destination review. Physical display validation remains separate from the successful device-field and import round trips. The status-bar and Export-menu **Apply to Midra** actions prepare a fresh plan for the current editor selection using the session mappings, target and sizing mode. Valid changed plans send immediately with readback verification, without a preflight refusal. Missing or invalid mappings open the configuration window without writing; no-op plans and busy/offline actions are disabled. No persistent schema changes are involved. + +Snapshot layer lists omit unassigned source slots (`NONE` or empty), before geometry validation. Assigned layers remain available even when OFF. diff --git a/docs/interfaces/midra-layout-settings-v5.example.json b/docs/interfaces/midra-layout-settings-v5.example.json new file mode 100644 index 0000000..40ebf76 --- /dev/null +++ b/docs/interfaces/midra-layout-settings-v5.example.json @@ -0,0 +1,18 @@ +{ + "version": 5, + "theme": "midra", + "recent_themes": [ + "midra" + ], + "show_toolbar_icon_names": false, + "keep_aspect_ratio": true, + "show_source_pattern": false, + "snapping": { + "enabled": false, + "pixels": true, + "screen_edges": true, + "layer_edges": true + }, + "midra_host": "", + "allow_sending_to_program": false +} diff --git a/docs/interfaces/midra-layout-settings.md b/docs/interfaces/midra-layout-settings.md index 5e3dbdc..b230978 100644 --- a/docs/interfaces/midra-layout-settings.md +++ b/docs/interfaces/midra-layout-settings.md @@ -1,13 +1,13 @@ -# Midra Layout application settings, version 4 +# Midra Layout application settings, version 5 Implementation: `crates/midra-layout/src/settings.rs`. This per-user JSON file is independent of the [project JSON and SVG contracts](midra-layout.md). -[Complete default example](midra-layout-settings-v4.example.json). +[Complete default example](midra-layout-settings-v5.example.json). Version 1 files migrate automatically: the saved theme becomes the only entry in `recent_themes`, with all other preferences preserved. The [version 1 example](midra-layout-settings-v1.example.json) remains a migration fixture. Version 2 files then migrate by adding disabled snapping with all target types enabled. The [version 2 example](midra-layout-settings-v2.example.json) -remains a migration fixture too. Version 3 files migrate by adding an empty `midra_host`; the [version 3 example](midra-layout-settings-v3.example.json) remains a migration fixture. Saving writes version 4; old applications reject it. +remains a migration fixture too. Version 3 files migrate by adding an empty `midra_host`; the [version 3 example](midra-layout-settings-v3.example.json) remains a migration fixture. Version 4 files migrate by adding `allow_sending_to_program: false`; the [version 4 example](midra-layout-settings-v4.example.json) remains a migration fixture. Saving writes version 5; old applications reject it. The `directories` 6 crate resolves `ProjectDirs::from("org", "beffroi", "midra-layout")`. The filename is `settings.json` beneath `config_dir()`: @@ -24,7 +24,8 @@ unknown theme names are rejected. There are no numeric coordinates or units. | Field | Values / default | | --- | --- | -| `version` | Integer `4` | +| `version` | Integer `5` | +| `allow_sending_to_program` | Boolean; default false. Enables the Program destination in the exporter. Turning it off restores Preview; applies to quick Apply too. | | `midra_host` | Device IP address text; default `""`. Saved as typed, including incomplete drafts; validated when connecting. | | `theme` | Theme ID from the catalog below; default `"midra"` | | `recent_themes` | 1–3 unique theme IDs, newest first; first must equal `theme`; default `["midra"]` | @@ -104,3 +105,5 @@ layer movement and resize handles; numeric entry, nudges and crop-content gestur bypass it. Resize snapping preserves anchors and proportions and shows guides only when the resulting edge actually reaches its target. Shift temporarily inverts snapping during layer resizing, including release, without changing the saved option. Alt temporarily disables it and takes precedence over Shift. + +**Preferences → Midra integration → Allow sending to Program** saves immediately. Restore default preferences disables it. Projects do not override this application preference; the Preview/Program destination itself remains session-only. diff --git a/docs/midra-layout.md b/docs/midra-layout.md index a731935..ff11383 100644 --- a/docs/midra-layout.md +++ b/docs/midra-layout.md @@ -623,3 +623,5 @@ no layer mapping. Layer rows use padlock and eye icon buttons for locking and visibility, with tooltips and highlighted locked/hidden states. Double-click a layer name in the right-hand list to rename it. Enter saves, Escape or Cancel discards the edit; names must contain 1–128 characters. Renaming preserves the layer ID and folder and supports Undo. Snapping also applies to side and corner resizing, including with aspect ratio locked. Hold **Shift** during a resize to temporarily invert snapping (on when disabled, off when enabled); release uses the current modifier state. **Alt** still disables snapping. Shift-drag on a resize handle resizes; Shift-click and Shift-drag elsewhere retain selection behavior. + +Midra layer lists omit unassigned source slots (`NONE` or empty). Assigned inputs remain listed even if the layer is off. The exporter defaults to Preview and hides Program until **Preferences → Midra integration → Allow sending to Program** is checked. This preference is saved automatically; turning it off returns the exporter and quick Apply action to Preview.