Separate advanced editor inputs from Midra layer mapping

This commit is contained in:
Dandaedre 2026-11-14 18:31:32 +01:00
parent c8b4201d2c
commit a1133cb8d2
7 changed files with 117 additions and 15 deletions

View File

@ -344,13 +344,6 @@ impl Editor {
ui.heading("Layer mapping");
self.layer_mapping_controls(ui, i);
ui.separator();
ui.horizontal(|ui| {
ui.label("Editor input");
egui::ComboBox::from_id_salt("source-id").selected_text(format!("Input {}",d.source_id+1)).show_ui(ui,|ui| {
for id in 0..self.layout.formats().sources.len() { if ui.selectable_value(&mut d.source_id,id,format!("Input {}",id+1)).changed() { d.source=self.layout.formats().sources[id];d.input_size=d.source.input().unwrap(); } }
});
});
ui.small("Editor input shares source format and input crop between editor layers; it is separate from the Midra link.");
}
if self.property_tab == PropertyTab::Source {
ui.heading("Advanced source / input settings");
@ -359,6 +352,21 @@ impl Editor {
ui.label("Editor source model (local geometry)");
ui.small("These dimensions describe the editor source, not a device timing command. Local input correction is currently folded into exported layer crop; use the device controls above for the actual shared Midra input settings.");
ui.add_enabled_ui(self.device.input_edits.enabled, |ui| {
ui.horizontal(|ui| {
ui.label("Editor input");
egui::ComboBox::from_id_salt("source-id").selected_text(format!("Input {}",d.source_id+1)).show_ui(ui,|ui| {
let count = self.layout.formats().sources.len().max(8).max(d.source_id + 1);
for id in 0..count { if ui.selectable_value(&mut d.source_id,id,format!("Input {}",id+1)).changed() { d.source=self.layout.formats().sources.get(id).copied().unwrap_or_default();d.input_size=d.source.input().unwrap(); } }
ui.separator();
if ui.add_enabled(count < 1024, egui::Button::new("New editor input")).clicked() {
d.source_id = count;
d.source = Default::default();
d.input_size = d.source.input().unwrap();
ui.close_menu();
}
});
});
ui.small("Editor inputs share source format and input crop between editor layers. Inputs 1–8 are offered initially; add more as needed. This local identity does not select a physical Midra input or change routing.");
let affected:Vec<_>=(0..self.layout.layers().len()).filter(|j| *j==i || self.layout.formats().source_for[*j]==d.source_id).map(|j|self.layout.layer_label(j)).collect();
ui.label(format!("Input edits affect: {}",affected.join(", ")));
@ -426,7 +434,7 @@ impl Editor {
ui.small("Layer size changes apply as you edit. Undo restores earlier values.");
}
if !ui.input(|input| input.pointer.primary_down()) { d.layer_before = None; }
if matches!(self.property_tab, PropertyTab::Source | PropertyTab::Mapping) {
if self.property_tab == PropertyTab::Source {
let g=self.layout.layers()[i];
let [x,y]=self.position_reference().offsets_on(g,self.layout.formats().output);
let geometry=self.position_reference().geometry_on(x,y,d.size[0],d.size[1],self.layout.formats().output);
@ -439,7 +447,7 @@ impl Editor {
_=>{}
}
let pending = d.pending(&self.layout);
if apply_button(ui,"Apply source changes", pending && (self.device.input_edits.enabled || self.property_tab == PropertyTab::Mapping)).clicked() {
if apply_button(ui,"Apply source changes", pending && self.device.input_edits.enabled).clicked() {
match d.apply(&mut self.layout, position_reference, self.keep_aspect_ratio) { Ok(())=>{self.sync();d=FormatDraft::new(&self.layout,i);},Err(e)=>d.error=e }
}
ui.small("Source changes require Apply. Switching tabs keeps pending source edits.");

View File

@ -6451,6 +6451,27 @@ mod tests {
}
}
#[test]
fn advanced_source_offers_eight_editor_inputs_without_extra_layers() {
let ctx = egui::Context::default();
let mut app = Editor::default();
app.layout.select(Some(0));
app.format_draft = Some(FormatDraft::new(&app.layout, 0));
app.property_tab = PropertyTab::Source;
app.device.input_edits.enabled = true;
frame(&mut app, &ctx, vec![]);
click_text(&mut app, &ctx, "Input 1");
click_text(&mut app, &ctx, "Input 8");
assert_eq!(app.layout.formats().sources.len(), 2);
click_text(&mut app, &ctx, "Apply source changes");
assert_eq!(app.layout.formats().source_for[0], 7);
assert_eq!(app.layout.layers().len(), 2);
click_text(&mut app, &ctx, "Input 8");
click_text(&mut app, &ctx, "New editor input");
click_text(&mut app, &ctx, "Apply source changes");
assert_eq!(app.layout.formats().source_for[0], 8);
assert_eq!(app.layout.formats().sources.len(), 9);
}
#[test]
fn snapped_move_and_resize_stay_snapped_on_release_and_undo_as_one_edit() {
for resize in [false, true] {
for zoom in [0.75, 1.0] {

View File

@ -863,14 +863,19 @@ impl Layout {
geometry: Geometry,
allow_adjustment: bool,
) -> Result<String, String> {
if !self.selectable(i) || source_id >= self.formats.sources.len() {
return Err("Select an editable layer and existing source.".into());
if !self.selectable(i) || source_id >= 1024 {
return Err("Select an editable layer and an input between 1 and 1024.".into());
}
source.input()?;
geometry.validate()?;
self.finish_drag();
let before = self.snapshot();
let mut next = before.clone();
// Input identities are independent of layers and created atomically on Apply.
next.formats.sources.resize(
next.formats.sources.len().max(source_id + 1),
Source::default(),
);
next.formats.source_for[i] = source_id;
next.formats.sources[source_id] = source;
next.layers[i] = geometry;
@ -878,7 +883,7 @@ impl Layout {
for j in 0..self.layers.len() {
let affected = j == i
|| (next.formats.source_for[j] == source_id
&& source != before.formats.sources[source_id]);
&& before.formats.sources.get(source_id) != Some(&source));
if !affected {
continue;
}

View File

@ -482,3 +482,48 @@ fn reference_collection_migrates_single_images_and_rejects_mislabeled_or_oversiz
let example = include_str!("../../../docs/interfaces/midra-layout-v10.example.json");
assert_eq!(Project::from_json(example).unwrap().version, 10);
}
#[test]
fn editor_inputs_grow_independently_and_roundtrip_with_undo() {
let mut layout = Layout::default();
let before = layout.formats().clone();
let geometry = layout.layers()[0];
layout
.configure(0, 7, Source::default(), geometry, true)
.unwrap();
assert_eq!(layout.layers().len(), 2);
assert_eq!(layout.formats().sources.len(), 8);
assert_eq!(layout.formats().source_for, [7, 1]);
layout.undo();
assert_eq!(layout.formats(), &before);
layout.redo();
layout
.configure(1, 7, Source::default(), layout.layers()[1], true)
.unwrap();
let project = Project::from_layout(&layout);
let restored = Project::from_json(&project.to_json().unwrap())
.unwrap()
.layout()
.unwrap();
assert_eq!(restored.formats(), layout.formats());
assert_eq!(project.inputs.len(), 8);
assert_eq!(project.layers[0].source_id, 8);
layout
.configure(0, 8, Source::default(), geometry, true)
.unwrap();
assert_eq!(layout.formats().sources.len(), 9);
let before = layout.formats().clone();
assert!(
layout
.configure(0, 1024, Source::default(), geometry, true)
.is_err()
);
assert_eq!(layout.formats(), &before);
layout.set_locked(0, true);
assert!(
layout
.configure(0, 9, Source::default(), geometry, true)
.is_err()
);
assert_eq!(layout.formats(), &before);
}

View File

@ -252,3 +252,17 @@ Manual device import now saves the reviewed `midra_link` with imported geometry/
in one Undo step. New layers inherit the chosen folder; existing folder names remain.
All these values use the existing layer fields (unchanged in version 10). See
[device transfer scopes](midra-device-send.md#shared-transfer-scopes-and-folder-layouts).
### Editor input creation
The opt-in Advanced Source section offers Inputs 1–8 independently of editor/device
layer counts. Mapping only edits Midra screen/layer links, not input identities.
**New editor input** extends this local list up to the existing 1024-slot limit.
Selecting an unused identity is staged; **Apply source changes** creates any
missing consecutive slots with the default 1920 × 1080, 16:9 source and zero input
crop, then assigns the selected layer. Creation and assignment form one undoable
edit. Multiple layers may share the new identity. Existing smaller projects remain
unchanged until Apply; saving writes the materialized slots in `inputs` and the
one-based assignment in `layers[].source_id`. Version 10 and older-version
migration rules are unchanged. These IDs do not select or route physical inputs.

View File

@ -497,8 +497,8 @@ The same window offers numeric camera zoom relative to fit-to-screen and a
Select one layer and click its **Layer resolution** card to open **Layer properties**:
1. Choose a local **Editor input** in **Mapping**, then its original **Source format** in **Source** and native
dimensions. Input 1/2 are planning identities, not device routing commands.
1. Enable advanced editing in **Source**, choose a local **Editor input**, then its original **Source format** and native
dimensions. Editor inputs are planning identities, not device routing commands.
2. Set **Input resolution** to the usable size. Typing a custom size centers the
input crop; edit L/R/T/B for asymmetric placement. Crop edges stop at zero
when dragging; negative or non-finite typed/pasted values are not accepted. Native-size changes reset
@ -598,7 +598,7 @@ the device controls above wait for Send.
Layer properties has four tabs: **Source** for native/input resolution and input
crop, **Layer** for the final visible box, **Crop** for content zoom and offset,
and **Mapping** for editor input identity and the saved Midra screen/layer link.
and **Mapping** for the saved Midra screen/layer link. Editor input identity belongs to the opt-in **Source** tab.
The right-click properties entries open their matching tab directly.
Mapping offers device screen/layer selectors when connected, or numeric IDs offline.
Link edits apply locally immediately and support Undo. **Unmap** removes the link,
@ -1035,3 +1035,10 @@ Opening a project or restoring recovery now reads, validates and decodes embedde
references in a worker. The current editor stays intact until the whole project
is ready. Manual loading has a Cancel button; errors keep the old project.
Recovery autosave pauses while loading, including on exit.
In the opt-in **Layer properties → Source** section, **Editor input** offers Inputs 1–8 separately
from Midra screen/layer destinations. Use **New editor input** for additional
local identities, then **Apply source changes**. Layers sharing an editor input
share its source format and input crop. Assignments are saved in projects and
undoable; they do not change physical input routing.

View File

@ -4,6 +4,8 @@
## Unreleased
- Keep Mapping limited to Midra screen/layer links; move editor input identity into the opt-in Advanced Source section. Offer editor Inputs 1–8 independently of layer count, with New editor input for additional local identities. Apply creates missing slots and assigns the source atomically with Undo; project round-trip tests cover shared Input 8, expansion and limits. Midra layer links and physical routing remain separate.
- Filter Midra destinations by each screen's CURRENT allocated layer count, not the eight firmware storage slots or physical inputs. Keep allocated layers available without assigned sources; exclude unallocated slots from import, mapping and sends, including saved links. Regression checks cover active versus staged allocation and Preview/Program sends.
- Keep existing Midra layers available for mapping, import and send regardless of input assignment or OFF state. Uncropped layers without content dimensions import their container; sends use editor dimensions when hardware content dimensions are unavailable, preserving routing. Regression tests cover unassigned layers and both send strategies/targets.