Adjust layer crops automatically on resize and clarify crop controls

This commit is contained in:
Dandaedre 2026-11-13 13:43:51 +01:00
parent 4f90ec760e
commit feb829ae02
6 changed files with 51 additions and 50 deletions

View File

@ -9,7 +9,6 @@ pub(super) struct FormatDraft {
size: [f64; 2],
layer_aspect: Aspect,
framing: Framing,
allow_adjustment: bool,
error: String,
}
impl FormatDraft {
@ -25,7 +24,6 @@ impl FormatDraft {
size: [g.width, g.height],
layer_aspect: Aspect::Custom,
framing: layout.formats().mapping(i, g).unwrap().framing,
allow_adjustment: false,
error: String::new(),
}
}
@ -157,8 +155,8 @@ impl Editor {
}
let i = d.layer;
let mut open = true;
egui::Window::new(format!("Formats & framing · {}",label(i))).open(&mut open).default_width(540.0).default_height(740.0).min_height(380.0).vscroll(true).show(ctx,|ui| {
ui.label("Scroll for content framing, preview and crop calculations.");
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.");
ui.heading("Source / input resolution");
ui.horizontal(|ui| {
ui.label("Source identity");
@ -215,16 +213,16 @@ impl Editor {
let input_matches=d.source.input().is_ok_and(|size| (size[0]-d.input_size[0]).abs()<1e-7 && (size[1]-d.input_size[1]).abs()<1e-7);
let reviewed=if input_matches {geometry.and_then(|geometry|preview.configure(i,d.source_id,d.source,geometry,true))} else {Err("Input resolution is invalid or does not match the crop edges.".into())};
match &reviewed {
Ok(message) if !message.is_empty()=>{ ui.colored_label(AMBER,message); ui.checkbox(&mut d.allow_adjustment,"Accept the content-center adjustment shown above"); },
Ok(message) if !message.is_empty()=>{ ui.label(message); },
Err(e)=>{ ui.colored_label(AMBER,e); },
_=>{}
}
if ui.add_enabled(reviewed.is_ok(),egui::Button::new("Apply source / input / layer formats")).clicked() {
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,d.allow_adjustment));
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("Content framing");
ui.label("These controls operate on the applied formats above. 100% is the minimum crop that fills the box.");
ui.separator();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| {
if ui.add(egui::DragValue::new(&mut percent).speed(1.0).custom_formatter(|v,_|number(v)).suffix("% content zoom")).changed() {d.framing.zoom=percent/100.0;}
@ -236,16 +234,16 @@ impl Editor {
ui.label(format!("Offsets in output px: X ±{:.1}, Y ±{:.1}. Positive moves content right/down.",limit[0],limit[1]));
}
ui.horizontal(|ui| {
let apply=ui.button("Apply framing").clicked();
let apply=ui.button("Apply crop").clicked();
let recenter=ui.button("Recenter").clicked();
let reset=ui.button("Reset framing").clicked();
let reset=ui.button("Reset crop").clicked();
if recenter { d.framing=self.layout.formats().mapping(i,current).unwrap().framing; d.framing.offset=[0.0;2]; }
if reset {d.framing=Framing::default();}
if apply||recenter||reset {
match self.layout.set_framing(i,d.framing) {Ok(())=>{self.sync();d.error.clear();d.framing=self.layout.formats().mapping(i,current).unwrap().framing;},Err(e)=>d.error=e}
}
});
if ui.add(egui::Button::new(if self.edit_content { "Done editing content" } else { "Edit content" }).selected(self.edit_content)).clicked() {
if ui.add(egui::Button::new(if self.edit_content { "Done adjusting crop" } else { "Adjust layer crop" }).selected(self.edit_content)).clicked() {
self.edit_content = !self.edit_content;
}
ui.checkbox(&mut self.show_pattern,"Show source-coordinate test pattern in viewport");

View File

@ -284,16 +284,13 @@ impl Formats {
if [before.width, before.height] == [after.width, after.height] {
return Ok(());
}
let (crop, adjusted) = reframed(
let (crop, _) = reframed(
self.input(i)?,
[before.width, before.height],
self.advanced[i],
self.input(i)?,
[after.width, after.height],
)?;
if adjusted {
return Err("Resizing would shift the retained content. Recenter first, or use Formats & framing to review and accept the adjustment.".into());
}
self.advanced[i] = crop;
Ok(())
}

View File

@ -547,7 +547,7 @@ impl Editor {
}
fn inspector(&mut self, ui: &mut egui::Ui) {
let (r, _) = ui.allocate_exact_size(
Vec2::new(ui.available_width(), 1008.0),
Vec2::new(ui.available_width(), 1060.0),
egui::Sense::hover(),
);
let ink = Ink::new(ui, r);
@ -656,7 +656,7 @@ impl Editor {
ink.text(
0.0,
191.0,
"LAYER RESOLUTION · CLICK TO EDIT FORMATS",
"LAYER RESOLUTION · CLICK FOR LAYER PROPERTIES",
11.0,
MUTED,
);
@ -692,16 +692,21 @@ impl Editor {
);
}
let edit_label = if self.edit_content {
"Done editing content"
"Done adjusting crop"
} else {
"Edit content"
"Adjust layer crop"
};
ink.button(0.0, 275.0, w, edit_label, self.edit_content);
if click(ui, &ink, [0.0, 275.0, w, 34.0], "edit-layer-content") {
self.edit_content = !self.edit_content;
}
// Leave a dedicated row for the layer's content-editing action.
let ink = Ink::new(ui, r.translate(Vec2::new(0.0, 54.0)));
ui.put(
Rect::from_min_size(ink.point(0.0, 317.0), Vec2::new(w, 48.0)),
egui::Label::new(egui::RichText::new(
"Changes the crop values inside this layer. Drag content to reposition it; the visible box stays fixed."
).size(12.0).color(MUTED)).wrap().halign(egui::Align::Min),
);
let ink = Ink::new(ui, r.translate(Vec2::new(0.0, 108.0)));
ink.text(0.0, 267.0, "POSITION FROM SCREEN CORNER", 11.0, MUTED);
ink.card(0.0, 292.0, 94.0, 58.0, FIELD, LINE);
for (x, y, c) in [
@ -796,7 +801,7 @@ impl Editor {
ink.text(
0.0,
748.0,
"Formats panel: crops / provisional device mapping",
"Layer properties: crops / provisional device mapping",
12.0,
MUTED,
);

View File

@ -235,7 +235,7 @@ fn shared_sources_update_atomically_and_layer_framing_stays_independent() {
assert_eq!(*layout.formats(), after);
}
#[test]
fn resize_requires_explicit_acceptance_when_center_cannot_be_preserved() {
fn resize_adjusts_crop_automatically_and_undo_restores_framing() {
let mut layout = Layout::default();
let g = box_size(300.0, 250.0);
layout.apply(1, g).unwrap();
@ -250,19 +250,19 @@ fn resize_requires_explicit_acceptance_when_center_cannot_be_preserved() {
.unwrap();
let before = *layout.formats();
let next = box_size(640.0, 360.0);
assert!(layout.apply(1, next).is_err());
assert!(
layout
.configure(1, 1, Source::default(), next, false)
.unwrap_err()
.contains("Review required")
layout.apply(1, next).unwrap();
assert_eq!(layout.layers()[1], next);
close(
layout.formats().mapping(1, next).unwrap().framing.offset[0],
0.0,
);
layout.undo();
assert_eq!(layout.layers()[1], g);
assert_eq!(*layout.formats(), before);
let message = layout
.configure(1, 1, Source::default(), next, true)
.unwrap();
assert!(message.contains("offsets adjusted"));
layout.start_resize(1, Corner::BottomRight, [400.0, 450.0], false);
layout.drag_to([740.0, 560.0]);
layout.finish_drag();
assert_eq!(layout.layers()[1], next);
close(
layout.formats().mapping(1, next).unwrap().framing.offset[0],
0.0,

View File

@ -10,9 +10,9 @@ as a validated device recipe. No REST calls are made.
Implementation limits: integer native/output dimensions 1–16384 per side;
positive finite layer/input dimensions up to 1,000,000 px; content zoom 100–10000%.
These are planning limits, not claimed hardware capabilities. Invalid edits are
rejected atomically. If framing must shift after a resize/source change, the
formats dialog previews the adjusted offsets for explicit acceptance; handle or
numeric resizing refuses the shift and directs the user to recenter/review.
rejected atomically. If framing must shift after a resize/source change, the crop offsets
adjust automatically to fit the new dimensions. Undo restores size and crop
together. Layer properties exposes crop adjustment and reset controls.
## Names and coordinate spaces
@ -224,7 +224,7 @@ Retain the A/B/C positioning layouts. Add sections in this order after the draft
2. **Layer resolution**: final width/height and optional ratio lock, followed by
the existing corner positioning controls.
3. **Framing**: Content zoom, Offset X/Y, Recenter and Reset framing. An explicit
“Edit content” mode makes dragging reframe content inside the fixed box;
“Adjust layer crop” mode makes dragging reframe content inside the fixed box;
ordinary dragging still moves the complete box. Escape leaves framing mode.
4. **WebRCS values**: derived size/position, crop settings and aspect mode, with
an expandable explanation of units and any representability error.

View File

@ -26,7 +26,7 @@ cargo run --locked -p midra-layout
position, or uncheck it for position only. Choose **Include outline in bounds**
if the layer should cover the rectangle's outline too.
5. Click **Apply mapped values** to update the entire selection in one undo step.
Cancel leaves all layers unchanged. Invalid geometry or incompatible framing
Cancel leaves all layers unchanged. Invalid geometry
blocks the whole batch, without partial changes.
The current workspace has two layers; the import review handles all selected
@ -238,8 +238,7 @@ coordinates, alignment, reference-image mapping and warnings use the new output.
The same window offers numeric camera zoom relative to fit-to-screen and a
**1:1 display pixels** action; camera changes never modify crop geometry.
Select one layer and click its **Layer resolution** card to open **Formats &
framing**:
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
dimensions. Input 1/2 are planning identities, not device routing commands.
@ -250,13 +249,13 @@ framing**:
3. Set **Layer resolution** to the final visible box. Use the aspect toggle to
enter an independent custom width and height. Apply source/input/layer changes
together; the selected screen-corner anchor stays fixed.
4. Use **Content framing** for zoom (100–10000%) and X/Y offsets in output pixels.
These controls operate on the applied formats. **Apply framing** is one edit;
**Recenter** preserves zoom; **Reset framing** returns to the minimum centered
4. Use **Layer crop / zoom & position** for zoom (100–10000%) and X/Y offsets in output pixels.
These controls operate on the applied formats. **Apply crop** is one edit;
**Recenter** preserves zoom; **Reset crop** returns to the minimum centered
cover crop. Invalid typed offsets show the permitted range and do not apply.
5. Click **Edit content** in the selected layer’s parameters, below its format
5. Click **Adjust layer crop** in the selected layer’s parameters, below its format
summary, to drag or arrow-nudge content inside the fixed box. The button
highlights while active; click **Done editing content** to leave the mode.
highlights while active; click **Done adjusting crop** to leave the mode.
Drags clamp at valid crop boundaries; Escape cancels a drag and leaves this
mode. Wheel zoom still controls the camera. A source-coordinate test pattern
illustrates framing; it is deliberately separate from the screen reference.
@ -270,11 +269,13 @@ Sources shared by both layers share the input crop. The dialog names affected
layers; each keeps its independent layer crop. Shared changes undo atomically,
and edits affecting a locked layer require it to be unlocked first.
Moving/alignment preserves crops. Resizing or changing input geometry preserves
content zoom and the normalized retained center. If that center no longer fits,
the formats dialog previews the required offset adjustment and requires explicit
acceptance. Ordinary numeric/handle resizing stops at infeasible framing instead
of silently shifting content; recenter first or use the formats dialog.
Moving/alignment preserves crops. Resizing keeps content zoom and the retained
center where possible, automatically shifting the crop when needed to fit the
new size. Source/input changes do the same when applied in Layer properties.
No recentering or extra acceptance is needed. Undo restores both size and crop.
**Adjust layer crop** changes the crop values inside the layer while keeping its
visible box fixed; **Reset crop** returns to the minimum centered crop.
**Calculated crops / provisional WebRCS mapping** shows input crops in native
pixels, advanced crops in usable-input pixels, combined retained native bounds,