diff --git a/crates/ui-egui/src/panels/info.rs b/crates/ui-egui/src/panels/info.rs index f3a6572081..eeca9db7e3 100644 --- a/crates/ui-egui/src/panels/info.rs +++ b/crates/ui-egui/src/panels/info.rs @@ -49,8 +49,6 @@ pub(super) fn info_panel(app: &mut PhotocraftApp, ui: &mut egui::Ui) { // With the Crop tool, W and H are the pending frame's, as in Photoshop (#3145). let crop = crate::crop_ui::info_size(app); let wh = crop.or(sel); - // And the frame's ratio, to match another photo's (#3145). - let ratio = crop.and_then(crate::crop_ui::ratio_label); let pos = hover_pixel(app); // While a guide is dragged (#5728), the Info panel shows its position in one axis only, even // when the pointer is outside the canvas (ruler drags do not update `hover_doc` there). @@ -90,12 +88,6 @@ pub(super) fn info_panel(app: &mut PhotocraftApp, ui: &mut egui::Ui) { let [w, h] = wh.map_or_else(|| [dash(), dash()], |s| wh_readout(&units_wh, dpi, [size.width as f64, size.height as f64], s)); row(&mut cols[1], "W:", w); row(&mut cols[1], "H:", h); - if let Some(r) = ratio { - cols[1].horizontal(|ui| { - ui.label(RichText::new(format!("{}:", tl!("Ratio"))).color(t.text_dim).size(11.5)); - ui.label(RichText::new(r).font(mono.clone()).color(t.text)); - }); - } }); widgets::hairline(ui); ui.label( diff --git a/crates/ui-egui/src/tools/crop_ui.rs b/crates/ui-egui/src/tools/crop_ui.rs index 74c6add2f7..024e40b5bd 100644 --- a/crates/ui-egui/src/tools/crop_ui.rs +++ b/crates/ui-egui/src/tools/crop_ui.rs @@ -738,31 +738,6 @@ pub fn info_size(app: &PhotocraftApp) -> Option<[f64; 2]> { frame_size(app.ui.crop_rect?) } -/// The Info panel's ratio for a frame of `size` (whole px, as [`info_size`] gives): reduced to -/// whole numbers when both are small ("4:3", "16:9", "1:1"), else as a decimal against 1 on the -/// short side ("1.413:1", "1:1.5"), so a photo's ratio can be matched (#3145). -pub fn ratio_label(size: [f64; 2]) -> Option { - let [w, h] = size; - if !(w.is_finite() && h.is_finite() && w >= 1.0 && h >= 1.0) { - return None; - } - // Whole px from `frame_size`; `as` saturates for huge values and the gcd stays positive. - let (a, b) = (w.round() as u64, h.round() as u64); - let (mut x, mut y) = (a, b); - while y != 0 { - (x, y) = (y, x % y); - } - let (rw, rh) = (a / x.max(1), b / x.max(1)); - if rw <= 32 && rh <= 32 { - return Some(format!("{rw}:{rh}")); - } - let trim = |v: f64| { - let s = format!("{v:.3}"); - s.trim_end_matches('0').trim_end_matches('.').to_string() - }; - Some(if w >= h { format!("{}:1", trim(w / h)) } else { format!("1:{}", trim(h / w)) }) -} - /// 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())) diff --git a/crates/ui-egui/src/tools/crop_ui/tests.rs b/crates/ui-egui/src/tools/crop_ui/tests.rs index 280b854c00..52a6295a75 100644 --- a/crates/ui-egui/src/tools/crop_ui/tests.rs +++ b/crates/ui-egui/src/tools/crop_ui/tests.rs @@ -1236,38 +1236,6 @@ fn info_panel_shows_the_pending_frame_size() { assert_eq!(info_size(&app), None, "another tool shows the selection instead"); } -/// #3145: the Info panel's crop ratio, reduced when small, else a decimal against 1. -#[test] -fn ratio_label_reduces_or_shows_a_decimal() { - assert_eq!(ratio_label([400.0, 300.0]).as_deref(), Some("4:3")); - assert_eq!(ratio_label([1920.0, 1080.0]).as_deref(), Some("16:9")); - assert_eq!(ratio_label([500.0, 500.0]).as_deref(), Some("1:1")); - assert_eq!(ratio_label([800.0, 1000.0]).as_deref(), Some("4:5")); - assert_eq!(ratio_label([1413.0, 1000.0]).as_deref(), Some("1.413:1")); - assert_eq!(ratio_label([200.0, 301.0]).as_deref(), Some("1:1.505")); - assert_eq!(ratio_label([1000.0, 1.0]).as_deref(), Some("1000:1")); - // Broken or absurd sizes never panic. - assert_eq!(ratio_label([f64::NAN, 1.0]), None); - assert_eq!(ratio_label([0.0, 1.0]), None); - assert!(ratio_label([f64::MAX, 1.0]).is_some()); -} - -/// #3145 review: the ratio of a frame that is 16:9 only after rounding to whole px, of a frame -/// near 16:9 but not on it, and of degenerate frames (under a pixel, or a line). -#[test] -fn ratio_label_rounds_and_rejects_degenerate_frames() { - assert_eq!(ratio_label([1920.4, 1079.6]).as_deref(), Some("16:9"), "rounded to whole px first"); - assert_eq!(ratio_label([1366.0, 768.0]).as_deref(), Some("1.779:1"), "near 16:9 is not 16:9"); - assert_eq!(ratio_label([1.0, 1.0]).as_deref(), Some("1:1")); - assert_eq!(ratio_label([0.4, 100.0]), None, "under a pixel wide"); - assert_eq!(ratio_label([100.0, 0.0]), None, "a line"); - assert_eq!(ratio_label([-16.0, -9.0]), None, "negative"); - assert_eq!(ratio_label([f64::INFINITY, 9.0]), None); - // A frame `frame_size` floors to 1 px stays labelled, never a division by zero. - let tiny = frame_size([0.0, 0.0, 0.2, 0.4]).unwrap(); - assert_eq!(ratio_label(tiny).as_deref(), Some("1:1")); -} - /// #3145 review: the crop frame's W and H use the Info panel's formatter for the ruler unit, /// the same one the selection's go through. #[test]