Refactor UI dialogs for strict Clippy checks

This commit is contained in:
Dylan M. Taylor committed 2026-10-27 23:47:05 +00:00
1 parent 9366cd58ec
commit bba45115fa
22 files changed
+151 -108

No files matched your search

@@ -1,5 +1,8 @@
use super::hue_saturation::RANGE_LABELS;
use super::*;
use super::{
Color32, Edit, EditorCx, HUE_RANGES, PHOTO_FILTERS, RichText, Sense, Stroke, StrokeKind, Tokens, Value, adjust_params, color_button, flag, json, label,
num, nums, pos2, rgb_of, round, tone, vec2, widgets,
};
/// Labelled slider rows over top-level keys: (key, label, min, max, default, unit).
/// A row of [`sliders`]: params key, label, range, default, unit, and its decimal places (None:
@@ -1,4 +1,7 @@
use super::*;
use super::{
Color32, CurveUi, Edit, EditorCx, Pos2, Rect, RichText, Sense, Stroke, StrokeKind, Tokens, ToneSpace, Value, adjust_params, curve_edit, json, label, pos2,
space_of, tone, vec2, widgets,
};
// ---------------------------------------------------------------------------------------------
// Channels of Levels / Curves
@@ -1,5 +1,8 @@
use super::hue_saturation::spectrum_bar;
use super::*;
use super::{
Color32, Edit, EditorCx, GradientPreset, Group, PhotocraftApp, Pos2, Rect, RichText, Sense, Stroke, StrokeKind, Tokens, Value, adjust_params, color_button,
color32, flag, json, label, pos2, rgb_of, round, vec2, widgets,
};
// ---------------------------------------------------------------------------------------------
// Gradient Map
@@ -1,7 +1,10 @@
use super::basic::{sliders, track_stops};
use super::curves::gradient_bar;
use super::levels::nearest;
use super::*;
use super::{
Color32, Edit, EditorCx, HUE_RANGES, HueRange, Rect, RichText, Sense, Stroke, StrokeKind, Tokens, Value, color32, flag, hue_color, json, num, nums, pos2,
vec2, widgets,
};
// ---------------------------------------------------------------------------------------------
// Hue/Saturation
@@ -1,5 +1,5 @@
use super::curves::{ToneChannel, bar_color, channel_picker, gradient_bar, hist_color, tone_channels};
use super::*;
use super::{Color32, Edit, EditorCx, Sense, Stroke, StrokeKind, Tokens, Value, json, label, pos2, round, space_of, tone, vec2, widgets};
// ---------------------------------------------------------------------------------------------
// Levels
@@ -1,6 +1,6 @@
use super::basic::reset_color_balance;
use super::gradient_map::{gradient_presets, is_gray, swatches};
use super::*;
use super::{Adjustment, EditorCx, HistSource, LayerId, PhotocraftApp, RichText, Tokens, Value, adjust_params, editor, json, needs_histogram, space_of, tone};
/// Root of an adjustment layer's Properties editor view state in egui memory.
pub fn layer_mem(id: LayerId) -> egui::Id {
@@ -1,6 +1,6 @@
use super::lifecycle::{apply, cancel, close, fill_edit, redo, report, reset, set_sampling, undo};
use super::preview::{rebase, wait_preview};
use super::*;
use super::{CafTool, CafWorkspace, LASSO_OPS, PhotocraftApp, ToolEvent, Value, json};
/// Control channel: `edit.contentAwareFill {"ui": {...}}` while the workspace is open.
pub fn control(app: &mut PhotocraftApp, ui: &Value) -> Result<Value, String> {
@@ -1,5 +1,5 @@
use super::preview::{Base, Preview, cancel_preview, compute_base, plan_params, points_limit, rebase, refresh};
use super::*;
use super::{CMD, CafOpts, CafTool, CafWorkspace, MAX_CAF_EDITS, MAX_CAF_POINTS, PROXY_SIDE, PhotocraftApp, REMEMBERED, Rect, Step, Value};
/// Opens the workspace on the active layer and its selection.
pub fn open(app: &mut PhotocraftApp) -> Result<(), String> {
+1 -1
View File
@@ -1,4 +1,4 @@
use super::*;
use super::{CMD, CafWorkspace, Color32, LayerId, MAX_CAF_POINTS, MAX_OUTLINE_EDGES, PhotocraftApp, Rect, TextureHandle, Value, json, stroke_json};
/// What the plan (without the brush strokes) says: the window, the fill area and the sampling
/// option's area, over `rect`.
+52 -43
View File
@@ -1,7 +1,10 @@
use super::controls::{pointer, tool_icon, tool_tip};
use super::lifecycle::{apply, bounds, cancel, commit, fill_edit, report, reset, set_sampling};
use super::preview::{drive_preview, rebase, refresh};
use super::*;
use super::{
Align2, BAR_H, CafTool, CafWorkspace, Color32, ERect, FontId, LEFT_W, PANEL_W, PREVIEW_W, PhotocraftApp, Pos2, Rect, Sense, Stroke, Tokens, ToolEvent,
Value, json, pos2, vec2, widgets,
};
/// A view: screen px per document px and the document point at the centre of `area`.
#[derive(Clone, Copy)]
@@ -26,6 +29,52 @@ impl View {
}
/// Upload what changed: the document proxy, the overlay, a finished preview.
/// The options bar of the Content-Aware Fill workspace, for the active tool.
fn caf_options_bar(bui: &mut egui::Ui, w: &mut CafWorkspace, fill_btn: &mut Option<Value>, reset_what: &mut Option<&str>) {
match w.tool {
CafTool::Brush => {
if crate::icons::button(bui, "plus", 26.0, w.brush_add, tl!("Add")).clicked() {
w.brush_add = true;
}
if crate::icons::button(bui, "minus", 26.0, !w.brush_add, tl!("Subtract")).clicked() {
w.brush_add = false;
}
bui.add_space(8.0);
bui.label(tl!("Size:"));
let mut size = w.brush_size as f32;
if widgets::value_field(bui, &mut size, 1.0..=5000.0, " px", 64.0).accessible_name(tl!("Size:")).changed() {
w.brush_size = f64::from(size);
}
}
CafTool::Lasso => {
// The selection tools' mode buttons (the lasso here edits the fill area).
let tips = [
tl!("New selection").to_string(),
crate::i18n::fmt(tl!("Add to selection ({key})"), &[("key", &crate::shortcuts::pretty("Shift"))]),
crate::i18n::fmt(tl!("Subtract from selection ({key})"), &[("key", &crate::shortcuts::pretty("Alt"))]),
crate::i18n::fmt(tl!("Intersect with selection ({key})"), &[("key", &crate::shortcuts::pretty("Shift+Alt"))]),
];
for (i, (icon, tip)) in ["square", "plus", "minus", "squares-subtract"].into_iter().zip(tips.iter()).enumerate() {
if crate::icons::button(bui, icon, 26.0, w.lasso_op == i, tip).clicked() {
w.lasso_op = i;
}
}
bui.add_space(8.0);
if widgets::secondary_button(bui, tl!("Expand"), 70.0).clicked() {
*fill_btn = Some(json!({"op": "expand", "by": w.expand_by}));
}
if widgets::secondary_button(bui, tl!("Contract"), 70.0).clicked() {
*fill_btn = Some(json!({"op": "contract", "by": w.expand_by}));
}
widgets::value_field(bui, &mut w.expand_by, 1.0..=100.0, " px", 56.0).accessible_name(tl!("Expand"));
if crate::icons::button(bui, "undo-2", 26.0, false, tl!("Reset")).clicked() {
*reset_what = Some("lasso");
}
}
_ => {}
}
}
fn upload(app: &mut PhotocraftApp, ctx: &egui::Context) {
let need_image = app.distort.caf.as_ref().is_some_and(|w| w.image_tex.is_none());
if need_image {
@@ -108,48 +157,8 @@ pub fn show(app: &mut PhotocraftApp, ctx: &egui::Context) {
painter.line_segment([bar.left_bottom(), bar.right_bottom()], Stroke::new(1.0, t.separator));
let mut bui =
ui.new_child(egui::UiBuilder::new().max_rect(bar.shrink2(vec2(LEFT_W + 8.0, 4.0))).layout(egui::Layout::left_to_right(egui::Align::Center)));
match w.tool {
CafTool::Brush => {
if crate::icons::button(&mut bui, "plus", 26.0, w.brush_add, tl!("Add")).clicked() {
w.brush_add = true;
}
if crate::icons::button(&mut bui, "minus", 26.0, !w.brush_add, tl!("Subtract")).clicked() {
w.brush_add = false;
}
bui.add_space(8.0);
bui.label(tl!("Size:"));
let mut size = w.brush_size as f32;
if widgets::value_field(&mut bui, &mut size, 1.0..=5000.0, " px", 64.0).accessible_name(tl!("Size:")).changed() {
w.brush_size = f64::from(size);
}
}
CafTool::Lasso => {
// The selection tools' mode buttons (the lasso here edits the fill area).
let tips = [
tl!("New selection").to_string(),
crate::i18n::fmt(tl!("Add to selection ({key})"), &[("key", &crate::shortcuts::pretty("Shift"))]),
crate::i18n::fmt(tl!("Subtract from selection ({key})"), &[("key", &crate::shortcuts::pretty("Alt"))]),
crate::i18n::fmt(tl!("Intersect with selection ({key})"), &[("key", &crate::shortcuts::pretty("Shift+Alt"))]),
];
for (i, (icon, tip)) in ["square", "plus", "minus", "squares-subtract"].into_iter().zip(tips.iter()).enumerate() {
if crate::icons::button(&mut bui, icon, 26.0, w.lasso_op == i, tip).clicked() {
w.lasso_op = i;
}
}
bui.add_space(8.0);
if widgets::secondary_button(&mut bui, tl!("Expand"), 70.0).clicked() {
fill_btn = Some(json!({"op": "expand", "by": w.expand_by}));
}
if widgets::secondary_button(&mut bui, tl!("Contract"), 70.0).clicked() {
fill_btn = Some(json!({"op": "contract", "by": w.expand_by}));
}
widgets::value_field(&mut bui, &mut w.expand_by, 1.0..=100.0, " px", 56.0).accessible_name(tl!("Expand"));
if crate::icons::button(&mut bui, "undo-2", 26.0, false, tl!("Reset")).clicked() {
reset_what = Some("lasso");
}
}
_ => {}
}
caf_options_bar(&mut bui, w, &mut fill_btn, &mut reset_what);
let body = ERect::from_min_max(pos2(full.left(), bar.bottom()), full.max);
// Left tool strip.
let left = ERect::from_min_size(pos2(full.left(), title.bottom()), vec2(LEFT_W, full.height() - title.height()));
@@ -19,6 +19,7 @@ use photocraft_algo::camera_raw::{CameraRaw, Wheel, curve_lut};
use photocraft_algo::histogram::RgbHistogram;
use crate::camera_raw_scope_ui::{MAX_SAMPLERS, ToneZone};
use photocraft_doc::LayerId;
use photocraft_geom::Rect;
use serde_json::{Value, json};
@@ -1,6 +1,9 @@
use super::open::{Target, cancel, commit_open_raw, open_raw, raw_stage};
use super::sidecar::{load_settings, report_file_error, save_settings};
use super::*;
use super::{
Align2, BANDS, CameraRaw, CameraRawDialog, Color32, ERect, FontId, PANEL_W, PhotocraftApp, Pos2, Sense, Stroke, Tokens, ToneZone, Value, Wheel, curve_lut,
json, pos2, vec2, widgets,
};
const RAW_UNDO_LIMIT: usize = 40;
@@ -1,5 +1,5 @@
use super::open::{Coverage, Target};
use super::*;
use super::{CameraRaw, CameraRawDialog, LayerId, MAX_SAMPLERS, PROXY_SIDE, PhotocraftApp, Rect, RgbHistogram, Value, json};
/// Camera Raw Defaults › Sharpen For: output sharpening, folded into the Camera Raw step `rest`
/// as the workflow's Sharpen For is. Returns what it applied.
@@ -1,7 +1,7 @@
use super::controls::{commit, redo_edit, remember_edit, undo_edit};
use super::open::{cancel, open, open_smart_filter};
use super::sidecar::{load_settings, save_settings};
use super::*;
use super::{CameraRaw, LayerId, PhotocraftApp, Value, json};
/// Menu / control-channel entry point. `None` when the call isn't for this dialog.
pub fn menu(app: &mut PhotocraftApp, ctx: &egui::Context, id: &str, params: &Value) -> Option<Result<Value, String>> {
@@ -1,6 +1,6 @@
use super::convert::{apply_raw_conversions, open_pixels, output_sharpening, raw_conversions};
use super::sidecar::{read_sidecar, write_sidecar};
use super::*;
use super::{CameraRaw, LayerId, PhotocraftApp, Rect, Value, json};
/// Opens the dialog on the active layer.
/// Where OK writes: a new filter on the layer, or an existing smart filter (by index).
@@ -1,5 +1,5 @@
use super::open::raw_stage;
use super::*;
use super::{CameraRaw, CameraRawDialog, PARALLEL_MIN_PIXELS, RgbHistogram};
/// Everything one develop of the proxy reads, owned, so it can run off the UI thread.
pub(super) struct ProxyJob {
@@ -1,6 +1,6 @@
use super::controls::remember_edit;
use super::open::RawOpen;
use super::*;
use super::{CameraRaw, PhotocraftApp, Value, json};
/// The sidecar beside a raw file: `IMG_0001.xmp` for `IMG_0001.CR2`, as Camera Raw names it.
pub fn sidecar_path(path: &str) -> String {
+1 -1
View File
@@ -1,4 +1,4 @@
use super::*;
use super::{Arc, DialogKind, Map, PhotocraftApp, Tokens, Value, b, check, dropdown_str, json, n, number, params, s};
/// Print's Printer menu: the default printer (value ""), then every printer `file.printers`
/// listed. A saved name the spooler no longer lists stays selectable rather than vanishing.
+1 -1
View File
@@ -1,4 +1,4 @@
use super::*;
use super::{Arc, DialogKind, Map, PhotocraftApp, Tokens, Value, WebSettings, b, check, dropdown_str, json, n, number, params, s, web_cmds, web_preview};
const WEB_FORMATS: [(&str, &str); 5] = [("gif", "GIF"), ("png8", "PNG-8"), ("png24", "PNG-24"), ("jpeg", "JPEG"), ("wbmp", "WBMP")];
@@ -1,5 +1,5 @@
//! Save for Web navigation and indexed palette UI. Draft state is serialized in dialog fields.
use super::*;
use super::{Arc, Map, Optimized, PhotocraftApp, Tokens, Value, WebSettings, json, n, params, s, web_cmds};
/// Export dimensions, using the same percent/width/height precedence as web_document.
pub fn dimensions(doc: &photocraft_doc::Document, p: &Value) -> Result<(f64, f64), String> {
+1 -1
View File
@@ -582,7 +582,7 @@ fn poll_job(d: &mut GalleryDialog, ctx: &egui::Context) {
#[cfg(not(target_arch = "wasm32"))]
fn start_job(d: &mut GalleryDialog, ctx: &egui::Context, key: u64, vis: Rect, k: u32, params: &Value, now: f64) {
if let Some(job) = &d.job {
let settled = d.latest.is_some_and(|(k0, t)| k0 == key && now - t >= crate::filter_preview_worker::SETTLE_MS);
let settled = d.latest.is_some_and(|(k0, t)| k0 == key && now - t >= crate::dialogs::filter_preview_worker::SETTLE_MS);
if job.key != key && settled {
job.ctl.cancel();
}
+64 -46
View File
@@ -885,6 +885,68 @@ fn backdrop_layering<T: Copy>(backdrop: Option<T>, mode: BackdropMode, opacity:
}
/// Draws the dialog (a full-window layer over the app).
fn draw_tool_strip(ui: &mut egui::Ui, painter: &egui::Painter, t: &Tokens, d: &mut LiquifyDialog, body: ERect) -> ERect {
// Left tool strip.
let left = ERect::from_min_size(body.min, vec2(LEFT_W, body.height()));
painter.rect_filled(left, 0.0, t.dock);
painter.line_segment([left.right_top(), left.right_bottom()], Stroke::new(1.0, t.separator));
let mut strip = ui.new_child(egui::UiBuilder::new().max_rect(left.shrink2(vec2(6.0, 8.0))));
strip.spacing_mut().item_spacing.y = 4.0;
for tool in LiquifyTool::ALL {
let tip = match tool {
// The lasso works on the same freeze mask as Freeze/Thaw.
LiquifyTool::LassoMask => tl!("Freeze Lasso: drag to freeze an area, Alt-drag to thaw it (L)").to_string(),
_ => format!("{} ({})", tl!(tool.label()), shortcut(tool)),
};
if crate::icons::button(&mut strip, tool_icon(tool), 34.0, d.opts.tool == tool, &tip).clicked() {
d.opts.tool = tool;
}
if matches!(tool, LiquifyTool::Smooth | LiquifyTool::PushLeft | LiquifyTool::Thaw) {
strip.add_space(6.0);
}
}
left
}
/// The preview's wheel and trackpad input: zoom about the pointer, or pan.
fn apply_preview_wheel(
ctx: &egui::Context,
d: &mut LiquifyDialog,
area: ERect,
resp: &egui::Response,
wheel_id: egui::Id,
pinch_zooms: bool,
animated_zoom: bool,
) {
let wheel = crate::wheel_nav::read(ctx, true, pinch_zooms, animated_zoom, wheel_id, resp.hovered());
if let Some(hp) = resp.hover_pos() {
let zoom = match wheel {
Some(crate::wheel_nav::Wheel::Zoom(f)) => {
let z = d.zoom * f;
// At a limit, drop the rest of an eased notch, or it would swallow the first notch back.
if z != z.clamp(ZOOM_MIN, ZOOM_MAX) {
crate::wheel_nav::settle(ctx, wheel_id);
}
Some(z.clamp(ZOOM_MIN, ZOOM_MAX))
}
Some(crate::wheel_nav::Wheel::SnapZoom(n)) => {
Some((0..n.unsigned_abs()).fold(d.zoom, |z, _| crate::zoom_levels::step_in_range(z, n.signum(), ZOOM_MIN, ZOOM_MAX)))
}
Some(crate::wheel_nav::Wheel::Pan(v)) => {
d.center = [d.center[0] - f64::from(v.x / d.zoom), d.center[1] - f64::from(v.y / d.zoom)];
None
}
None => None,
};
if let Some(z) = zoom {
let before = to_doc(d, area, hp);
d.zoom = z;
let after = to_doc(d, area, hp);
d.center = [d.center[0] + before[0] - after[0], d.center[1] + before[1] - after[1]];
}
}
}
pub fn show(app: &mut PhotocraftApp, ctx: &egui::Context) {
let t = Tokens::get(ctx);
let screen = ctx.content_rect();
@@ -924,25 +986,7 @@ pub fn show(app: &mut PhotocraftApp, ctx: &egui::Context) {
t.text,
);
let body = ERect::from_min_max(pos2(full.left(), title.bottom()), full.max);
// Left tool strip.
let left = ERect::from_min_size(body.min, vec2(LEFT_W, body.height()));
painter.rect_filled(left, 0.0, t.dock);
painter.line_segment([left.right_top(), left.right_bottom()], Stroke::new(1.0, t.separator));
let mut strip = ui.new_child(egui::UiBuilder::new().max_rect(left.shrink2(vec2(6.0, 8.0))));
strip.spacing_mut().item_spacing.y = 4.0;
for tool in LiquifyTool::ALL {
let tip = match tool {
// The lasso works on the same freeze mask as Freeze/Thaw.
LiquifyTool::LassoMask => tl!("Freeze Lasso: drag to freeze an area, Alt-drag to thaw it (L)").to_string(),
_ => format!("{} ({})", tl!(tool.label()), shortcut(tool)),
};
if crate::icons::button(&mut strip, tool_icon(tool), 34.0, d.opts.tool == tool, &tip).clicked() {
d.opts.tool = tool;
}
if matches!(tool, LiquifyTool::Smooth | LiquifyTool::PushLeft | LiquifyTool::Thaw) {
strip.add_space(6.0);
}
}
let left = draw_tool_strip(ui, &painter, &t, d, body);
// Right properties panel.
let right = ERect::from_min_size(pos2(body.right() - RIGHT_W, body.top()), vec2(RIGHT_W, body.height()));
painter.rect_filled(right, 0.0, t.dock);
@@ -1047,33 +1091,7 @@ pub fn show(app: &mut PhotocraftApp, ctx: &egui::Context) {
// Preferences › Enhanced Controls › Zoom with Trackpad Pinch is off); a sideways scroll
// pans (#7210). Read every frame, as `wheel_nav` asks, so its modifier state follows.
let wheel_id = egui::Id::unique("liquify-preview-wheel");
let wheel = crate::wheel_nav::read(ctx, true, pinch_zooms, animated_zoom, wheel_id, resp.hovered());
if let Some(hp) = resp.hover_pos() {
let zoom = match wheel {
Some(crate::wheel_nav::Wheel::Zoom(f)) => {
let z = d.zoom * f;
// At a limit, drop the rest of an eased notch, or it would swallow the first notch back.
if z != z.clamp(ZOOM_MIN, ZOOM_MAX) {
crate::wheel_nav::settle(ctx, wheel_id);
}
Some(z.clamp(ZOOM_MIN, ZOOM_MAX))
}
Some(crate::wheel_nav::Wheel::SnapZoom(n)) => {
Some((0..n.unsigned_abs()).fold(d.zoom, |z, _| crate::zoom_levels::step_in_range(z, n.signum(), ZOOM_MIN, ZOOM_MAX)))
}
Some(crate::wheel_nav::Wheel::Pan(v)) => {
d.center = [d.center[0] - f64::from(v.x / d.zoom), d.center[1] - f64::from(v.y / d.zoom)];
None
}
None => None,
};
if let Some(z) = zoom {
let before = to_doc(d, area, hp);
d.zoom = z;
let after = to_doc(d, area, hp);
d.center = [d.center[0] + before[0] - after[0], d.center[1] + before[1] - after[1]];
}
}
apply_preview_wheel(ctx, d, area, &resp, wheel_id, pinch_zooms, animated_zoom);
d.update_view_preview(ctx, area);
let img = ERect::from_min_max(
to_screen(d, area, [f64::from(d.canvas.x0), f64::from(d.canvas.y0)]),