Add layer mapping properties with screen selection and unmap
Beffroi/beffroi-tools/pipeline/head This commit looks good Details

This commit is contained in:
Dandaedre 2026-11-14 16:03:26 +01:00
parent f63d4f31a8
commit d92c4f5c9f
6 changed files with 168 additions and 8 deletions

View File

@ -266,6 +266,102 @@ impl DeviceUi {
}
}
impl Editor {
pub(super) fn layer_mapping_controls(&mut self, ui: &mut egui::Ui, i: usize) {
let original = self.layout.layer_info(i).midra_link.clone();
let mut link = original.clone();
ui.label("Midra screen / layer");
ui.small("Saved with this layer. Linked sends and loads use this screen and layer. Editing the link does not contact the device.");
if let Some(mapped) = &mut link {
if let Some(snapshot) = &self.device.snapshot {
egui::ComboBox::from_id_salt("property-midra-screen")
.selected_text(format!("Screen {}", mapped.screen))
.show_ui(ui, |ui| {
for screen in &snapshot.screens {
if ui
.selectable_value(
&mut mapped.screen,
screen.id.clone(),
format!("Screen {}", screen.id),
)
.changed()
&& !screen.layers.iter().any(|layer| layer.id == mapped.layer)
&& let Some(layer) = screen.layers.first()
{
mapped.layer = layer.id.clone();
}
}
});
egui::ComboBox::from_id_salt("property-midra-layer")
.selected_text(format!("Layer {}", mapped.layer))
.show_ui(ui, |ui| {
if let Some(screen) = snapshot
.screens
.iter()
.find(|screen| screen.id == mapped.screen)
{
for layer in &screen.layers {
ui.selectable_value(
&mut mapped.layer,
layer.id.clone(),
format!("Layer {}", layer.id),
);
}
}
});
} else {
ui.small("Offline: enter the screen and layer numbers, or connect to choose from the device.");
for (label, value) in [
("Screen ", &mut mapped.screen),
("Layer ", &mut mapped.layer),
] {
let mut number = value.parse::<u64>().unwrap_or(1);
if ui
.add(
egui::DragValue::new(&mut number)
.range(1..=9_999_999_999_999_999_u64)
.prefix(label),
)
.changed()
{
*value = number.to_string();
}
}
}
if ui.button("Unmap").clicked() {
link = None;
}
} else {
ui.label("Unmapped — excluded from linked sends and loads.");
if ui.button("Link to Midra layer").clicked() {
link = self.device.snapshot.as_ref().and_then(|snapshot| {
snapshot.screens.iter().find_map(|screen| {
screen.layers.first().map(|layer| midra_layout::MidraLink {
screen: screen.id.clone(),
layer: layer.id.clone(),
})
})
});
if self.device.snapshot.is_none() {
link = Some(midra_layout::MidraLink {
screen: "1".into(),
layer: "1".into(),
});
}
}
}
if link != original {
match self.layout.set_midra_link(i, link) {
Ok(()) => {
self.device.mapping_scope = None;
self.sync();
}
Err(error) => {
ui.colored_label(ui.visuals().error_fg_color, error);
}
}
}
}
pub(super) fn midra_load_button(&mut self, ui: &mut egui::Ui) {
let enabled = self.device.online() && self.device.pending.is_none();
let tooltip = if self.device.message.is_empty() {
@ -895,6 +991,46 @@ mod tests {
)
.unwrap()
}
#[test]
fn property_mapping_selects_screen_and_unmaps_without_device_writes() {
use super::super::tests::click_text;
let ctx = egui::Context::default();
let mut app = Editor::default();
let i = app.layout.selected().unwrap();
let before = app.layout.layers().clone();
let mut snapshot = linked_test_snapshot();
let mut second = snapshot.screens[0].clone();
second.id = "2".into();
snapshot.screens.push(second);
app.device.snapshot = Some(snapshot);
app.property_tab = PropertyTab::Mapping;
app.format_draft = Some(FormatDraft::new(&app.layout, i));
click_text(&mut app, &ctx, "Link to Midra layer");
assert_eq!(
app.layout.layer_info(i).midra_link.as_ref().unwrap().screen,
"1"
);
click_text(&mut app, &ctx, "Screen 1");
click_text(&mut app, &ctx, "Screen 2");
assert_eq!(
app.layout.layer_info(i).midra_link.as_ref().unwrap().screen,
"2"
);
assert_eq!(app.device.scoped_links(&app.layout).len(), 1);
let project = midra_layout::project::Project::from_layout(&app.layout);
click_text(&mut app, &ctx, "Unmap");
assert!(app.layout.layer_info(i).midra_link.is_none());
assert!(app.device.scoped_links(&app.layout).is_empty());
assert_eq!(*app.layout.layers(), before);
assert!(!app.device.sending);
assert!(app.device.pending.is_none());
app.layout.undo();
assert_eq!(
midra_layout::project::Project::from_layout(&app.layout),
project
);
}
#[test]
fn closing_import_review_applies_locally_and_never_starts_a_send() {
let ctx = egui::Context::default();

View File

@ -4,6 +4,7 @@ use midra_layout::formats::{Aspect, Crop, Framing, Source};
#[derive(Clone, Copy, Debug, Default, PartialEq)]
pub(super) enum PropertyTab {
Source,
Mapping,
#[default]
Layer,
Crop,
@ -336,16 +337,23 @@ impl Editor {
ui.selectable_value(&mut self.property_tab,PropertyTab::Source,"Source");
ui.selectable_value(&mut self.property_tab,PropertyTab::Layer,"Layer");
ui.selectable_value(&mut self.property_tab,PropertyTab::Crop,"Crop");
ui.selectable_value(&mut self.property_tab,PropertyTab::Mapping,"Mapping");
});
ui.separator();
if self.property_tab == PropertyTab::Source {
ui.heading("Source / input resolution");
if self.property_tab == PropertyTab::Mapping {
ui.heading("Layer mapping");
self.layer_mapping_controls(ui, i);
ui.separator();
ui.horizontal(|ui| {
ui.label("Source identity");
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("Source / input resolution");
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(", ")));
let old_native=d.source.native;
@ -411,7 +419,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 self.property_tab == PropertyTab::Source {
if matches!(self.property_tab, PropertyTab::Source | PropertyTab::Mapping) {
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);
@ -1055,6 +1063,7 @@ mod tests {
app.format_draft = Some(d);
for (title, tab, heading) in [
("Source", PropertyTab::Source, "Source / input resolution"),
("Mapping", PropertyTab::Mapping, "Layer mapping"),
("Crop", PropertyTab::Crop, "Layer crop / zoom & position"),
(
"Layer",
@ -1073,6 +1082,7 @@ mod tests {
egui::Shape::Text(t)
if [
"Source / input resolution",
"Layer mapping",
"Layer crop / zoom & position",
"Layer resolution / final visible box",
]

View File

@ -1654,6 +1654,7 @@ impl Editor {
("Source properties…", PropertyTab::Source),
("Layer properties…", PropertyTab::Layer),
("Crop properties…", PropertyTab::Crop),
("Mapping properties…", PropertyTab::Mapping),
] {
if ui.button(title).clicked() {
if self.format_draft.as_ref().is_none_or(|d| !d.is_for(i)) {

View File

@ -142,3 +142,9 @@ inherit the scope's folder (root in All). A successful manual import saves revie
source/crop data and new-layer membership in one undoable transaction. Invalid mapping,
link or geometry rejects the entire transaction. This uses existing project-v9 fields;
there is no schema/version change. Source routing and device memories are not imported.
Layer properties → **Mapping** edits the existing per-layer `midra_link.screen`
and `midra_link.layer` fields locally. **Unmap** saves `midra_link: null`, so
linked sends and loads skip the layer. These edits are undoable and never issue
device commands. Connected selectors use discovered screens/layers; offline
editing accepts positive numeric IDs. Project schema and version are unchanged.

View File

@ -483,7 +483,7 @@ 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 **Source identity** and its original **Source format** and native
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.
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
@ -558,9 +558,14 @@ Pending changes make Apply solid purple. This applies to position/size, output
resolution drafts, source/input formats, names/folders, and mapped imports. Each
section tracks its own values; reverting an edit clears its pending state.
Layer properties has three tabs: **Source** for native/input resolution and input
crop, **Layer** for the final visible box, and **Crop** for content zoom and offset.
The three right-click properties entries open their matching tab directly.
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.
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,
excluding the layer from linked sends and loads; it does not change the device.
Editor input identity remains a separate source setting requiring Apply.
Switching tabs retains pending Source edits, which require Apply. Layer size and
Crop changes apply immediately; each continuous drag is one Undo step.

View File

@ -4,6 +4,8 @@
## Unreleased
- Add a Mapping properties tab and right-click entry with selectable Midra screen/layer links and Unmap. Unmapped layers are excluded from linked sends/loads; link edits are local, saved with projects and undoable. Move the separate editor input identity selector into Mapping.
- Draw the snapping dropdown chevron and layer order arrows as vector icons, avoiding missing font glyphs while preserving tooltips, disabled states and button accessibility.
- Default Midra transfers to All layers with a shared All/Selected/Folder selector. Folder mode follows clicked folders for quick alternate-layout sends/loads; links remain editable and out-of-scope links are preserved. Import suggests saved links and saves remapped/new-layer links and folder membership atomically with geometry. Tests cover scope isolation, reused destinations, in-flight reads and Undo; no hardware writes were needed.