Skip to content

PhotoCraft: An open-source, photo editor written by scratch in pure Rust

Merge PR #6936: Crop tool: switching tools drops an untouched ratio-fitted frame instead of cropping

aiongg7c08e3d7bb9c
diff --cc crates/ui-egui/src/crop_ui.rs
index 7c5e4db8e,0910f3de6..feb90da8b
--- a/crates/ui-egui/src/crop_ui.rs
+++ b/crates/ui-egui/src/crop_ui.rs
@@@ -249,24 -248,9 +249,24 @@@ pub(crate) fn apply_ratio(app: &mut Pho
crate::crop_mode::sync_frame(app);
}
+/// [`apply_ratio`] for a ratio being typed: fits from `base`, the frame the edit started with,
+/// not from the frame the last keystroke's ratio left (#7752).
+pub(crate) fn apply_ratio_from(app: &mut PhotocraftApp, base: [f64; 4]) {
+ if app.ui.tool != Tool::Crop || app.crop.drag.is_some() {
+ return;
+ }
+ if let Some(ratio) = preset_ratio(app)
+ && let Some(fitted) = fitted_ratio(base, ratio)
+ && app.ui.crop_rect != Some(fitted)
+ {
+ keyed(app, fitted);
+ }
+ crate::crop_mode::sync_frame(app);
+}
+
fn fit_frame(app: &mut PhotocraftApp) {
let dpi = app.session.active().map_or(72.0, |s| f64::from(s.doc.resolution_dpi));
- let pt_per_in = app.session.prefs().units_and_rulers.point_size.per_inch();
+ let sized = crate::crop_size::target(&app.ui.tool_options, dpi).is_some();
if let Some(r) = app.ui.crop_rect
&& let Some(ratio) = preset_ratio(app)
&& let Some(fitted) = fitted_ratio(r, ratio)