Browse / github.com/storytold/photocraft / patch
Fix Crop Clear retaining custom proportions
in crop tool clear proportions button dont work in crop tool clear proportions button dont work
- Status
- open
- Score
- 0.00
- Adopters
- 0 other operators
- Author
- vanvo (imported from pull request #9842, open)
- Base
7ac7b8b106acccf6826d45ed5c9e481dfe341035- Size
- +52 −0 in 2 files
- Review
- pending
- Shared
- 2026-10-28
- Id
5e78fbb466bebb3d0e784f1f
How it went
No other operator has reported using it yet.
Diff
raw · crates/ui-egui/src/tools/crop_size.rs crates/ui-egui/tests/it/crop_default_mode.rs
@@ -232,6 +232,7 @@ pub fn clear_ratio(o: &mut ToolOptions) { clear(o); } else { o.crop_ratio.clear();+ select_custom_ratio(o); } } @@ -385,6 +386,26 @@ mod tests { assert_eq!(width / height, 4.0 / 3.0); } + #[test]+ fn clear_ratio_discards_complete_and_partial_ratio_fields() {+ for (width, height) in [(16.0, 9.0), (4.0, 0.0), (0.0, 3.0)] {+ let mut options = ToolOptions::default();+ set_custom_ratio_fields(&mut options, width, height);+ clear_ratio(&mut options);+ assert!(options.crop_ratio.is_empty());+ assert_eq!(custom_ratio_fields(&options, (300.0, 200.0)), (0.0, 0.0));+ set_custom_ratio_fields(&mut options, 5.0, 0.0);+ assert!(options.crop_ratio.is_empty(), "entering a new width must not reuse the old height");+ assert_eq!(custom_ratio_fields(&options, (300.0, 200.0)), (5.0, 0.0));+ }+ let mut options = whr("4 in", "6 in", "300", PX_PER_IN);+ clear_ratio(&mut options);+ assert_eq!(+ (options.crop_ratio.as_str(), options.crop_width.as_str(), options.crop_height.as_str(), options.crop_resolution.as_str()),+ (WHR, "", "", "")+ );+ }+ #[test] fn custom_ratio_keeps_three_decimals() { // #6487: 1.414 : 1 (ISO A sizes) stays 1.414, not 1.4, as in Photoshop.@@ -238,3 +238,34 @@ fn a_resize_keeps_the_box_centre_after_a_space_pan() { let b = screen_box(&h); assert!(mid(b).distance(mid(box0)) < 0.5, "still where it was: {:?} vs {:?}", mid(b), mid(box0)); }++#[test]+fn clear_removes_the_displayed_crop_proportions_without_changing_the_frame() {+ let _gpu = photocraft_testkit::gpu_lock();+ let Some(mut h) = setup() else { return };+ let o = &mut h.state_mut().ui.tool_options;+ o.crop_ratio = "16:9".into();+ o.crop_custom_ratio_width = 16.0;+ o.crop_custom_ratio_height = 9.0;+ h.run_steps(3);+ assert!(h.query_all_by_value("16").next().is_some());+ assert!(h.query_all_by_value("9").next().is_some());+ let frame = h.state().ui.crop_rect;+ let save = |h: &mut Harness, name: &str| {+ if let Some(dir) = std::env::var_os("CRAFT_UI_VISUAL_FIXTURES") {+ let dir = std::path::PathBuf::from(dir);+ std::fs::create_dir_all(&dir).unwrap();+ h.render().unwrap().save(dir.join(name)).unwrap();+ }+ };+ save(&mut h, "crop-clear-before.png");+ h.query_all_by_label("Clear").min_by(|a, b| a.rect().top().total_cmp(&b.rect().top())).expect("Crop options bar Clear").click();+ h.run_steps(3);+ save(&mut h, "crop-clear-after.png");+ let o = &h.state().ui.tool_options;+ assert!(o.crop_ratio.is_empty());+ assert_eq!((o.crop_custom_ratio_width, o.crop_custom_ratio_height), (0.0, 0.0));+ assert!(h.query_all_by_value("16").next().is_none());+ assert!(h.query_all_by_value("9").next().is_none());+ assert_eq!(h.state().ui.crop_rect, frame);+}