Split layer properties into Source Layer and Crop tabs
Beffroi/beffroi-tools/pipeline/head This commit looks good Details

This commit is contained in:
Dandaedre 2026-11-13 14:44:41 +01:00
parent d0195893a8
commit 35ceab2846
3 changed files with 108 additions and 16 deletions

View File

@ -1,6 +1,14 @@
use super::*;
use midra_layout::formats::{Aspect, Crop, Framing, Source};
#[derive(Clone, Copy, Debug, Default, PartialEq)]
pub(super) enum PropertyTab {
Source,
#[default]
Layer,
Crop,
}
pub(super) struct FormatDraft {
layer: usize,
source_id: usize,
@ -12,6 +20,9 @@ pub(super) struct FormatDraft {
error: String,
}
impl FormatDraft {
pub(super) fn is_for(&self, layer: usize) -> bool {
self.layer == layer
}
pub(super) fn new(layout: &Layout, i: usize) -> Self {
let source_id = layout.formats().source_for[i];
let source = layout.formats().sources[source_id];
@ -162,8 +173,14 @@ impl Editor {
}
let i = d.layer;
let mut open = true;
egui::Window::new(format!("Layer properties · {}",label(i))).open(&mut open).default_width(540.0).default_height(740.0).min_height(380.0).vscroll(true).show(ctx,|ui| {
ui.label("Resizing automatically adjusts the layer crop to fit the new dimensions.");
egui::Window::new(format!("Layer properties · {}",label(i))).open(&mut open).default_width(540.0).default_height(520.0).min_height(380.0).vscroll(true).show(ctx,|ui| {
ui.horizontal(|ui| {
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.separator();
if self.property_tab == PropertyTab::Source {
ui.heading("Source / input resolution");
ui.horizontal(|ui| {
ui.label("Source identity");
@ -201,7 +218,10 @@ impl Editor {
});
if old_crop!=d.source.input_crop && let Ok(size)=d.source.input() { d.input_size=size; }
ui.label("Input crop edges: native source pixels. Native-size changes reset the draft input crop before review.");
ui.separator();ui.heading("Layer resolution / final visible box");
}
if self.property_tab == PropertyTab::Layer {
ui.heading("Layer resolution / final visible box");
ui.label("Resizing automatically adjusts the layer crop to fit the new dimensions.");
ui.horizontal(|ui| {
ui.label("Format");
if aspect_combo(ui,"layer-aspect",&mut d.layer_aspect) && let Some(r)=d.layer_aspect.ratio() { d.size[1]=d.size[0]/r; }
@ -213,6 +233,8 @@ impl Editor {
if d.size[0]!=old[0] { d.size[1]=d.size[0]/ratio; } else if d.size[1]!=old[1] { d.size[0]=d.size[1]*ratio; }
}
ui.checkbox(&mut self.keep_aspect_ratio,"Keep aspect ratio when resizing");
}
if self.property_tab != PropertyTab::Crop {
let g=self.layout.layers()[i];
let [x,y]=self.corner.offsets_on(g,self.layout.formats().output);
let geometry=self.corner.geometry_on(x,y,d.size[0],d.size[1],self.layout.formats().output);
@ -231,7 +253,10 @@ impl Editor {
let result=self.corner.geometry_on(x,y,d.size[0],d.size[1],self.layout.formats().output).and_then(|g|self.layout.configure(i,d.source_id,d.source,g,true));
match result { Ok(_)=>{self.sync();d=FormatDraft::new(&self.layout,i);},Err(e)=>d.error=e }
}
ui.separator();ui.heading("Layer crop / zoom & position");
ui.small("Apply commits pending Source and Layer changes together. Switching tabs keeps your edits.");
}
if self.property_tab == PropertyTab::Crop {
ui.heading("Layer crop / zoom & position");
ui.label("Zoom and position change the crop values inside this layer, keeping its visible box fixed. 100% is the minimum crop that fills the box.");
let mut percent=d.framing.zoom*100.0;
ui.horizontal(|ui| {
@ -263,6 +288,7 @@ impl Editor {
let preview_rect=fit_rect(rect,[current.width,current.height]);
paint_pattern(ui.painter(),preview_rect,self.layout.formats().sources[self.layout.formats().source_for[i]],self.layout.formats().advanced[i]);
ui.label("Source test pattern only; the screen reference image is not source content.");
}
if !d.error.is_empty() {ui.colored_label(AMBER,&d.error);}
ui.collapsing("Calculated crops / provisional WebRCS mapping",|ui| {
if let Ok(report)=self.layout.calculation_report(i) {
@ -410,6 +436,52 @@ mod tests {
);
frame(app, ctx, vec![mouse(pos, false)]);
}
#[test]
fn property_tabs_keep_pending_edits_and_show_only_their_controls() {
let mut app = Editor::default();
let ctx = egui::Context::default();
let before = *app.layout.layers();
let mut d = FormatDraft::new(&app.layout, 1);
d.size = [800.0, 450.0];
d.framing.zoom = 2.0;
app.format_draft = Some(d);
for (title, tab, heading) in [
("Source", PropertyTab::Source, "Source / input resolution"),
("Crop", PropertyTab::Crop, "Layer crop / zoom & position"),
(
"Layer",
PropertyTab::Layer,
"Layer resolution / final visible box",
),
] {
click_text(&mut app, &ctx, title);
assert_eq!(app.property_tab, tab);
let output = frame(&mut app, &ctx, vec![]);
let headings: Vec<_> = output
.shapes
.iter()
.filter_map(|s| match &s.shape {
egui::Shape::Text(t)
if [
"Source / input resolution",
"Layer crop / zoom & position",
"Layer resolution / final visible box",
]
.contains(&t.galley.text()) =>
{
Some(t.galley.text())
}
_ => None,
})
.collect();
assert_eq!(headings, vec![heading]);
let d = app.format_draft.as_ref().unwrap();
assert_eq!(d.size, [800.0, 450.0]);
assert_eq!(d.framing.zoom, 2.0);
assert_eq!(*app.layout.layers(), before);
}
}
#[test]
fn unchanged_output_apply_does_not_reset_camera_and_reapplies_after_undo() {
let mut app = Editor {

View File

@ -1,7 +1,7 @@
use super::*;
#[path = "format_ui.rs"]
mod format_ui;
use format_ui::{FormatDraft, OutputDraft};
use format_ui::{FormatDraft, OutputDraft, PropertyTab};
use midra_layout::import::{DetectedShape, ImportDocument, parse_svg, parse_values};
use midra_layout::{AlignTarget, Alignment, Corner, Geometry, Layout, ResizeHandle, ResizeMode};
@ -20,6 +20,7 @@ pub struct Editor {
keep_aspect_ratio: bool,
resize_mode: ResizeMode,
format_draft: Option<FormatDraft>,
property_tab: PropertyTab,
output_draft: Option<OutputDraft>,
edit_content: bool,
show_pattern: bool,
@ -173,6 +174,7 @@ impl Default for Editor {
keep_aspect_ratio: true,
resize_mode: ResizeMode::Individual,
format_draft: None,
property_tab: PropertyTab::default(),
output_draft: None,
edit_content: false,
show_pattern: false,
@ -753,6 +755,7 @@ impl Editor {
TEXT,
);
if click(ui, &ink, [0.0, 214.0, w, 34.0], "open-formats") {
self.property_tab = PropertyTab::Layer;
self.format_draft = Some(FormatDraft::new(&self.layout, i));
}
if let Ok(m) = self.layout.formats().mapping(i, g) {
@ -1002,9 +1005,18 @@ impl Editor {
let selected = self.layout.selected_indices();
if let Some(i) = self.layout.selected() {
ui.weak(label(i));
if ui.button("Layer properties…").clicked() {
self.format_draft = Some(FormatDraft::new(&self.layout, i));
ui.close_menu();
for (title, tab) in [
("Source properties…", PropertyTab::Source),
("Layer properties…", PropertyTab::Layer),
("Crop properties…", PropertyTab::Crop),
] {
if ui.button(title).clicked() {
if self.format_draft.as_ref().is_none_or(|d| !d.is_for(i)) {
self.format_draft = Some(FormatDraft::new(&self.layout, i));
}
self.property_tab = tab;
ui.close_menu();
}
}
let crop_label = if self.edit_content {
"Done adjusting crop"
@ -1587,8 +1599,8 @@ impl Editor {
if hit.is_none_or(|i| !self.layout.selection_mask()[i]) {
self.layout.select(hit);
self.edit_content = false;
self.sync();
}
self.sync();
}
response.context_menu(|ui| self.layer_context_menu(ui));
let screen = Ink {
@ -3035,7 +3047,12 @@ mod tests {
#[test]
fn canvas_context_menu_selects_target_preserves_groups_and_opens_properties() {
for grouped in [false, true] {
for (grouped, title, tab) in [
(false, "Source properties…", PropertyTab::Source),
(false, "Layer properties…", PropertyTab::Layer),
(false, "Crop properties…", PropertyTab::Crop),
(true, "Lock selected layers", PropertyTab::Layer),
] {
let mut app = Editor::default();
if grouped {
app.layout.set_selection([true; 2]);
@ -3059,11 +3076,6 @@ mod tests {
let output = frame(&mut app, &ctx, vec![]);
assert_eq!(app.layout.selection_mask(), [true, grouped]);
assert_eq!(*app.layout.layers(), before);
let title = if grouped {
"Lock selected layers"
} else {
"Layer properties…"
};
let pos = output
.shapes
.iter()
@ -3085,6 +3097,7 @@ mod tests {
assert!(app.layout.selected_indices().is_empty());
} else {
assert!(app.format_draft.is_some());
assert_eq!(app.property_tab, tab);
}
assert_eq!(*app.layout.layers(), before);
}

View File

@ -142,7 +142,8 @@ clipboard testing against a running draw.io instance remains to be done.
offsets are not copied. Crop zoom is included separately as a percentage and
can be toggled on paste. This is not a native WebRCS clipboard payload.
Right-click a layer for **Layer properties**, **Adjust layer crop**, aspect-ratio
Right-click a layer for **Source properties**, **Layer properties**, **Crop properties**,
**Adjust layer crop**, aspect-ratio
locking, alignment, copying values, and lock/hide actions. Right-clicking a layer
already in a selection keeps the whole selection and offers **Resize together**.
Right-clicking an unselected layer selects it first. Locked/hidden layers remain
@ -359,3 +360,9 @@ Apply buttons are muted and disabled when their values already match the layout.
Pending changes make Apply solid purple. This applies to position/size, output
resolution, source/input/layer formats, crop framing, 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.
Switching tabs retains pending edits. Source and Layer changes still apply together
with their shared Apply button; Crop has its own Apply button.