Add inverse conversion from smart to edge crop
This commit is contained in:
parent
a872be4766
commit
0c438ebbca
|
|
@ -602,7 +602,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "canvas-pilot"
|
||||
version = "0.10.0-rc.14"
|
||||
version = "0.10.0-rc.15"
|
||||
dependencies = [
|
||||
"base64 0.22.1",
|
||||
"craft-dwg",
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ default-members = ["crates/canvas-pilot"]
|
|||
resolver = "3"
|
||||
|
||||
[workspace.package]
|
||||
version = "0.10.0-rc.14"
|
||||
version = "0.10.0-rc.15"
|
||||
edition = "2024"
|
||||
license = "MIT"
|
||||
repository = "https://proxy.dandaedre.com/gitea/idle-org/canvas-pilot"
|
||||
|
|
|
|||
|
|
@ -511,6 +511,19 @@ impl Editor {
|
|||
});
|
||||
if !ui.input(|input| input.pointer.primary_down()) { d.crop_before = None; }
|
||||
ui.small(tr(ui.ctx(), "ui.crop-zoom-and-offsets-apply-as-you-edit-offsets-stop-at-the-content-edges-and-adjust"));
|
||||
if ui.button("Convert to Edge crop")
|
||||
.on_hover_text("Keep the current picture and crop, then edit its source edges independently. Undo returns to Smart crop.")
|
||||
.clicked() {
|
||||
match self.layout.convert_to_edge_crop(i) {
|
||||
Ok(()) => {
|
||||
self.sync();
|
||||
d.refresh_fit(&self.layout);
|
||||
self.edit_mask = false;
|
||||
self.edit_content = true;
|
||||
}
|
||||
Err(e) => d.error = e,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if self.property_tab == PropertyTab::Preview {
|
||||
|
|
|
|||
|
|
@ -2515,6 +2515,16 @@ impl Editor {
|
|||
}
|
||||
ui.close();
|
||||
}
|
||||
if self.layout.formats().layer_fit[i].is_none()
|
||||
&& ui.button("Convert to Edge crop")
|
||||
.on_hover_text("Keep the current picture and crop, then edit its source edges independently. Undo returns to Smart crop.")
|
||||
.clicked() {
|
||||
match self.layout.convert_to_edge_crop(i) {
|
||||
Ok(()) => { self.sync(); self.edit_mask = false; self.edit_content = true; },
|
||||
Err(e) => self.error = e,
|
||||
}
|
||||
ui.close();
|
||||
}
|
||||
if ui.button(tr(ui.ctx(), "ui.reset-crop")).clicked() {
|
||||
let result = if let Some(mode) = self.layout.formats().layer_fit[i] {
|
||||
self.layout
|
||||
|
|
@ -9126,6 +9136,8 @@ mod tests {
|
|||
!labels.iter().any(|label| label.starts_with("crop.")),
|
||||
"raw key in {language:?} menu"
|
||||
);
|
||||
assert!(labels.contains(&"Convert to Edge crop"));
|
||||
assert!(!labels.contains(&"Convert to Smart crop"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1082,6 +1082,28 @@ impl Layout {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
/// Switch a normal crop to Centered edge crop without changing its picture.
|
||||
pub fn convert_to_edge_crop(&mut self, i: usize) -> Result<(), String> {
|
||||
if !self.selectable(i) {
|
||||
return Err("Unlock and show this layer first.".into());
|
||||
}
|
||||
if self.formats.layer_fit[i].is_some() {
|
||||
return Ok(());
|
||||
}
|
||||
self.finish_drag();
|
||||
let geometry = self.layers[i];
|
||||
let crop = self.formats.advanced[i];
|
||||
formats::mapping(
|
||||
self.formats.input(i)?,
|
||||
[geometry.width, geometry.height],
|
||||
crop,
|
||||
)?;
|
||||
let before = self.snapshot();
|
||||
self.formats.layer_fit[i] = Some(formats::LayerFit::Centered);
|
||||
self.remember(before);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn start_content_resize(&mut self, index: usize, handle: ResizeHandle, point: [f64; 2]) {
|
||||
self.finish_drag();
|
||||
if !self.selectable(index)
|
||||
|
|
|
|||
|
|
@ -505,3 +505,48 @@ fn rounded_import_tolerance_is_bounded_and_does_not_change_native_or_stretch_mod
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn smart_crop_converts_to_centered_edge_crop_losslessly_and_undoes() {
|
||||
use canvas_pilot::formats::{Framing, Mask};
|
||||
let mut layout = Layout::default();
|
||||
layout.select(Some(0));
|
||||
layout
|
||||
.set_framing(
|
||||
0,
|
||||
Framing {
|
||||
zoom: 1.75,
|
||||
offset: [41.0, -23.0],
|
||||
},
|
||||
)
|
||||
.unwrap();
|
||||
let mask = Mask {
|
||||
left: 0.1,
|
||||
right: 0.05,
|
||||
..Default::default()
|
||||
};
|
||||
layout.set_mask(0, mask).unwrap();
|
||||
let before = Project::from_layout(&layout);
|
||||
let geometry = layout.layers()[0];
|
||||
let crop = layout.formats().advanced[0];
|
||||
let input = layout.formats().input(0).unwrap();
|
||||
|
||||
layout.convert_to_edge_crop(0).unwrap();
|
||||
assert_eq!(layout.formats().layer_fit[0], Some(LayerFit::Centered));
|
||||
assert_eq!(layout.layers()[0], geometry);
|
||||
assert_eq!(layout.formats().advanced[0], crop);
|
||||
assert_eq!(layout.formats().masks[0], mask);
|
||||
let image = LayerFit::Centered
|
||||
.image(crop.remaining(input).unwrap(), geometry)
|
||||
.unwrap();
|
||||
near(image.x, geometry.x);
|
||||
near(image.y, geometry.y);
|
||||
near(image.width, geometry.width);
|
||||
near(image.height, geometry.height);
|
||||
|
||||
layout.undo();
|
||||
assert_eq!(Project::from_layout(&layout), before);
|
||||
layout.redo();
|
||||
layout.convert_to_smart_crop(0).unwrap();
|
||||
assert_eq!(Project::from_layout(&layout), before);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,12 @@
|
|||
|
||||
## Unreleased
|
||||
|
||||
### v0.10.0-rc.15
|
||||
|
||||
- Add the inverse **Convert to Edge crop** action to the layer context menu and
|
||||
Crop properties. Preserve the Smart crop's picture, crop, container and mask,
|
||||
enter the green edge helper immediately, and return to Smart crop with Undo.
|
||||
|
||||
### v0.10.0-rc.14
|
||||
|
||||
- Enabling an input preview from the right-click menu or Preview properties queues
|
||||
|
|
|
|||
|
|
@ -192,8 +192,10 @@ Numeric crop controls remain available in Crop properties.
|
|||
**Convert to Smart crop**, in the right-click menu and Crop properties, switches
|
||||
to Canvas Pilot's normal zoom/position algorithm. It preserves an exactly matching
|
||||
crop; otherwise it resets to centered cover framing, so the picture can change.
|
||||
Undo restores the previous fit and crop. Unchecking Advanced layer fit also resets
|
||||
to centered cover framing. Pending Source edits still require Apply.
|
||||
**Convert to Edge crop** appears in the same places for a Smart crop. It keeps the
|
||||
current picture, crop, container and mask exactly as they are, selects Centered fit,
|
||||
and opens the green edge helper. Undo returns to Smart crop. Unchecking Advanced
|
||||
layer fit resets to centered cover framing. Pending Source edits still require Apply.
|
||||
|
||||
Device loads use Smart crop when the retained picture exactly fills the container
|
||||
with uniform scaling and the crop is representable by the normal algorithm.
|
||||
|
|
|
|||
Loading…
Reference in New Issue