Apply Layer properties size edits immediately
Beffroi/beffroi-tools/pipeline/head There was a failure building this commit
Details
Beffroi/beffroi-tools/pipeline/head There was a failure building this commit
Details
This commit is contained in:
parent
7626515dd2
commit
274934e079
|
|
@ -13,6 +13,7 @@ pub(super) struct FormatDraft {
|
|||
layer: usize,
|
||||
baseline: (usize, Source, [f64; 2], [f64; 2], Framing),
|
||||
crop_before: Option<Layout>,
|
||||
layer_before: Option<Layout>,
|
||||
source_id: usize,
|
||||
source: Source,
|
||||
input_size: [f64; 2],
|
||||
|
|
@ -48,6 +49,27 @@ impl FormatDraft {
|
|||
self.baseline.4 = self.framing;
|
||||
Ok(())
|
||||
}
|
||||
fn apply_layer_size(
|
||||
&mut self,
|
||||
layout: &mut Layout,
|
||||
reference: PositionReference,
|
||||
dragging: bool,
|
||||
) -> Result<(), String> {
|
||||
if dragging && self.layer_before.is_none() {
|
||||
self.layer_before = Some(layout.clone());
|
||||
}
|
||||
let mut next = self.layer_before.as_ref().unwrap_or(layout).clone();
|
||||
let g = next.layers()[self.layer];
|
||||
let output = next.formats().output;
|
||||
let [x, y] = reference.offsets_on(g, output);
|
||||
let geometry = reference.geometry_on(x, y, self.size[0], self.size[1], output)?;
|
||||
next.apply(self.layer, geometry)?;
|
||||
self.framing = next.formats().mapping(self.layer, geometry)?.framing;
|
||||
self.baseline.3 = self.size;
|
||||
self.baseline.4 = self.framing;
|
||||
*layout = next;
|
||||
Ok(())
|
||||
}
|
||||
fn commit_ratio(&mut self, locked: bool) -> Result<(), String> {
|
||||
self.ratio_edit.commit()?;
|
||||
if locked && let Some(ratio) = self.ratio_edit.target {
|
||||
|
|
@ -100,6 +122,7 @@ impl FormatDraft {
|
|||
Self {
|
||||
layer: i,
|
||||
crop_before: None,
|
||||
layer_before: None,
|
||||
baseline: (
|
||||
source_id,
|
||||
source,
|
||||
|
|
@ -361,6 +384,7 @@ impl Editor {
|
|||
ui.label("Input crop edges: native source pixels. Native-size changes reset the draft input crop before review.");
|
||||
}
|
||||
if self.property_tab == PropertyTab::Layer {
|
||||
let before_size = d.size;
|
||||
ui.heading("Layer resolution / final visible box");
|
||||
ui.label("Resizing automatically adjusts the layer crop to fit the new dimensions.");
|
||||
ui.horizontal(|ui| {
|
||||
|
|
@ -384,8 +408,16 @@ impl Editor {
|
|||
let ratio=old[0]/old[1];
|
||||
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; }
|
||||
}
|
||||
if d.size != before_size {
|
||||
match d.apply_layer_size(&mut self.layout, position_reference, ui.input(|input| input.pointer.primary_down())) {
|
||||
Ok(()) => { self.sync(); d.error.clear(); },
|
||||
Err(error) => d.error = error,
|
||||
}
|
||||
}
|
||||
if self.property_tab != PropertyTab::Crop {
|
||||
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 {
|
||||
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);
|
||||
|
|
@ -401,7 +433,7 @@ impl Editor {
|
|||
if apply_button(ui,"Apply source / input / layer formats", pending).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("Apply commits pending Source and Layer changes together. Switching tabs keeps your edits.");
|
||||
ui.small("Source changes require Apply. Switching tabs keeps pending source edits.");
|
||||
}
|
||||
if self.property_tab == PropertyTab::Crop {
|
||||
ui.heading("Layer crop / zoom & position");
|
||||
|
|
@ -608,6 +640,56 @@ mod tests {
|
|||
frame(app, ctx, vec![]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn layer_size_autoapplies_without_committing_source_drafts() {
|
||||
let ctx = egui::Context::default();
|
||||
let mut app = Editor::default();
|
||||
let before = app.layout.layers().clone();
|
||||
let sources = app.layout.formats().sources.clone();
|
||||
let mut d = FormatDraft::new(&app.layout, 1);
|
||||
d.source.native = [1280, 720];
|
||||
d.input_size = [1280.0, 720.0];
|
||||
app.format_draft = Some(d);
|
||||
enter_value(&mut app, &ctx, "W 640.0", "800");
|
||||
assert_eq!(app.layout.layers()[1].width, 800.0);
|
||||
assert_eq!(app.layout.layers()[1].height, 450.0);
|
||||
assert_eq!(app.layout.formats().sources, sources);
|
||||
assert_eq!(
|
||||
app.format_draft.as_ref().unwrap().source.native,
|
||||
[1280, 720]
|
||||
);
|
||||
let output = frame(&mut app, &ctx, vec![]);
|
||||
assert!(!output.shapes.iter().any(|s| matches!(&s.shape, egui::Shape::Text(t) if t.galley.text() == "Apply source / input / layer formats")));
|
||||
app.layout.undo();
|
||||
assert_eq!(app.layout.layers(), &before);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn layer_size_drag_is_atomic_and_invalid_edits_keep_geometry() {
|
||||
let mut layout = Layout::default();
|
||||
let before = layout.layers().clone();
|
||||
let formats = layout.formats().clone();
|
||||
let mut d = FormatDraft::new(&layout, 1);
|
||||
for width in [700.0, 750.0, 800.0] {
|
||||
d.size = [width, 450.0];
|
||||
d.apply_layer_size(&mut layout, PositionPoint::Center.into(), true)
|
||||
.unwrap();
|
||||
assert_eq!(layout.layers()[1].center(), before[1].center());
|
||||
}
|
||||
let resized = layout.layers().clone();
|
||||
d.size = [-1.0, 450.0];
|
||||
assert!(
|
||||
d.apply_layer_size(&mut layout, PositionPoint::Center.into(), true)
|
||||
.is_err()
|
||||
);
|
||||
assert_eq!(layout.layers(), &resized);
|
||||
layout.undo();
|
||||
assert_eq!(layout.layers(), &before);
|
||||
assert_eq!(layout.formats(), &formats);
|
||||
layout.redo();
|
||||
assert_eq!(layout.layers(), &resized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn draft_ratio_changes_only_apply_to_document_on_apply() {
|
||||
let mut layout = Layout::default();
|
||||
|
|
@ -999,6 +1081,7 @@ mod tests {
|
|||
#[test]
|
||||
fn source_and_layer_dialog_applies_worked_example_with_one_undo() {
|
||||
let mut app = Editor {
|
||||
property_tab: PropertyTab::Source,
|
||||
keep_aspect_ratio: false,
|
||||
..Default::default()
|
||||
};
|
||||
|
|
|
|||
|
|
@ -316,8 +316,8 @@ and crop together. Zero, negative, non-finite and out-of-range results are rejec
|
|||
With the lock unchecked, entering a ratio does not resize: it stays ready until
|
||||
the lock is enabled. The displayed current ratio still describes the actual
|
||||
sizes. Selecting another layer discards that prepared value. In Layer properties,
|
||||
manual ratios and presets update the size draft only when locked; **Apply** commits
|
||||
the draft. Unapplied ratio text/targets are temporary UI state, not saved settings
|
||||
manual ratios and presets resize immediately when locked, as do width/height edits.
|
||||
The Layer tab needs no Apply; pending Source edits still require their own Apply. Unapplied ratio text/targets are temporary UI state, not saved settings
|
||||
or a separate project constraint. Source content remains proportionally scaled.
|
||||
|
||||
### Move, Pan and Zoom tools
|
||||
|
|
@ -428,8 +428,8 @@ Select one layer and click its **Layer resolution** card to open **Layer propert
|
|||
the draft crop to the full source before review. A custom input retains the
|
||||
original Source format, e.g. 16:9 native 1920 × 1080 cropped to 1920 × 1000.
|
||||
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.
|
||||
enter an independent custom width and height. Layer changes apply immediately;
|
||||
the selected measurement anchor stays fixed. Source/input changes require Apply.
|
||||
4. Use **Layer crop / zoom & position** for zoom (100–10000%) and X/Y offsets in output pixels.
|
||||
Zoom is bounded to 100–10000%; negative or non-finite entries are rejected.
|
||||
X/Y offsets remain signed for left/up positioning; they are not crop amounts.
|
||||
|
|
@ -492,14 +492,14 @@ to both kinds of resize handles.
|
|||
|
||||
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 drafts, source/input/layer formats, names/folders, and mapped imports. Each
|
||||
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.
|
||||
Switching tabs retains pending edits. Source and Layer changes still apply together
|
||||
with their shared Apply button; Crop applies immediately without a separate button.
|
||||
Switching tabs retains pending Source edits, which require Apply. Layer size and
|
||||
Crop changes apply immediately; each continuous drag is one Undo step.
|
||||
|
||||
Closing a window with unapplied source/layer formats, invalid output values,
|
||||
layer names/folders, a rename, or mapped Midra imports asks **Would you like to
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@
|
|||
|
||||
## Unreleased
|
||||
|
||||
- Layer properties’ Layer tab applies size/locked-ratio changes immediately; remove its Apply button. Drag edits undo together; Source edits remain explicit.
|
||||
|
||||
- Layer properties’ Crop tab automatically enables visual crop editing and disables it on leaving/closing; remove its redundant toggle button.
|
||||
|
||||
- Ctrl/Pivot now works on crop/zoom handles, keeping the source pixel under the saved gravity point fixed; crop limits prevent empty borders.
|
||||
|
|
|
|||
Loading…
Reference in New Issue