mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-03 06:31:42 +01:00
Crop: the Info panel shows the crop frame's W and H (#3145)
While the Crop tool shows a frame, the Info panel's W and H are the frame's own size (before any turn), as in Photoshop, so a crop's ratio can be matched to another photo. Other tools still show the selection. The other #3145 symptoms are already fixed on main: the ratio fields (#3209), the crop box's Undo (#3510) and handle-snap jitter (#3206). Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
1c3db2e5c3
commit
2bc47b5820
2 files changed
+34
-3
No files matched your search
@@ -666,6 +666,16 @@ pub fn sizing(app: &PhotocraftApp) -> Option<[f64; 2]> {
|
||||
frame_size(app.ui.crop_rect?)
|
||||
}
|
||||
|
||||
/// The Info panel's W and H while the Crop tool shows a frame: the frame's size (its own, before
|
||||
/// any turn), as Photoshop's Info panel shows it, so its ratio can be matched (#3145). `None`
|
||||
/// with another tool or no frame, and the panel shows the selection's size.
|
||||
pub fn info_size(app: &PhotocraftApp) -> Option<[f64; 2]> {
|
||||
if app.ui.tool != Tool::Crop {
|
||||
return None;
|
||||
}
|
||||
frame_size(app.ui.crop_rect?)
|
||||
}
|
||||
|
||||
/// The Crop tool owns the arrow keys and X: a pending frame and no gesture in progress.
|
||||
pub fn takes_keys(app: &PhotocraftApp) -> bool {
|
||||
app.ui.tool == Tool::Crop && app.crop.drag.is_none() && app.ui.transform.is_none() && app.ui.crop_rect.is_some_and(|r| r.iter().all(|v| v.is_finite()))
|
||||
@@ -2180,4 +2190,23 @@ mod tests {
|
||||
assert_eq!(frame_size([f64::NAN, 0.0, 1.0, 1.0]), None);
|
||||
assert_eq!(frame_size([-f64::MAX, 0.0, f64::MAX, 1.0]), None);
|
||||
}
|
||||
|
||||
/// #3145: the Info panel shows the pending frame's W × H while the Crop tool is active
|
||||
/// (between gestures too, and its own size when turned), and nothing for other tools.
|
||||
#[test]
|
||||
fn info_panel_shows_the_pending_frame_size() {
|
||||
let mut app = app(SampleType::U8);
|
||||
app.ui.tool = Tool::Crop;
|
||||
app.ui.crop_rect = None;
|
||||
assert_eq!(info_size(&app), None, "no frame");
|
||||
app.ui.crop_rect = Some([20.0, 20.0, 100.0, 65.4]);
|
||||
assert_eq!(info_size(&app), Some([80.0, 45.0]), "rounded as ↵ crops it");
|
||||
app.ui.crop_angle = 30.0;
|
||||
assert_eq!(info_size(&app), Some([80.0, 45.0]), "a turned frame keeps its own size");
|
||||
app.ui.crop_rect = Some([f64::NAN, 0.0, 1.0, 1.0]);
|
||||
assert_eq!(info_size(&app), None, "a broken frame shows nothing");
|
||||
app.ui.crop_rect = Some([20.0, 20.0, 100.0, 60.0]);
|
||||
app.ui.tool = Tool::Move;
|
||||
assert_eq!(info_size(&app), None, "another tool shows the selection instead");
|
||||
}
|
||||
}
|
||||
@@ -1878,7 +1878,9 @@ fn info_panel(app: &mut PhotocraftApp, ui: &mut egui::Ui) {
|
||||
let fx = move |px: f64| units.format(px, dpi, size.width as f64);
|
||||
let units_y = app.session.prefs().units_and_rulers.clone();
|
||||
let fy = move |px: f64| units_y.format(px, dpi, size.height as f64);
|
||||
let sel = st.doc.selection.as_ref().map(photocraft_compose::bounds::content_bounds);
|
||||
let sel = st.doc.selection.as_ref().map(photocraft_compose::bounds::content_bounds).map(|r| [r.width() as f64, r.height() as f64]);
|
||||
// With the Crop tool, W and H are the pending frame's, as in Photoshop (#3145).
|
||||
let wh = crate::crop_ui::info_size(app).or(sel);
|
||||
let pos = app
|
||||
.hover_doc
|
||||
.map(|p| (p[0].floor() as i32, p[1].floor() as i32))
|
||||
@@ -1931,8 +1933,8 @@ fn info_panel(app: &mut PhotocraftApp, ui: &mut egui::Ui) {
|
||||
// Measured from the rulers' zero point (#2955).
|
||||
row(&mut cols[0], "X:", guide_x.map(|p| fx(p - origin[0])).or_else(|| pos.map(|p| fx(p.0 as f64 - origin[0]))).unwrap_or_else(dash));
|
||||
row(&mut cols[0], "Y:", guide_y.map(|p| fy(p - origin[1])).or_else(|| pos.map(|p| fy(p.1 as f64 - origin[1]))).unwrap_or_else(dash));
|
||||
row(&mut cols[1], "W:", sel.map_or_else(dash, |r| fx(r.width() as f64)));
|
||||
row(&mut cols[1], "H:", sel.map_or_else(dash, |r| fy(r.height() as f64)));
|
||||
row(&mut cols[1], "W:", wh.map_or_else(dash, |s| fx(s[0])));
|
||||
row(&mut cols[1], "H:", wh.map_or_else(dash, |s| fy(s[1])));
|
||||
});
|
||||
widgets::hairline(ui);
|
||||
ui.label(
|
||||
|
||||
Reference in new issue
Block a user