From dccf6182eb2780a3489c327f8b208cdcd7ff0d85 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Tue, 27 Oct 2026 23:47:05 +0000 Subject: [PATCH] Refactor UI support for strict Clippy checks --- crates/ui-egui/src/control/dispatch.rs | 2 +- crates/ui-egui/src/control/params.rs | 2 +- crates/ui-egui/src/i18n/tests.rs | 8 + crates/ui-egui/src/lib.rs | 5 +- .../ui-egui/src/prefs/prefs_ui/appearance.rs | 2 +- crates/ui-egui/src/prefs/prefs_ui/dialogs.rs | 2 +- crates/ui-egui/src/prefs/prefs_ui/fields.rs | 2 +- crates/ui-egui/src/prefs/prefs_ui/graphics.rs | 2 +- crates/ui-egui/src/prefs/prefs_ui/save.rs | 2 +- .../ui-egui/src/prefs/prefs_ui/shortcuts.rs | 2 +- crates/ui-egui/src/prefs/prefs_ui/startup.rs | 2 +- crates/ui-egui/src/screenshot_tests.rs | 243 ++++++++++-------- crates/ui-egui/src/services.rs | 5 +- crates/ui-egui/src/state.rs | 8 + crates/ui-egui/src/state/color_panel.rs | 2 +- crates/ui-egui/src/state/panel_state.rs | 2 +- crates/ui-egui/src/state/tool.rs | 2 +- crates/ui-egui/src/state/tool_options.rs | 2 +- crates/ui-egui/src/state/transform.rs | 2 +- crates/ui-egui/src/theme.rs | 225 +++++++++++++--- crates/ui-egui/src/widgets/angle_dial.rs | 3 +- crates/ui-egui/src/widgets/buttons.rs | 2 +- crates/ui-egui/src/widgets/color.rs | 2 +- crates/ui-egui/src/widgets/color_count.rs | 3 +- crates/ui-egui/src/widgets/dropdown.rs | 2 +- crates/ui-egui/src/widgets/fields.rs | 2 +- crates/ui-egui/src/widgets/panel.rs | 2 +- crates/ui-egui/src/widgets/scrub.rs | 2 +- crates/ui-egui/src/widgets/slider.rs | 2 +- crates/ui-egui/src/widgets/text_field.rs | 2 +- crates/ui-egui/src/widgets/units.rs | 2 +- 31 files changed, 374 insertions(+), 172 deletions(-) diff --git a/crates/ui-egui/src/control/dispatch.rs b/crates/ui-egui/src/control/dispatch.rs index 7057d35f55..f7b87f6e9c 100644 --- a/crates/ui-egui/src/control/dispatch.rs +++ b/crates/ui-egui/src/control/dispatch.rs @@ -3,7 +3,7 @@ use super::params::{ BUTTONS, KEY_MODIFIERS, MAX_CLICKS, POINTER_MODIFIERS, UI_SET_FIELDS, bool_field, err, f32_field, f32_range, input_choice, input_modifiers, input_number, input_object, merged_object, modifiers_from, num_field, ok, screen_point, uint_field, whole_object, }; -use super::*; +use super::{ControlRequest, DialogKind, Outcome, PhotocraftApp, SHELL_DIALOG, Tool, ToolEvent, Value, json, run_waiting, tool_event, wrap}; pub(super) fn dispatch(app: &mut PhotocraftApp, ctx: &egui::Context, req: &ControlRequest) -> Outcome { let p = &req.params; diff --git a/crates/ui-egui/src/control/params.rs b/crates/ui-egui/src/control/params.rs index 0d9fbd6a49..b2d8668ecb 100644 --- a/crates/ui-egui/src/control/params.rs +++ b/crates/ui-egui/src/control/params.rs @@ -1,4 +1,4 @@ -use super::*; +use super::{Outcome, PhotocraftApp, Value, json}; /// The fields `ui.set` reads. Anything else is rejected before a field is applied, and every /// field's value is validated before the first one is applied, so a typo, an unknown field, a diff --git a/crates/ui-egui/src/i18n/tests.rs b/crates/ui-egui/src/i18n/tests.rs index cca640fbba..a8497bb5ec 100644 --- a/crates/ui-egui/src/i18n/tests.rs +++ b/crates/ui-egui/src/i18n/tests.rs @@ -54,6 +54,11 @@ fn picker_lists_english_first_then_names_alphabetically() { #[test] fn tags_map_to_languages() { + western_and_legacy_tags_resolve(); + chinese_tags_resolve_by_region_and_script(); +} + +fn western_and_legacy_tags_resolve() { assert_eq!(lang_from_tag("ja_JP.UTF-8"), Some(JA())); assert_eq!(lang_from_tag("ja-JP"), Some(JA())); assert_eq!(lang_from_tag("en_US.UTF-8"), Some(Lang::EN)); @@ -73,6 +78,9 @@ fn tags_map_to_languages() { assert_eq!(lang_from_tag("tr_TR.UTF-8"), Lang::from_code("tr")); assert_eq!(lang_from_tag("tr-TR"), Lang::from_code("tr")); assert_eq!(lang_from_tag("tr"), Lang::from_code("tr")); +} + +fn chinese_tags_resolve_by_region_and_script() { // Traditional Chinese: by region, by script, and with a region after the script. assert_eq!(lang_from_tag("zh_TW.UTF-8"), Some(ZH())); assert_eq!(lang_from_tag("zh-TW"), Some(ZH())); diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs index 190d9e5603..a1954b3d49 100644 --- a/crates/ui-egui/src/lib.rs +++ b/crates/ui-egui/src/lib.rs @@ -127,9 +127,8 @@ pub use dialogs::export_dialog; pub use dialogs::file_ui; pub use dialogs::fill_ui; pub use dialogs::filter_dialog; -use dialogs::filter_preview_ui; #[cfg(not(target_arch = "wasm32"))] -use dialogs::filter_preview_worker; +use dialogs::filter_preview_ui; pub use dialogs::gallery_ui; pub use dialogs::guide_layout_ui; pub use dialogs::history_options_ui; @@ -473,7 +472,7 @@ pub struct PhotocraftApp { pub(crate) filter_preview: Option, pub(crate) smart_filter_targets: smart_filter_dialog::Targets, #[cfg(not(target_arch = "wasm32"))] - filter_preview_worker: filter_preview_worker::Worker, + filter_preview_worker: crate::dialogs::filter_preview_worker::Worker, /// Full CPU canvas redraws running in the background, by document (#4024). pub(crate) redraws: std::collections::HashMap, /// The last finished background redraws, for going back to a state drawn a moment ago (#6528). diff --git a/crates/ui-egui/src/prefs/prefs_ui/appearance.rs b/crates/ui-egui/src/prefs/prefs_ui/appearance.rs index bf08302397..87405f606e 100644 --- a/crates/ui-egui/src/prefs/prefs_ui/appearance.rs +++ b/crates/ui-egui/src/prefs/prefs_ui/appearance.rs @@ -1,6 +1,6 @@ use super::dialogs::open_preferences; use super::fields::{choice_label, color_of, preference_matches}; -use super::*; +use super::{AppearanceMode, Color32, DarkTheme, LightTheme, Map, PhotocraftApp, RichText, SavedTheme, Sense, ThemeKind, Tokens, Value, json, prefs, vec2}; /// The GPU canvas colours from Preferences › Transparency & Gamut. pub fn canvas_style(app: &PhotocraftApp) -> crate::gpu_canvas::CanvasStyle { diff --git a/crates/ui-egui/src/prefs/prefs_ui/dialogs.rs b/crates/ui-egui/src/prefs/prefs_ui/dialogs.rs index 8a1b298100..c1519b48d9 100644 --- a/crates/ui-egui/src/prefs/prefs_ui/dialogs.rs +++ b/crates/ui-egui/src/prefs/prefs_ui/dialogs.rs @@ -1,5 +1,5 @@ use super::shortcuts::shortcut_items; -use super::*; +use super::{BTreeMap, DialogKind, Map, PhotocraftApp, RichText, SECTIONS, Tokens, Value, json, prefs}; // ------------------------------------------------------------------ menu routing diff --git a/crates/ui-egui/src/prefs/prefs_ui/fields.rs b/crates/ui-egui/src/prefs/prefs_ui/fields.rs index cd1c867521..2258a3f7be 100644 --- a/crates/ui-egui/src/prefs/prefs_ui/fields.rs +++ b/crates/ui-egui/src/prefs/prefs_ui/fields.rs @@ -2,7 +2,7 @@ use super::appearance::{AppearanceRows, appearance_rows, system_theme}; use super::dialogs::{mismatch_body, presets_body, presets_io_body, settings_height}; use super::graphics::{gpu_memory_lines, gpu_status_rows, memory_usage_row, read_at_launch, rendering_mode_row}; use super::shortcuts::shortcuts_body; -use super::*; +use super::{Color32, Map, PhotocraftApp, RichText, SECTIONS, Sense, Tokens, Value, json, prefs, vec2}; // ------------------------------------------------------------------ bodies diff --git a/crates/ui-egui/src/prefs/prefs_ui/graphics.rs b/crates/ui-egui/src/prefs/prefs_ui/graphics.rs index 63930425ea..166f5ed299 100644 --- a/crates/ui-egui/src/prefs/prefs_ui/graphics.rs +++ b/crates/ui-egui/src/prefs/prefs_ui/graphics.rs @@ -1,5 +1,5 @@ use super::fields::choice_label; -use super::*; +use super::{Map, PhotocraftApp, RichText, Tokens, Value, json, prefs}; /// Performance › Graphics: the compositor's GPU memory budget and whether the active document's /// layers fit it (the GPU Memory preference sets it). diff --git a/crates/ui-egui/src/prefs/prefs_ui/save.rs b/crates/ui-egui/src/prefs/prefs_ui/save.rs index 78408b5e1f..9dba6f78f2 100644 --- a/crates/ui-egui/src/prefs/prefs_ui/save.rs +++ b/crates/ui-egui/src/prefs/prefs_ui/save.rs @@ -1,6 +1,6 @@ use super::appearance::{canvas_style, sync_animations, sync_appearance, sync_display_scale, sync_tooltips}; use super::startup::{load, presets_store, recovery, sync_rulers}; -use super::*; +use super::{DocId, HashMap, PhotocraftApp, Value, prefs}; /// Per-frame upkeep: theme sync, persistence, autosave and the history log. pub fn tick(app: &mut PhotocraftApp, ctx: &egui::Context) { diff --git a/crates/ui-egui/src/prefs/prefs_ui/shortcuts.rs b/crates/ui-egui/src/prefs/prefs_ui/shortcuts.rs index 73b7d475d9..3c0bf1d4a4 100644 --- a/crates/ui-egui/src/prefs/prefs_ui/shortcuts.rs +++ b/crates/ui-egui/src/prefs/prefs_ui/shortcuts.rs @@ -1,5 +1,5 @@ use super::dialogs::toolbar_tab; -use super::*; +use super::{BTreeMap, Map, PhotocraftApp, RichText, Tokens, Value, default_shortcut, json, prefs, vec2}; /// Every shortcut-bearing command (engine registry plus shell commands): (id, label, menu path, /// default shortcut), menu items first in Photoshop order. diff --git a/crates/ui-egui/src/prefs/prefs_ui/startup.rs b/crates/ui-egui/src/prefs/prefs_ui/startup.rs index 30da36a2a3..1d4005f17a 100644 --- a/crates/ui-egui/src/prefs/prefs_ui/startup.rs +++ b/crates/ui-egui/src/prefs/prefs_ui/startup.rs @@ -1,4 +1,4 @@ -use super::*; +use super::{JobEvent, JobOutcome, PhotocraftApp, Started, Value, json, prefs}; /// View › Rulers follows `unitsAndRulers.showRulers` when the preference changes (at launch, from /// `prefs.set` or a reset), so documents open with the rulers as last set. diff --git a/crates/ui-egui/src/screenshot_tests.rs b/crates/ui-egui/src/screenshot_tests.rs index 4d23b0607b..9771548b59 100644 --- a/crates/ui-egui/src/screenshot_tests.rs +++ b/crates/ui-egui/src/screenshot_tests.rs @@ -509,114 +509,151 @@ fn actual_callback(output: &egui::FullOutput) -> Option)>>>; +type ScreenshotEncodes = std::rc::Rc)>>>; + +struct ActualCallbackFixture { + app: crate::PhotocraftApp, + ctx: Context, + writes: ScreenshotWrites, + encodes: ScreenshotEncodes, + reply: std::sync::mpsc::Receiver, + document: Option, + old_geometry: CaptureGeometry, + old_pixels: std::sync::Weak, +} + +fn actual_callback_fixture() -> ActualCallbackFixture { use std::cell::RefCell; use std::rc::Rc; - // Unchanged success, resize, DPI change, and minimized are separate real app instances. + + let writes = Rc::new(RefCell::new(Vec::new())); + let encodes = Rc::new(RefCell::new(Vec::new())); + let (written, encoded) = (writes.clone(), encodes.clone()); + let services = crate::Services { + automation_write: Some(Box::new(move |path, bytes| { + written.borrow_mut().push((path.to_owned(), bytes.to_vec())); + Ok(()) + })), + encode_png: Some(Box::new(move |w, h, rgba| { + encoded.borrow_mut().push((w, h, rgba.get(..4).unwrap_or_default().to_vec())); + let image = photocraft_codecs::Image::from_u8(w, h, photocraft_codecs::ChannelLayout::Rgba, rgba.to_vec()).map_err(|error| error.to_string())?; + photocraft_codecs::encode(&image, photocraft_codecs::Format::Png, &photocraft_codecs::EncodeOptions::default()).map_err(|error| error.to_string()) + })), + ..Default::default() + }; + let mut app = crate::PhotocraftApp::new(photocraft_engine::Session::new(), services); + app.run("file.new", serde_json::json!({"width": 32, "height": 32})).unwrap(); + let ctx = Context::default(); + for _ in 0..4 { + actual_capture_frame(&mut app, &ctx, vec2(600.0, 400.0), 1.0, false); + } + let old_geometry = app.captures.last_geometry().expect("the old real UI geometry"); + let document = app.document_identity(); + let (tx, reply) = std::sync::mpsc::channel(); + app.captures.admit(91, Some("fixture/current.png".into()), tx, document, 0.0, super::screenshot::now()).unwrap(); + let mut callback = None; + for _ in 0..8 { + let output = actual_capture_frame(&mut app, &ctx, vec2(600.0, 400.0), 1.0, false); + if let Some(found) = actual_callback(&output) { + callback = Some(found); + break; + } + } + let old_image = Arc::new(ColorImage::filled(old_geometry.expected_pixels().unwrap(), Color32::RED)); + let old_pixels = Arc::downgrade(&old_image); + callback.expect("actual app issued one screenshot callback").complete(old_image); + assert!(writes.borrow().is_empty() && encodes.borrow().is_empty(), "the real callback only stores pixels"); + ActualCallbackFixture { app, ctx, writes, encodes, reply, document, old_geometry, old_pixels } +} + +#[test] +fn completed_callback_revalidates_next_raw_input_before_actual_app_writes() { for (size, scale, minimized) in [(vec2(600.0, 400.0), 1.0, false), (vec2(640.0, 400.0), 1.0, false), (vec2(600.0, 400.0), 2.0, false), (vec2(600.0, 400.0), 1.0, true)] { - let changed = size != vec2(600.0, 400.0) || scale != 1.0 || minimized; - let writes = Rc::new(RefCell::new(Vec::new())); - let encodes = Rc::new(RefCell::new(Vec::new())); - let (written, encoded) = (writes.clone(), encodes.clone()); - let services = crate::Services { - automation_write: Some(Box::new(move |path, bytes| { - written.borrow_mut().push((path.to_owned(), bytes.to_vec())); - Ok(()) - })), - encode_png: Some(Box::new(move |w, h, rgba| { - encoded.borrow_mut().push((w, h, rgba.get(..4).unwrap_or_default().to_vec())); - let image = - photocraft_codecs::Image::from_u8(w, h, photocraft_codecs::ChannelLayout::Rgba, rgba.to_vec()).map_err(|error| error.to_string())?; - photocraft_codecs::encode(&image, photocraft_codecs::Format::Png, &photocraft_codecs::EncodeOptions::default()) - .map_err(|error| error.to_string()) - })), - ..Default::default() - }; - let mut app = crate::PhotocraftApp::new(photocraft_engine::Session::new(), services); - app.run("file.new", serde_json::json!({"width": 32, "height": 32})).unwrap(); - let ctx = Context::default(); - for _ in 0..4 { - actual_capture_frame(&mut app, &ctx, vec2(600.0, 400.0), 1.0, false); + let mut fixture = actual_callback_fixture(); + if size == vec2(600.0, 400.0) && scale == 1.0 && !minimized { + verify_unchanged_capture(&mut fixture); + } else { + verify_changed_capture(&mut fixture, size, scale, minimized); } - let old = app.captures.last_geometry().expect("the old real UI geometry"); - let document = app.document_identity(); - let (tx, rx) = std::sync::mpsc::channel(); - app.captures.admit(91, Some("fixture/current.png".into()), tx, document, 0.0, super::screenshot::now()).unwrap(); - let mut callback = None; - for _ in 0..8 { - let output = actual_capture_frame(&mut app, &ctx, vec2(600.0, 400.0), 1.0, false); - if let Some(found) = actual_callback(&output) { - callback = Some(found); - break; - } - } - let old_image = Arc::new(ColorImage::filled(old.expected_pixels().unwrap(), Color32::RED)); - let old_pixels = Arc::downgrade(&old_image); - callback.expect("actual app issued one screenshot callback").complete(old_image); - assert!(writes.borrow().is_empty() && encodes.borrow().is_empty(), "the real callback only stores pixels"); - let output = actual_capture_frame(&mut app, &ctx, size, scale, minimized); - if changed { - assert!(writes.borrow().is_empty() && encodes.borrow().is_empty(), "no stale encode/write on the first changed input"); - assert!(old_pixels.upgrade().is_none(), "old pixels are released on geometry rejection"); - let current = app.captures.last_geometry().unwrap(); - assert!(current.logical_size != old.logical_size || current.pixels_per_point != old.pixels_per_point || current.minimized != old.minimized); - if minimized { - // A minimized surface cannot be retried. It fails once, then an independent - // request after restoration proves that cancellation releases its budget. - let reply = rx.try_recv().expect("one minimized error"); - assert_eq!(reply["ok"], false, "{reply}"); - assert!(reply["error"].as_str().unwrap().contains("minimized")); - assert_eq!(app.captures.pending(), 0); - assert_eq!(app.captures.reserved_bytes(), 0); - assert!(actual_callback(&output).is_none()); - actual_capture_frame(&mut app, &ctx, size, scale, false); - let (tx, restored_rx) = std::sync::mpsc::channel(); - app.captures.admit(92, Some("fixture/restored.png".into()), tx, document, 0.0, super::screenshot::now()).unwrap(); - for _ in 0..8 { - let output = actual_capture_frame(&mut app, &ctx, size, scale, false); - if let Some(callback) = actual_callback(&output) { - callback.complete(Arc::new(ColorImage::filled(app.captures.last_geometry().unwrap().expected_pixels().unwrap(), Color32::BLUE))); - break; - } - } - actual_capture_frame(&mut app, &ctx, size, scale, false); - let reply = restored_rx.try_recv().expect("the restored window accepts a new request"); - assert_eq!(reply["ok"], true, "{reply}"); - assert_eq!(writes.borrow().len(), 1); - assert!(writes.borrow()[0].1.starts_with(b"\x89PNG\r\n\x1a\n")); - assert_eq!(encodes.borrow().len(), 1); - assert_eq!(encodes.borrow()[0].2, [0, 0, 255, 255]); - assert_eq!(app.captures.pending(), 0); - assert_eq!(app.captures.reserved_bytes(), 0); - assert!(rx.try_recv().is_err() && restored_rx.try_recv().is_err()); - continue; - } - assert!(rx.try_recv().is_err(), "bounded retry has not delivered a stale success"); - let mut retry = actual_callback(&output); - for _ in 0..8 { - if retry.is_some() { - break; - } - retry = actual_callback(&actual_capture_frame(&mut app, &ctx, size, scale, minimized)); - } - retry - .expect("the actual app reissues at bounded current geometry") - .complete(Arc::new(ColorImage::filled(current.expected_pixels().unwrap(), Color32::BLUE))); - actual_capture_frame(&mut app, &ctx, size, scale, minimized); - assert_eq!(encodes.borrow().first().map(|entry| entry.2.as_slice()), Some([0, 0, 255, 255].as_slice()), "only the new callback image is encoded"); - } - let reply = rx.try_recv().expect("one response after the valid callback"); - assert_eq!(reply["ok"], true, "{reply}"); - assert_eq!(writes.borrow().len(), 1); - assert!(writes.borrow()[0].1.starts_with(b"\x89PNG\r\n\x1a\n"), "real PNG encoding and automation_write ran"); - assert_eq!(encodes.borrow().len(), 1); - assert_eq!(app.captures.pending(), 0); - assert_eq!(app.captures.reserved_bytes(), 0); - actual_capture_frame(&mut app, &ctx, size, scale, minimized); - assert_eq!(writes.borrow().len(), 1, "no duplicate output"); - assert!(rx.try_recv().is_err()); } } + +fn verify_unchanged_capture(fixture: &mut ActualCallbackFixture) { + actual_capture_frame(&mut fixture.app, &fixture.ctx, vec2(600.0, 400.0), 1.0, false); + assert_successful_capture(fixture, vec2(600.0, 400.0), 1.0, false); +} + +fn verify_changed_capture(fixture: &mut ActualCallbackFixture, size: egui::Vec2, scale: f32, minimized: bool) { + let output = actual_capture_frame(&mut fixture.app, &fixture.ctx, size, scale, minimized); + assert!(fixture.writes.borrow().is_empty() && fixture.encodes.borrow().is_empty(), "no stale encode/write on the first changed input"); + assert!(fixture.old_pixels.upgrade().is_none(), "old pixels are released on geometry rejection"); + let current = fixture.app.captures.last_geometry().unwrap(); + assert!( + current.logical_size != fixture.old_geometry.logical_size + || current.pixels_per_point != fixture.old_geometry.pixels_per_point + || current.minimized != fixture.old_geometry.minimized + ); + if minimized { + verify_minimized_capture(fixture, size, scale, &output); + return; + } + assert!(fixture.reply.try_recv().is_err(), "bounded retry has not delivered a stale success"); + let mut retry = actual_callback(&output); + for _ in 0..8 { + if retry.is_some() { + break; + } + retry = actual_callback(&actual_capture_frame(&mut fixture.app, &fixture.ctx, size, scale, minimized)); + } + retry + .expect("the actual app reissues at bounded current geometry") + .complete(Arc::new(ColorImage::filled(current.expected_pixels().unwrap(), Color32::BLUE))); + actual_capture_frame(&mut fixture.app, &fixture.ctx, size, scale, minimized); + assert_eq!(fixture.encodes.borrow().first().map(|entry| entry.2.as_slice()), Some([0, 0, 255, 255].as_slice()), "only the new callback image is encoded"); + assert_successful_capture(fixture, size, scale, minimized); +} + +fn verify_minimized_capture(fixture: &mut ActualCallbackFixture, size: egui::Vec2, scale: f32, output: &egui::FullOutput) { + let reply = fixture.reply.try_recv().expect("one minimized error"); + assert_eq!(reply["ok"], false, "{reply}"); + assert!(reply["error"].as_str().unwrap().contains("minimized")); + assert_eq!(fixture.app.captures.pending(), 0); + assert_eq!(fixture.app.captures.reserved_bytes(), 0); + assert!(actual_callback(output).is_none()); + actual_capture_frame(&mut fixture.app, &fixture.ctx, size, scale, false); + let (tx, restored_rx) = std::sync::mpsc::channel(); + fixture.app.captures.admit(92, Some("fixture/restored.png".into()), tx, fixture.document, 0.0, super::screenshot::now()).unwrap(); + for _ in 0..8 { + let output = actual_capture_frame(&mut fixture.app, &fixture.ctx, size, scale, false); + if let Some(callback) = actual_callback(&output) { + callback.complete(Arc::new(ColorImage::filled(fixture.app.captures.last_geometry().unwrap().expected_pixels().unwrap(), Color32::BLUE))); + break; + } + } + actual_capture_frame(&mut fixture.app, &fixture.ctx, size, scale, false); + let reply = restored_rx.try_recv().expect("the restored window accepts a new request"); + assert_eq!(reply["ok"], true, "{reply}"); + assert_eq!(fixture.writes.borrow().len(), 1); + assert!(fixture.writes.borrow()[0].1.starts_with(b"\x89PNG\r\n\x1a\n")); + assert_eq!(fixture.encodes.borrow().len(), 1); + assert_eq!(fixture.encodes.borrow()[0].2, [0, 0, 255, 255]); + assert_eq!(fixture.app.captures.pending(), 0); + assert_eq!(fixture.app.captures.reserved_bytes(), 0); + assert!(fixture.reply.try_recv().is_err() && restored_rx.try_recv().is_err()); +} + +fn assert_successful_capture(fixture: &mut ActualCallbackFixture, size: egui::Vec2, scale: f32, minimized: bool) { + let reply = fixture.reply.try_recv().expect("one response after the valid callback"); + assert_eq!(reply["ok"], true, "{reply}"); + assert_eq!(fixture.writes.borrow().len(), 1); + assert!(fixture.writes.borrow()[0].1.starts_with(b"\x89PNG\r\n\x1a\n"), "real PNG encoding and automation_write ran"); + assert_eq!(fixture.encodes.borrow().len(), 1); + assert_eq!(fixture.app.captures.pending(), 0); + assert_eq!(fixture.app.captures.reserved_bytes(), 0); + actual_capture_frame(&mut fixture.app, &fixture.ctx, size, scale, minimized); + assert_eq!(fixture.writes.borrow().len(), 1, "no duplicate output"); + assert!(fixture.reply.try_recv().is_err()); +} diff --git a/crates/ui-egui/src/services.rs b/crates/ui-egui/src/services.rs index d330884a0a..53d3c2e7f0 100644 --- a/crates/ui-egui/src/services.rs +++ b/crates/ui-egui/src/services.rs @@ -1,4 +1,7 @@ -use super::*; +use super::{ + CaptionStyle, Document, FileDialogFn, OsEvent, Value, dds_options_ui, jobs_ui, jpeg_options_ui, monitor_status, native_menu, screen_picker, + targa_options_ui, +}; /// The error a save gets while another save waits on its format prompt. pub(crate) const SAVE_OPTIONS_OPEN: &str = "Answer the TIFF, Targa, DDS or JPEG Options before starting another save"; diff --git a/crates/ui-egui/src/state.rs b/crates/ui-egui/src/state.rs index 8fb058524a..eac69a2263 100644 --- a/crates/ui-egui/src/state.rs +++ b/crates/ui-egui/src/state.rs @@ -657,6 +657,11 @@ mod tests { #[test] fn tool_names_parse() { + basic_and_retouch_tool_names_parse(); + vector_tool_names_parse(); + } + + fn basic_and_retouch_tool_names_parse() { assert_eq!(Tool::from_name("brush"), Some(Tool::Brush)); assert_eq!(Tool::from_name("Rect"), Some(Tool::RectMarquee)); assert_eq!(Tool::from_name("RectMarquee"), Some(Tool::RectMarquee)); @@ -675,6 +680,9 @@ mod tests { assert_eq!(Tool::from_name("patternStamp"), Some(Tool::PatternStamp)); assert_eq!(Tool::from_name("Pattern Stamp Tool"), Some(Tool::PatternStamp)); assert_eq!(Tool::ALL.len(), 68); + } + + fn vector_tool_names_parse() { assert_eq!(Tool::from_name("Vertical Type Mask Tool"), Some(Tool::VerticalTypeMask)); assert_eq!(Tool::from_name("addAnchorPoint"), Some(Tool::AddAnchorPoint)); assert_eq!(Tool::from_name("Delete Anchor Point Tool"), Some(Tool::DeleteAnchorPoint)); diff --git a/crates/ui-egui/src/state/color_panel.rs b/crates/ui-egui/src/state/color_panel.rs index 4b1ac89ee8..29dfebc471 100644 --- a/crates/ui-egui/src/state/color_panel.rs +++ b/crates/ui-egui/src/state/color_panel.rs @@ -1,4 +1,4 @@ -use super::*; +use super::{Deserialize, Serialize}; /// Selected tab per dock card. #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)] diff --git a/crates/ui-egui/src/state/panel_state.rs b/crates/ui-egui/src/state/panel_state.rs index 4cc2d67184..387f6ce915 100644 --- a/crates/ui-egui/src/state/panel_state.rs +++ b/crates/ui-egui/src/state/panel_state.rs @@ -1,4 +1,4 @@ -use super::*; +use super::{Deserialize, Serialize}; /// Photoshop-style Layers panel display preferences; part of serialized UI state. #[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize, Default)] diff --git a/crates/ui-egui/src/state/tool.rs b/crates/ui-egui/src/state/tool.rs index 2b6702f317..cd96f525a1 100644 --- a/crates/ui-egui/src/state/tool.rs +++ b/crates/ui-egui/src/state/tool.rs @@ -1,4 +1,4 @@ -use super::*; +use super::{Deserialize, Serialize}; #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)] pub enum Tool { diff --git a/crates/ui-egui/src/state/tool_options.rs b/crates/ui-egui/src/state/tool_options.rs index 6855ddeb12..8b8bad1630 100644 --- a/crates/ui-egui/src/state/tool_options.rs +++ b/crates/ui-egui/src/state/tool_options.rs @@ -1,5 +1,5 @@ use super::tool::Tool; -use super::*; +use super::{Deserialize, Serialize}; /// Options-bar state for tools (Photoshop keeps these per tool). #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] diff --git a/crates/ui-egui/src/state/transform.rs b/crates/ui-egui/src/state/transform.rs index ed14318721..5eb2064f0d 100644 --- a/crates/ui-egui/src/state/transform.rs +++ b/crates/ui-egui/src/state/transform.rs @@ -1,4 +1,4 @@ -use super::*; +use super::{Deserialize, Serialize}; /// Edit › Transform's mode: what a handle drag does with no modifier keys held. #[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)] diff --git a/crates/ui-egui/src/theme.rs b/crates/ui-egui/src/theme.rs index 822d79e148..88672fe75c 100644 --- a/crates/ui-egui/src/theme.rs +++ b/crates/ui-egui/src/theme.rs @@ -1180,52 +1180,197 @@ pub mod live { let mut unknown = Vec::new(); let Some(obj) = v.as_object() else { return unknown }; for (k, val) in obj { - macro_rules! c { - ($($f:ident),*) => { - match k.as_str() { - $(stringify!($f) => { if let Some(c) = color(val) { t.$f = c; } })* - "radius_sm" => { if let Some(x) = val.as_f64() { t.radius_sm = x as f32; } } - "radius" => { if let Some(x) = val.as_f64() { t.radius = x as f32; } } - "radius_lg" => { if let Some(x) = val.as_f64() { t.radius_lg = x as f32; } } - _ => unknown.push(k.clone()), + if override_chrome_color(t, k, val) || override_text_color(t, k, val) || override_accent_color(t, k, val) { + continue; + } + match k.as_str() { + "radius_sm" => { + if let Some(x) = val.as_f64() { + t.radius_sm = x as f32; } - }; + } + "radius" => { + if let Some(x) = val.as_f64() { + t.radius = x as f32; + } + } + "radius_lg" => { + if let Some(x) = val.as_f64() { + t.radius_lg = x as f32; + } + } + _ => unknown.push(k.clone()), } - c!( - caption_close, - caption_close_text, - chrome, - canvas, - canvas_dot, - dock, - card, - card_border, - field, - field_border, - hover, - pressed, - text, - text_dim, - text_faint, - icon, - accent, - accent_soft, - accent_border, - accent_text, - separator, - shadow, - primary_bg, - primary_text, - danger, - warning, - tab_strip, - row_selected, - scrim - ); } unknown } + fn override_chrome_color(t: &mut Tokens, key: &str, value: &serde_json::Value) -> bool { + match key { + "caption_close" => { + if let Some(c) = color(value) { + t.caption_close = c; + } + } + "caption_close_text" => { + if let Some(c) = color(value) { + t.caption_close_text = c; + } + } + "chrome" => { + if let Some(c) = color(value) { + t.chrome = c; + } + } + "canvas" => { + if let Some(c) = color(value) { + t.canvas = c; + } + } + "canvas_dot" => { + if let Some(c) = color(value) { + t.canvas_dot = c; + } + } + "dock" => { + if let Some(c) = color(value) { + t.dock = c; + } + } + "card" => { + if let Some(c) = color(value) { + t.card = c; + } + } + "card_border" => { + if let Some(c) = color(value) { + t.card_border = c; + } + } + "field" => { + if let Some(c) = color(value) { + t.field = c; + } + } + "field_border" => { + if let Some(c) = color(value) { + t.field_border = c; + } + } + _ => return false, + } + true + } + + fn override_text_color(t: &mut Tokens, key: &str, value: &serde_json::Value) -> bool { + match key { + "hover" => { + if let Some(c) = color(value) { + t.hover = c; + } + } + "pressed" => { + if let Some(c) = color(value) { + t.pressed = c; + } + } + "text" => { + if let Some(c) = color(value) { + t.text = c; + } + } + "text_dim" => { + if let Some(c) = color(value) { + t.text_dim = c; + } + } + "text_faint" => { + if let Some(c) = color(value) { + t.text_faint = c; + } + } + "icon" => { + if let Some(c) = color(value) { + t.icon = c; + } + } + "separator" => { + if let Some(c) = color(value) { + t.separator = c; + } + } + "shadow" => { + if let Some(c) = color(value) { + t.shadow = c; + } + } + "primary_bg" => { + if let Some(c) = color(value) { + t.primary_bg = c; + } + } + "primary_text" => { + if let Some(c) = color(value) { + t.primary_text = c; + } + } + _ => return false, + } + true + } + + fn override_accent_color(t: &mut Tokens, key: &str, value: &serde_json::Value) -> bool { + match key { + "accent" => { + if let Some(c) = color(value) { + t.accent = c; + } + } + "accent_soft" => { + if let Some(c) = color(value) { + t.accent_soft = c; + } + } + "accent_border" => { + if let Some(c) = color(value) { + t.accent_border = c; + } + } + "accent_text" => { + if let Some(c) = color(value) { + t.accent_text = c; + } + } + "danger" => { + if let Some(c) = color(value) { + t.danger = c; + } + } + "warning" => { + if let Some(c) = color(value) { + t.warning = c; + } + } + "tab_strip" => { + if let Some(c) = color(value) { + t.tab_strip = c; + } + } + "row_selected" => { + if let Some(c) = color(value) { + t.row_selected = c; + } + } + "scrim" => { + if let Some(c) = color(value) { + t.scrim = c; + } + } + _ => return false, + } + true + } + #[cfg(test)] mod tests { use super::*; diff --git a/crates/ui-egui/src/widgets/angle_dial.rs b/crates/ui-egui/src/widgets/angle_dial.rs index 7a6c82f6b1..a21b453ded 100644 --- a/crates/ui-egui/src/widgets/angle_dial.rs +++ b/crates/ui-egui/src/widgets/angle_dial.rs @@ -2,7 +2,7 @@ //! Drop Shadow's light (#882), Motion Blur and the other direction angles of the filter //! dialogs (#3152) share it, as Photoshop's dialogs do. -use super::*; +use super::{Response, Sense, Stroke, Tokens, Ui, value_field, vec2}; /// `Label (dial) [field°]` for a direction in document angles: counter-clockwise from three /// o'clock, y up. The dial points anywhere in -180..=180; the result is clamped to `range`, and @@ -61,6 +61,7 @@ pub fn angle_dial_row(ui: &mut Ui, label: &str, angle: &mut f32, range: std::ops #[cfg(test)] mod tests { use super::*; + use egui::Vec2; use egui_kittest::kittest::Queryable; fn click(h: &mut egui_kittest::Harness<'_, f32>, delta: Vec2) { diff --git a/crates/ui-egui/src/widgets/buttons.rs b/crates/ui-egui/src/widgets/buttons.rs index c6ac810d23..41ad5509bc 100644 --- a/crates/ui-egui/src/widgets/buttons.rs +++ b/crates/ui-egui/src/widgets/buttons.rs @@ -1,5 +1,5 @@ use super::panel::surface; -use super::*; +use super::{Color32, Rect, Response, Sense, Stroke, StrokeKind, Tokens, Ui, Vec2, pos2, theme, vec2}; /// iOS-style toggle switch. pub fn toggle(ui: &mut Ui, on: &mut bool, label: &str) -> Response { diff --git a/crates/ui-egui/src/widgets/color.rs b/crates/ui-egui/src/widgets/color.rs index 0c71e0746a..e246afcded 100644 --- a/crates/ui-egui/src/widgets/color.rs +++ b/crates/ui-egui/src/widgets/color.rs @@ -1,5 +1,5 @@ use super::dropdown::swatch_popup; -use super::*; +use super::{Color32, CornerRadius, Pos2, Rect, Response, Sense, Stroke, StrokeKind, Tokens, Ui, Vec2, pos2}; /// Cached RGB data; drawing work is bounded by the 256 display bins, never the image size. pub fn rgb_histogram(ui: &mut Ui, histogram: &photocraft_algo::histogram::RgbHistogram, height: f32) -> egui::Response { diff --git a/crates/ui-egui/src/widgets/color_count.rs b/crates/ui-egui/src/widgets/color_count.rs index da65928ad7..03da8cf31f 100644 --- a/crates/ui-egui/src/widgets/color_count.rs +++ b/crates/ui-egui/src/widgets/color_count.rs @@ -1,6 +1,6 @@ //! Integer-only Indexed Color field and a linear slider with common palette sizes. -use super::*; +use super::{Align2, Color32, Rect, Response, Sense, Stroke, StrokeKind, Tokens, Ui, pos2, surface, theme, vec2}; const STOPS: [u32; 6] = [8, 16, 32, 64, 128, 256]; @@ -102,6 +102,7 @@ pub fn color_count_row(ui: &mut Ui, label: &str, count: &mut u32) -> Response { #[cfg(test)] mod tests { use super::*; + use egui::Pos2; use egui_kittest::{Harness, kittest::Queryable}; #[test] diff --git a/crates/ui-egui/src/widgets/dropdown.rs b/crates/ui-egui/src/widgets/dropdown.rs index f1ef01940a..6f83b0edd2 100644 --- a/crates/ui-egui/src/widgets/dropdown.rs +++ b/crates/ui-egui/src/widgets/dropdown.rs @@ -1,7 +1,7 @@ use super::panel::chevron_icon; use super::scrub::take_label_scrub_name; use super::slider::wheel_notches_of; -use super::*; +use super::{Pos2, Rect, Response, Ui, Vec2, type_ahead}; /// A compact labelled dropdown in the studio style. pub fn dropdown(ui: &mut Ui, id: &str, name: &str, current: &mut T, options: &[(T, &str)], width: f32) -> bool { diff --git a/crates/ui-egui/src/widgets/fields.rs b/crates/ui-egui/src/widgets/fields.rs index 143320e330..439662724e 100644 --- a/crates/ui-egui/src/widgets/fields.rs +++ b/crates/ui-egui/src/widgets/fields.rs @@ -3,7 +3,7 @@ use super::scrub::{label_scrub_response, take_label_scrub}; use super::slider::slider; use super::text_field::first_field_id; use super::units::{FieldUnits, field_resolution_id, fmt_num, fmt_num_prec, fmt_num2, parse_num_in, plain, unit_of_suffix}; -use super::*; +use super::{Align2, Color32, Rect, Response, Sense, Stroke, StrokeKind, Tokens, Ui, Vec2, pos2, theme, vec2}; /// Monospace numeric field with a dimmed unit suffix, Photoshop style. Drag to scrub. Typed /// arithmetic (`1920/2`) applies on Enter, Tab or click-away, and a unit after a number converts diff --git a/crates/ui-egui/src/widgets/panel.rs b/crates/ui-egui/src/widgets/panel.rs index 43c52b1cf4..7833edc2bc 100644 --- a/crates/ui-egui/src/widgets/panel.rs +++ b/crates/ui-egui/src/widgets/panel.rs @@ -1,4 +1,4 @@ -use super::*; +use super::{Color32, CornerRadius, Rect, Response, Sense, Stroke, StrokeKind, Tokens, Ui, pos2, theme, vec2}; /// Match the Spectrum application-menu padding and blue/white hover state in /// secondary menus (status bar, dock hamburger, layer context menus; #2187). diff --git a/crates/ui-egui/src/widgets/scrub.rs b/crates/ui-egui/src/widgets/scrub.rs index 45056106bb..8602af4e61 100644 --- a/crates/ui-egui/src/widgets/scrub.rs +++ b/crates/ui-egui/src/widgets/scrub.rs @@ -1,4 +1,4 @@ -use super::*; +use super::{Rect, Response, Sense, Ui}; /// A drag on a value field's label this frame, for the value field drawn next on the label's row /// (Photoshop's scrubby labels). Left by [`scrub_label`], taken by that field. diff --git a/crates/ui-egui/src/widgets/slider.rs b/crates/ui-egui/src/widgets/slider.rs index 49363da87e..c4112fecb5 100644 --- a/crates/ui-egui/src/widgets/slider.rs +++ b/crates/ui-egui/src/widgets/slider.rs @@ -1,7 +1,7 @@ use super::fields::{FieldOpts, value_field_in}; use super::panel::surface; use super::scrub::scrub_label_within; -use super::*; +use super::{Color32, Pos2, Rect, Response, Sense, Stroke, Tokens, Ui, Vec2, pos2, vec2}; /// Thin-track slider with a round knob. `gradient` paints the track (e.g. hue spectrum). pub fn slider(ui: &mut Ui, value: &mut f32, range: std::ops::RangeInclusive, gradient: Option<&[Color32]>) -> Response { diff --git a/crates/ui-egui/src/widgets/text_field.rs b/crates/ui-egui/src/widgets/text_field.rs index 3a009d3635..b377fbf098 100644 --- a/crates/ui-egui/src/widgets/text_field.rs +++ b/crates/ui-egui/src/widgets/text_field.rs @@ -1,5 +1,5 @@ use super::panel::surface; -use super::*; +use super::{Response, Sense, Stroke, StrokeKind, Tokens, Ui, Vec2, theme, vec2}; /// The most characters a [`text_field`] holds unless its caller sets a limit: far beyond any /// search, name or hex value, yet a pasted multi-gigabyte string is cut at the field instead of diff --git a/crates/ui-egui/src/widgets/units.rs b/crates/ui-egui/src/widgets/units.rs index 388dddf26c..c4ea21dbde 100644 --- a/crates/ui-egui/src/widgets/units.rs +++ b/crates/ui-egui/src/widgets/units.rs @@ -1,5 +1,5 @@ use super::fields::{FieldOpts, value_field_in}; -use super::*; +use super::{Response, Ui}; /// A size dialog's unit key (`px`, `in`, `cm`, `mm`, `pt`, `pica`, `percent`) as a unit. pub fn unit_of_key(key: &str) -> photocraft_engine::prefs::Unit {