Refactor UI application for strict Clippy checks

This commit is contained in:
Dylan M. Taylor committed 2026-10-27 23:47:05 +00:00
1 parent eb6c1abf75
commit ef065ee66e
15 files changed
+124 -92

No files matched your search

+9 -1
View File
@@ -1,5 +1,13 @@
use super::services::{ExportSettings, FormatChoices, SAVE_OPTIONS_OPEN, SaveKind, Services, plain_raster, saved_revision_after_write};
use super::*;
use super::{
ControlRequest, DocId, Document, HashMap, PhotocraftApp, Receiver, Session, SyntheticTarget, Tool, UiState, Value, actions, analysis_ui, brush_panel,
brush_picker, camera_raw_ui, canvas, dds_options_ui, delete_layer_prompt, dialogs, discard_ui, distort_ui, dock, field_wheel, file_open, gpu_canvas,
gpu_status, gradient_ui, histogram_panel, i18n, jobs_ui, jpeg_options_ui, json, kys_import, last_brush, layers_panel_ui, mask_thumbs_ui, mask_trash_prompt,
monitor_status, native_menu, notices, open_prompt, paint_mouse, palette, panel_docking, panels, prefs_ui, preset_files_ui, preset_panels, rasterize_prompt,
screen_picker, shape_stroke_ui, shortcuts, single_line_drag, state, stroke_trace, stylus, targa_options_ui, text_field_menu, theme, tiff_options_ui,
timeline_ui, titlebar, tool_cursor, tool_memory, transform_tool, type_panels_ui, type_tool, type_transform, updates_ui, vector_ui, view_cmds, wheel_nav,
wide_angle_ui, widgets, work_area, workspace_ui,
};
mod clipboard;
mod commands;
+1 -1
View File
@@ -1,4 +1,4 @@
use super::*;
use super::PhotocraftApp;
fn clip_signature(w: u32, h: u32, px: &[u8]) -> u64 {
let mut sig = (w as u64) << 32 | h as u64;
+92 -77
View File
@@ -1,4 +1,7 @@
use super::*;
use super::{
DocId, PhotocraftApp, Tool, Value, actions, canvas, delete_layer_prompt, dock, gpu_canvas, jobs_ui, json, mask_trash_prompt, notices, panel_docking, state,
transform_tool, type_transform, vector_ui,
};
impl PhotocraftApp {
/// Run an engine command, reporting errors in the status bar.
@@ -115,82 +118,7 @@ impl PhotocraftApp {
jobs_ui::run(self, id, params)
};
let creates_adjustment_or_fill = id.starts_with("layer.newAdjustmentLayer.") || id.starts_with("layer.newFillLayer.");
if r.is_ok() && ADDS_LAYER_MASK.contains(&id) {
// Adding an explicit mask targets it, as in Photoshop (#2166).
self.ui.mask_target = true;
self.ui.vector_mask_target = false;
self.ui.properties_layer = None;
} else if r.is_ok() && creates_adjustment_or_fill {
// Panel Options may suppress a fill layer's default mask. Never target a
// nonexistent mask; an active path creates a vector mask instead.
let masks = self
.session
.active()
.and_then(|st| st.active_layer.and_then(|id| st.doc.layer(id)))
.map(|layer| (layer.mask.is_some(), layer.vector_mask.is_some()))
.unwrap_or((false, false));
self.ui.mask_target = masks.0;
self.ui.vector_mask_target = !masks.0 && masks.1;
// Keep Properties on the new layer contents, as on main (#3369).
self.ui.properties_layer = self.session.active().and_then(|st| st.active_layer).map(|l| l.0);
}
if r.is_ok() && creates_adjustment_or_fill {
// Properties comes to the front, shown and expanded, so the new layer's settings can
// be edited at once, as in Photoshop (#4028). The layer is made whatever happens here.
if self.ui.docking.is_some() {
let _ = panel_docking::command(self, "window.panel.activate", &json!({"panel": "properties"}));
} else {
self.ui.dock_tabs.properties = 0;
dock::reveal(self, dock::Group::Properties);
}
}
// Making a new selection reveals its outline after View > Extras was hidden (#5597).
// These interactive selection commands complete inline; a failed command, deselection,
// or painting inside an existing selection must leave the user's view choice alone.
if r.as_ref().is_ok_and(|v| v.get("changed") != Some(&Value::Bool(false)) && v.get("pending") != Some(&Value::Bool(true)))
&& matches!(
id,
"select.rect"
| "select.lasso"
| "select.magneticLasso"
| "select.magicWand"
| "select.quick"
| "select.object"
| "select.loadSelection"
| "select.loadLuminosity"
| "path.toSelection"
)
&& self.session.active().is_some_and(|st| st.doc.selection.is_some())
{
self.ui.view.extras = true;
}
if r.is_ok() && id == "select.toWorkPath" {
// Make Work Path selects the new work path in the Paths panel, as in Photoshop.
self.ui.selected_path = Some("work".into());
}
if r.is_ok() && path_mask {
// The new layer's vector mask becomes the active path, as in Photoshop: the path it
// was made from is no longer selected, so the next fill layer isn't masked by it too.
self.ui.selected_path = Some("layer".into());
}
if r.is_ok() && creates_active_mask {
// Adding a mask selects its thumbnail: the next brush or footer Delete targets it.
self.ui.mask_target = true;
self.ui.vector_mask_target = false;
}
if r.is_ok() && creates_active_vector_mask {
// Likewise a new vector mask (#4728): Properties shows its Density and Feather, and a
// mask made from a path becomes the active path.
self.ui.vector_mask_target = true;
self.ui.mask_target = false;
if matches!(id, "layer.vectorMask.currentPath" | "layer.vectorMask.fromPath") {
self.ui.selected_path = Some("layer".into());
}
}
if r.is_ok() && matches!(id, "edit.copy" | "edit.cut" | "edit.copyMerged") {
self.clip_external = false;
self.export_os_clipboard();
}
self.sync_command_side_effects(id, &r, creates_active_mask, creates_active_vector_mask, creates_adjustment_or_fill, path_mask);
self.perf.last_command = id.to_string();
self.perf.command_ms = gpu_canvas::now_ms() - t0;
match &r {
@@ -227,6 +155,93 @@ impl PhotocraftApp {
self.tool_override.unwrap_or(self.ui.tool)
}
fn sync_command_side_effects(
&mut self,
id: &str,
result: &Result<Value, String>,
creates_active_mask: bool,
creates_active_vector_mask: bool,
creates_adjustment_or_fill: bool,
path_mask: bool,
) {
if result.is_ok() && ADDS_LAYER_MASK.contains(&id) {
// Adding an explicit mask targets it, as in Photoshop (#2166).
self.ui.mask_target = true;
self.ui.vector_mask_target = false;
self.ui.properties_layer = None;
} else if result.is_ok() && creates_adjustment_or_fill {
// Panel Options may suppress a fill layer's default mask. Never target a
// nonexistent mask; an active path creates a vector mask instead.
let masks = self
.session
.active()
.and_then(|st| st.active_layer.and_then(|id| st.doc.layer(id)))
.map(|layer| (layer.mask.is_some(), layer.vector_mask.is_some()))
.unwrap_or((false, false));
self.ui.mask_target = masks.0;
self.ui.vector_mask_target = !masks.0 && masks.1;
// Keep Properties on the new layer contents, as on main (#3369).
self.ui.properties_layer = self.session.active().and_then(|st| st.active_layer).map(|l| l.0);
}
if result.is_ok() && creates_adjustment_or_fill {
// Properties comes to the front, shown and expanded, so the new layer's settings can
// be edited at once, as in Photoshop (#4028). The layer is made whatever happens here.
if self.ui.docking.is_some() {
let _ = panel_docking::command(self, "window.panel.activate", &json!({"panel": "properties"}));
} else {
self.ui.dock_tabs.properties = 0;
dock::reveal(self, dock::Group::Properties);
}
}
// Making a new selection reveals its outline after View > Extras was hidden (#5597).
// These interactive selection commands complete inline; a failed command, deselection,
// or painting inside an existing selection must leave the user's view choice alone.
if result.as_ref().is_ok_and(|v| v.get("changed") != Some(&Value::Bool(false)) && v.get("pending") != Some(&Value::Bool(true)))
&& matches!(
id,
"select.rect"
| "select.lasso"
| "select.magneticLasso"
| "select.magicWand"
| "select.quick"
| "select.object"
| "select.loadSelection"
| "select.loadLuminosity"
| "path.toSelection"
)
&& self.session.active().is_some_and(|st| st.doc.selection.is_some())
{
self.ui.view.extras = true;
}
if result.is_ok() && id == "select.toWorkPath" {
// Make Work Path selects the new work path in the Paths panel, as in Photoshop.
self.ui.selected_path = Some("work".into());
}
if result.is_ok() && path_mask {
// The new layer's vector mask becomes the active path, as in Photoshop: the path it
// was made from is no longer selected, so the next fill layer isn't masked by it too.
self.ui.selected_path = Some("layer".into());
}
if result.is_ok() && creates_active_mask {
// Adding a mask selects its thumbnail: the next brush or footer Delete targets it.
self.ui.mask_target = true;
self.ui.vector_mask_target = false;
}
if result.is_ok() && creates_active_vector_mask {
// Likewise a new vector mask (#4728): Properties shows its Density and Feather, and a
// mask made from a path becomes the active path.
self.ui.vector_mask_target = true;
self.ui.mask_target = false;
if matches!(id, "layer.vectorMask.currentPath" | "layer.vectorMask.fromPath") {
self.ui.selected_path = Some("layer".into());
}
}
if result.is_ok() && matches!(id, "edit.copy" | "edit.cut" | "edit.copyMerged") {
self.clip_external = false;
self.export_os_clipboard();
}
}
pub fn sync_views(&mut self) {
type_transform::cancel_stale(self);
crate::cam_transform::cancel_stale(self);
+1 -1
View File
@@ -1,4 +1,4 @@
use super::*;
use super::{ControlRequest, PhotocraftApp, Receiver};
impl PhotocraftApp {
/// Attach a control channel (requests arrive from a transport thread: TCP, stdin, tests).
+4 -1
View File
@@ -1,4 +1,7 @@
use super::*;
use super::{
DocId, ExportSettings, FormatChoices, PhotocraftApp, SAVE_OPTIONS_OPEN, SaveKind, Value, camera_raw_ui, dds_options_ui, file_open, jobs_ui,
jpeg_options_ui, json, notices, open_prompt, plain_raster, preset_files_ui, saved_revision_after_write, targa_options_ui, tiff_options_ui,
};
impl PhotocraftApp {
/// Record `path` as the most-recently-opened file (File › Open Recent): de-duplicated, newest
+8 -2
View File
@@ -1,4 +1,10 @@
use super::*;
use super::{
PhotocraftApp, analysis_ui, brush_panel, brush_picker, camera_raw_ui, canvas, dds_options_ui, dialogs, discard_ui, distort_ui, field_wheel, file_open,
gpu_canvas, gpu_status, gradient_ui, i18n, jobs_ui, jpeg_options_ui, kys_import, last_brush, layers_panel_ui, monitor_status, native_menu, notices,
paint_mouse, palette, panels, prefs_ui, preset_panels, rasterize_prompt, screen_picker, shape_stroke_ui, shortcuts, targa_options_ui, text_field_menu,
theme, tiff_options_ui, timeline_ui, titlebar, tool_cursor, tool_memory, transform_tool, type_panels_ui, type_tool, updates_ui, vector_ui, view_cmds,
wide_angle_ui, work_area, workspace_ui,
};
impl PhotocraftApp {
/// Wait out the rest of [`Self::min_frame_ms`] since the last frame started.
@@ -74,7 +80,7 @@ impl PhotocraftApp {
if !screen_picker::tick(self, ctx) {
jobs_ui::tick(self, ctx);
#[cfg(not(target_arch = "wasm32"))]
filter_preview_worker::discard_closed(self);
crate::dialogs::filter_preview_worker::discard_closed(self);
if type_tool::in_ui_pass(ctx) {
if self.fonts_ready {
shortcuts::handle(self, ctx);
+1 -1
View File
@@ -1,4 +1,4 @@
use super::*;
use super::{PhotocraftApp, gpu_canvas, gpu_status};
impl PhotocraftApp {
/// Draw the document canvas on the GPU (custom WGSL shader) instead of via egui textures.
+1 -1
View File
@@ -1,4 +1,4 @@
use super::*;
use super::{PhotocraftApp, type_tool};
impl PhotocraftApp {
/// Install the callback-mode markers in an app creator, before the first `run_ui` on this
+1 -1
View File
@@ -1,4 +1,4 @@
use super::*;
use super::{PhotocraftApp, SyntheticTarget};
/// Remove one contiguous run equal to `batch` from `events` (eframe's preserved synthetic
/// input). A no-op when the run is not present.
+1 -1
View File
@@ -1,4 +1,4 @@
use super::*;
use super::{PhotocraftApp, dock, panel_docking, single_line_drag, text_field_menu, theme, tool_cursor, wheel_nav};
impl PhotocraftApp {
/// Records a picked type family for the font menu's Recent group, capped by
+1 -1
View File
@@ -1,4 +1,4 @@
use super::*;
use super::PhotocraftApp;
impl PhotocraftApp {
/// Issue due screenshot requests. UI phase only: settling counts real layout passes, and the
+1 -1
View File
@@ -1,4 +1,4 @@
use super::*;
use super::{PhotocraftApp, Value, mask_thumbs_ui};
/// The active layer is an adjustment layer. It has no pixels, so painting and filling it edit its
/// mask even when its icon thumbnail, not the mask, is the Layers panel's target, as in
+1 -1
View File
@@ -1,4 +1,4 @@
use super::*;
use super::{DocId, Document, PhotocraftApp, mask_thumbs_ui};
impl PhotocraftApp {
pub(super) fn prune_thumbs(&mut self) {
+1 -1
View File
@@ -1,4 +1,4 @@
use super::*;
use super::PhotocraftApp;
impl PhotocraftApp {
/// Zoom of the active document's main view: screen (device) pixels per document pixel, the
+1 -1
View File
@@ -1,4 +1,4 @@
use super::*;
use super::PhotocraftApp;
impl PhotocraftApp {
/// Whether the title bar's free gap gets the drag overlay this frame: the app draws its title