From bba45115faf376a782b8ae73af54f32011eec686 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Tue, 27 Oct 2026 23:47:05 +0000 Subject: [PATCH] Refactor UI dialogs for strict Clippy checks --- .../src/dialogs/adjust_editors/basic.rs | 5 +- .../src/dialogs/adjust_editors/curves.rs | 5 +- .../dialogs/adjust_editors/gradient_map.rs | 5 +- .../dialogs/adjust_editors/hue_saturation.rs | 5 +- .../src/dialogs/adjust_editors/levels.rs | 2 +- .../src/dialogs/adjust_editors/session.rs | 2 +- crates/ui-egui/src/dialogs/caf_ui/controls.rs | 2 +- .../ui-egui/src/dialogs/caf_ui/lifecycle.rs | 2 +- crates/ui-egui/src/dialogs/caf_ui/preview.rs | 2 +- crates/ui-egui/src/dialogs/caf_ui/view.rs | 95 ++++++++------- crates/ui-egui/src/dialogs/camera_raw_ui.rs | 1 + .../src/dialogs/camera_raw_ui/controls.rs | 5 +- .../src/dialogs/camera_raw_ui/convert.rs | 2 +- .../ui-egui/src/dialogs/camera_raw_ui/menu.rs | 2 +- .../ui-egui/src/dialogs/camera_raw_ui/open.rs | 2 +- .../src/dialogs/camera_raw_ui/proxy.rs | 2 +- .../src/dialogs/camera_raw_ui/sidecar.rs | 2 +- crates/ui-egui/src/dialogs/file_ui/print.rs | 2 +- crates/ui-egui/src/dialogs/file_ui/web.rs | 2 +- .../src/dialogs/file_ui/web_preview.rs | 2 +- crates/ui-egui/src/dialogs/gallery_ui.rs | 2 +- crates/ui-egui/src/dialogs/liquify_ui.rs | 110 ++++++++++-------- 22 files changed, 151 insertions(+), 108 deletions(-) diff --git a/crates/ui-egui/src/dialogs/adjust_editors/basic.rs b/crates/ui-egui/src/dialogs/adjust_editors/basic.rs index 00b940cdbd..18c740ab80 100644 --- a/crates/ui-egui/src/dialogs/adjust_editors/basic.rs +++ b/crates/ui-egui/src/dialogs/adjust_editors/basic.rs @@ -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: diff --git a/crates/ui-egui/src/dialogs/adjust_editors/curves.rs b/crates/ui-egui/src/dialogs/adjust_editors/curves.rs index 7a3f4ea510..4b1867e83b 100644 --- a/crates/ui-egui/src/dialogs/adjust_editors/curves.rs +++ b/crates/ui-egui/src/dialogs/adjust_editors/curves.rs @@ -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 diff --git a/crates/ui-egui/src/dialogs/adjust_editors/gradient_map.rs b/crates/ui-egui/src/dialogs/adjust_editors/gradient_map.rs index 99750230f1..74dc454bb7 100644 --- a/crates/ui-egui/src/dialogs/adjust_editors/gradient_map.rs +++ b/crates/ui-egui/src/dialogs/adjust_editors/gradient_map.rs @@ -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 diff --git a/crates/ui-egui/src/dialogs/adjust_editors/hue_saturation.rs b/crates/ui-egui/src/dialogs/adjust_editors/hue_saturation.rs index 042f398619..b1c61947fa 100644 --- a/crates/ui-egui/src/dialogs/adjust_editors/hue_saturation.rs +++ b/crates/ui-egui/src/dialogs/adjust_editors/hue_saturation.rs @@ -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 diff --git a/crates/ui-egui/src/dialogs/adjust_editors/levels.rs b/crates/ui-egui/src/dialogs/adjust_editors/levels.rs index 8963e438e2..f1eac2a075 100644 --- a/crates/ui-egui/src/dialogs/adjust_editors/levels.rs +++ b/crates/ui-egui/src/dialogs/adjust_editors/levels.rs @@ -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 diff --git a/crates/ui-egui/src/dialogs/adjust_editors/session.rs b/crates/ui-egui/src/dialogs/adjust_editors/session.rs index bb3eeeebbc..12eb73b470 100644 --- a/crates/ui-egui/src/dialogs/adjust_editors/session.rs +++ b/crates/ui-egui/src/dialogs/adjust_editors/session.rs @@ -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 { diff --git a/crates/ui-egui/src/dialogs/caf_ui/controls.rs b/crates/ui-egui/src/dialogs/caf_ui/controls.rs index f01d4d6852..edb3087d00 100644 --- a/crates/ui-egui/src/dialogs/caf_ui/controls.rs +++ b/crates/ui-egui/src/dialogs/caf_ui/controls.rs @@ -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 { diff --git a/crates/ui-egui/src/dialogs/caf_ui/lifecycle.rs b/crates/ui-egui/src/dialogs/caf_ui/lifecycle.rs index 5bc21da079..fc3cb922f1 100644 --- a/crates/ui-egui/src/dialogs/caf_ui/lifecycle.rs +++ b/crates/ui-egui/src/dialogs/caf_ui/lifecycle.rs @@ -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> { diff --git a/crates/ui-egui/src/dialogs/caf_ui/preview.rs b/crates/ui-egui/src/dialogs/caf_ui/preview.rs index 628893bf1b..cf17506e3d 100644 --- a/crates/ui-egui/src/dialogs/caf_ui/preview.rs +++ b/crates/ui-egui/src/dialogs/caf_ui/preview.rs @@ -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`. diff --git a/crates/ui-egui/src/dialogs/caf_ui/view.rs b/crates/ui-egui/src/dialogs/caf_ui/view.rs index f9987ff822..b40e1f8ed2 100644 --- a/crates/ui-egui/src/dialogs/caf_ui/view.rs +++ b/crates/ui-egui/src/dialogs/caf_ui/view.rs @@ -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, 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())); diff --git a/crates/ui-egui/src/dialogs/camera_raw_ui.rs b/crates/ui-egui/src/dialogs/camera_raw_ui.rs index e920b95da8..1b71ef3306 100644 --- a/crates/ui-egui/src/dialogs/camera_raw_ui.rs +++ b/crates/ui-egui/src/dialogs/camera_raw_ui.rs @@ -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}; diff --git a/crates/ui-egui/src/dialogs/camera_raw_ui/controls.rs b/crates/ui-egui/src/dialogs/camera_raw_ui/controls.rs index 8af538511d..389af64d96 100644 --- a/crates/ui-egui/src/dialogs/camera_raw_ui/controls.rs +++ b/crates/ui-egui/src/dialogs/camera_raw_ui/controls.rs @@ -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; diff --git a/crates/ui-egui/src/dialogs/camera_raw_ui/convert.rs b/crates/ui-egui/src/dialogs/camera_raw_ui/convert.rs index 873db1a826..908f01e1f1 100644 --- a/crates/ui-egui/src/dialogs/camera_raw_ui/convert.rs +++ b/crates/ui-egui/src/dialogs/camera_raw_ui/convert.rs @@ -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. diff --git a/crates/ui-egui/src/dialogs/camera_raw_ui/menu.rs b/crates/ui-egui/src/dialogs/camera_raw_ui/menu.rs index 91b938e14c..ead69eba2b 100644 --- a/crates/ui-egui/src/dialogs/camera_raw_ui/menu.rs +++ b/crates/ui-egui/src/dialogs/camera_raw_ui/menu.rs @@ -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> { diff --git a/crates/ui-egui/src/dialogs/camera_raw_ui/open.rs b/crates/ui-egui/src/dialogs/camera_raw_ui/open.rs index 429e245eb0..87e1035a85 100644 --- a/crates/ui-egui/src/dialogs/camera_raw_ui/open.rs +++ b/crates/ui-egui/src/dialogs/camera_raw_ui/open.rs @@ -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). diff --git a/crates/ui-egui/src/dialogs/camera_raw_ui/proxy.rs b/crates/ui-egui/src/dialogs/camera_raw_ui/proxy.rs index 93e00960b0..46a82b140f 100644 --- a/crates/ui-egui/src/dialogs/camera_raw_ui/proxy.rs +++ b/crates/ui-egui/src/dialogs/camera_raw_ui/proxy.rs @@ -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 { diff --git a/crates/ui-egui/src/dialogs/camera_raw_ui/sidecar.rs b/crates/ui-egui/src/dialogs/camera_raw_ui/sidecar.rs index 1b5b6c9a3d..dfb03a13b9 100644 --- a/crates/ui-egui/src/dialogs/camera_raw_ui/sidecar.rs +++ b/crates/ui-egui/src/dialogs/camera_raw_ui/sidecar.rs @@ -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 { diff --git a/crates/ui-egui/src/dialogs/file_ui/print.rs b/crates/ui-egui/src/dialogs/file_ui/print.rs index 0a596a307b..c077259f92 100644 --- a/crates/ui-egui/src/dialogs/file_ui/print.rs +++ b/crates/ui-egui/src/dialogs/file_ui/print.rs @@ -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. diff --git a/crates/ui-egui/src/dialogs/file_ui/web.rs b/crates/ui-egui/src/dialogs/file_ui/web.rs index a2d45fa2f3..a370da2003 100644 --- a/crates/ui-egui/src/dialogs/file_ui/web.rs +++ b/crates/ui-egui/src/dialogs/file_ui/web.rs @@ -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")]; diff --git a/crates/ui-egui/src/dialogs/file_ui/web_preview.rs b/crates/ui-egui/src/dialogs/file_ui/web_preview.rs index 44399b7d52..ef2a6a5475 100644 --- a/crates/ui-egui/src/dialogs/file_ui/web_preview.rs +++ b/crates/ui-egui/src/dialogs/file_ui/web_preview.rs @@ -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> { diff --git a/crates/ui-egui/src/dialogs/gallery_ui.rs b/crates/ui-egui/src/dialogs/gallery_ui.rs index d37eec865d..2f2269b892 100644 --- a/crates/ui-egui/src/dialogs/gallery_ui.rs +++ b/crates/ui-egui/src/dialogs/gallery_ui.rs @@ -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(); } diff --git a/crates/ui-egui/src/dialogs/liquify_ui.rs b/crates/ui-egui/src/dialogs/liquify_ui.rs index 5d4da05bff..29536064a5 100644 --- a/crates/ui-egui/src/dialogs/liquify_ui.rs +++ b/crates/ui-egui/src/dialogs/liquify_ui.rs @@ -885,6 +885,68 @@ fn backdrop_layering(backdrop: Option, 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)]),