PhotoCraft: An open-source, photo editor written by scratch in pure Rust
Interface: wire Dynamic Color Sliders for the colour tracks (#204) (#2531)
Reynold Hu6bbfa77230b3
diff --git a/crates/engine/src/prefs.rs b/crates/engine/src/prefs.rsindex a4bbef608..c0c35bf52 100644--- a/crates/engine/src/prefs.rs+++ b/crates/engine/src/prefs.rs@@ -976,7 +976,6 @@ pub const HIDDEN_UNTIL_IMPLEMENTED: &[&str] = &["general.alwaysCreateSmartObjectsWhenPlacing","general.animatedZoom","general.zoomResizesWindows",- "interface.dynamicColorSliders","workspace.autoCollapseIconPanels","workspace.autoShowHiddenPanels","workspace.enableFloatingDocumentWindowDocking",diff --git a/crates/ui-egui/src/adjust_dialog.rs b/crates/ui-egui/src/adjust_dialog.rsindex e1b863ae9..a4b831ed2 100644--- a/crates/ui-egui/src/adjust_dialog.rs+++ b/crates/ui-egui/src/adjust_dialog.rs@@ -189,6 +189,7 @@ pub fn body(app: &mut PhotocraftApp, ui: &mut egui::Ui, fields: &mut Map<String,swatches: adjust_editors::swatches(app),gradients: adjust_editors::gradient_presets(app, &kind),dialog: true,+ dynamic_color_sliders: app.session.prefs().interface.dynamic_color_sliders,};let e = adjust_editors::editor(ui, &kind, &mut values, &cx);if e.changeddiff --git a/crates/ui-egui/src/adjust_editors.rs b/crates/ui-egui/src/adjust_editors.rsindex e202cef31..5ce9d1bd6 100644--- a/crates/ui-egui/src/adjust_editors.rs+++ b/crates/ui-egui/src/adjust_editors.rs@@ -86,6 +86,9 @@ pub struct EditorCx {/// Hosted by an Image › Adjustments dialog (false: the Properties panel). Photoshop's dialog/// sliders follow the mouse wheel; the panel's don't.pub dialog: bool,+ /// Preferences ▸ Interface ▸ Dynamic Color Sliders: colour tracks on the colour sliders+ /// (off: the plain track).+ pub dynamic_color_sliders: bool,}/// The Levels/Curves channel space the values address.@@ -120,7 +123,7 @@ pub fn editor(ui: &mut egui::Ui, kind: &str, v: &mut Value, cx: &EditorCx) -> Ed"vibrance" => sliders(ui, v, &[("vibrance", "Vibrance", -100.0, 100.0, 0.0, "%"), ("saturation", "Saturation", -100.0, 100.0, 0.0, "%")]),"hueSaturation" => hue_saturation(ui, v, cx),"colorBalance" => color_balance(ui, v, cx),- "blackWhite" => black_white(ui, v),+ "blackWhite" => black_white(ui, v, cx),"photoFilter" => photo_filter(ui, v, cx),"channelMixer" => channel_mixer(ui, v, cx),"posterize" => sliders(ui, v, &[("levels", "Levels", 2.0, 255.0, 4.0, "")]),@@ -200,11 +203,17 @@ fn sliders(ui: &mut egui::Ui, v: &mut Value, rows: &[(&str, &str, f32, f32, f32,e}-fn gradient_slider(ui: &mut egui::Ui, text: &str, x: &mut f32, range: std::ops::RangeInclusive<f32>, unit: &str, from: Color32, to: Color32) -> Edit {- let r = widgets::slider_row(ui, text, x, range, unit, Some(&[from, to]));+fn gradient_slider(ui: &mut egui::Ui, text: &str, x: &mut f32, range: std::ops::RangeInclusive<f32>, unit: &str, stops: [Color32; 2], dynamic: bool) -> Edit {+ let r = widgets::slider_row(ui, text, x, range, unit, dynamic.then_some(&stops));Edit::of(&r)}+/// Preferences ▸ Interface ▸ Dynamic Color Sliders: the colour track for a slider, or the plain+/// track when it is off.+fn track_stops<'a>(cx: &EditorCx, stops: &'a [Color32]) -> Option<&'a [Color32]> {+ cx.dynamic_color_sliders.then_some(stops)+}+// ---------------------------------------------------------------------------------------------// Brightness/Contrast@@ -763,7 +772,7 @@ fn hue_saturation(ui: &mut egui::Ui, v: &mut Value, cx: &EditorCx) -> Edit {if range == 0 {let (hlo, hhi, slo) = if colorize { (0.0, 360.0, 0.0) } else { (-180.0, 180.0, -100.0) };let mut h = num(v, "hue", 0.0).clamp(hlo, hhi);- let r = widgets::slider_row(ui, tl!("Hue"), &mut h, hlo..=hhi, "°", Some(&hue_grad));+ let r = widgets::slider_row(ui, tl!("Hue"), &mut h, hlo..=hhi, "°", track_stops(cx, &hue_grad));if r.changed() {v["hue"] = json!(h.round());}@@ -771,14 +780,14 @@ fn hue_saturation(ui: &mut egui::Ui, v: &mut Value, cx: &EditorCx) -> Edit {// The Saturation and Lightness tracks follow the current hue, as in Photoshop (UI-217-16).let sat_track = saturation_track(h);let mut s = num(v, "saturation", 0.0).clamp(slo, 100.0);- let r = widgets::slider_row(ui, tl!("Saturation"), &mut s, slo..=100.0, "%", Some(&sat_track));+ let r = widgets::slider_row(ui, tl!("Saturation"), &mut s, slo..=100.0, "%", track_stops(cx, &sat_track));if r.changed() {v["saturation"] = json!(s.round());}e.add(Edit::of(&r));let light_track = lightness_track(h);let mut l = num(v, "lightness", 0.0).clamp(-100.0, 100.0);- let r = widgets::slider_row(ui, tl!("Lightness"), &mut l, -100.0..=100.0, "%", Some(&light_track));+ let r = widgets::slider_row(ui, tl!("Lightness"), &mut l, -100.0..=100.0, "%", track_stops(cx, &light_track));if r.changed() {v["lightness"] = json!(l.round());}@@ -791,7 +800,7 @@ fn hue_saturation(ui: &mut egui::Ui, v: &mut Value, cx: &EditorCx) -> Edit {let mut o = v[key].clone();let mut sub = Edit::default();let mut h = num(&o, "hue", 0.0);- let r = widgets::slider_row(ui, tl!("Hue"), &mut h, -180.0..=180.0, "°", Some(&hue_grad));+ let r = widgets::slider_row(ui, tl!("Hue"), &mut h, -180.0..=180.0, "°", track_stops(cx, &hue_grad));if r.changed() {o["hue"] = json!(h.round());}@@ -946,13 +955,14 @@ fn color_balance(ui: &mut egui::Ui, v: &mut Value, cx: &EditorCx) -> Edit {// ---------------------------------------------------------------------------------------------// Black & White-fn black_white(ui: &mut egui::Ui, v: &mut Value) -> Edit {+fn black_white(ui: &mut egui::Ui, v: &mut Value, cx: &EditorCx) -> Edit {let mut e = Edit::default();let colors = [[230, 50, 50], [235, 215, 40], [50, 200, 70], [40, 200, 220], [50, 90, 235], [220, 50, 210]];for (i, key) in HUE_RANGES.iter().enumerate() {let mut x = num(v, key, adjust_params::BW_DEFAULTS[i]).clamp(-200.0, 300.0);let c = colors[i];- let r = gradient_slider(ui, RANGE_LABELS[i], &mut x, -200.0..=300.0, "%", Color32::BLACK, Color32::from_rgb(c[0], c[1], c[2]));+ let r =+ gradient_slider(ui, RANGE_LABELS[i], &mut x, -200.0..=300.0, "%", [Color32::BLACK, Color32::from_rgb(c[0], c[1], c[2])], cx.dynamic_color_sliders);if r.changed {v[*key] = json!(x.round());}@@ -1050,7 +1060,7 @@ fn channel_mixer(ui: &mut egui::Ui, v: &mut Value, cx: &EditorCx) -> Edit {let mut e = Edit::default();let mut changed = false;for (i, (text, c)) in [(tl!("Red"), [225, 50, 50]), (tl!("Green"), [50, 190, 70]), (tl!("Blue"), [60, 100, 235])].iter().enumerate() {- let r = gradient_slider(ui, text, &mut row[i], -200.0..=200.0, "%", Color32::BLACK, Color32::from_rgb(c[0], c[1], c[2]));+ let r = gradient_slider(ui, text, &mut row[i], -200.0..=200.0, "%", [Color32::BLACK, Color32::from_rgb(c[0], c[1], c[2])], cx.dynamic_color_sliders);changed |= r.changed;e.add(r);}@@ -1352,7 +1362,15 @@ pub fn layer_editor(app: &mut PhotocraftApp, ui: &mut egui::Ui, id: LayerId, adj};let gray = app.session.active().is_some_and(|s| is_gray(s.doc.mode));let hist = needs_histogram(kind).then(|| tone::histograms(app, HistSource::BelowLayer(id), space_of(&values)));- let cx = EditorCx { mem: layer_mem(id), hist, gray, swatches: swatches(app), gradients: gradient_presets(app, kind), dialog: false };+ let cx = EditorCx {+ mem: layer_mem(id),+ hist,+ gray,+ swatches: swatches(app),+ gradients: gradient_presets(app, kind),+ dialog: false,+ dynamic_color_sliders: app.session.prefs().interface.dynamic_color_sliders,+ };let e = editor(ui, kind, &mut values, &cx);if e.changed {app.live_adjust = Some((id, values.clone()));@@ -1388,6 +1406,23 @@ mod tests {assert_eq!(lightness_track(200.0), [Color32::BLACK, hue_color(200.0), Color32::WHITE]);}+ /// Preferences ▸ Interface ▸ Dynamic Color Sliders: off, the colour sliders get plain tracks.+ #[test]+ fn dynamic_color_sliders_switch_the_tracks_off() {+ let cx = |dynamic: bool| EditorCx {+ mem: egui::Id::NULL,+ hist: None,+ gray: false,+ swatches: [[0.0; 3]; 2],+ gradients: Vec::new(),+ dialog: false,+ dynamic_color_sliders: dynamic,+ };+ let stops = [Color32::BLACK, Color32::RED];+ assert_eq!(track_stops(&cx(true), &stops), Some(&stops[..]));+ assert_eq!(track_stops(&cx(false), &stops), None);+ }+#[test]fn hue_range_drag_canonicalizes_bounds_before_clamping() {let moved = move_hue_range_handle([0.0, 350.0, 100.0, 200.0], 2, 354.0);diff --git a/crates/ui-egui/src/panels.rs b/crates/ui-egui/src/panels.rsindex 7cad11516..ff7c31553 100644--- a/crates/ui-egui/src/panels.rs+++ b/crates/ui-egui/src/panels.rs@@ -1742,12 +1742,14 @@ fn color_picker(app: &mut PhotocraftApp, ui: &mut egui::Ui) {let mut s = hsva0.s * 100.0;let mut v = hsva0.v * 100.0;let hue = widgets::hue_stops();- let mut changed = widgets::slider_row(ui, tl!("Hue"), &mut h, 0.0..=360.0, "°", Some(&hue)).changed();+ // Preferences ▸ Interface ▸ Dynamic Color Sliders: off, the tracks are the plain ones.+ let dynamic = app.session.prefs().interface.dynamic_color_sliders;+ let mut changed = widgets::slider_row(ui, tl!("Hue"), &mut h, 0.0..=360.0, "°", dynamic.then_some(&hue)).changed();let sat_stops =[egui::ecolor::Hsva::new(hsva0.h, 0.0, hsva0.v.max(0.2), 1.0), egui::ecolor::Hsva::new(hsva0.h, 1.0, hsva0.v.max(0.2), 1.0)].map(Color32::from);- changed |= widgets::slider_row(ui, tl!("Saturation"), &mut s, 0.0..=100.0, "%", Some(&sat_stops)).changed();+ changed |= widgets::slider_row(ui, tl!("Saturation"), &mut s, 0.0..=100.0, "%", dynamic.then_some(&sat_stops)).changed();let val_stops = [Color32::BLACK, Color32::from(egui::ecolor::Hsva::new(hsva0.h, hsva0.s, 1.0, 1.0))];- changed |= widgets::slider_row(ui, tl!("Brightness"), &mut v, 0.0..=100.0, "%", Some(&val_stops)).changed();+ changed |= widgets::slider_row(ui, tl!("Brightness"), &mut v, 0.0..=100.0, "%", dynamic.then_some(&val_stops)).changed();let hsva = egui::ecolor::Hsva::new(h / 360.0, s / 100.0, v / 100.0, 1.0);// Only an edit counts: the h/s/v round trip isn't exact, so comparing values would rewrite// the foreground (and recolour selected type) every frame.diff --git a/docs/scorecard.md b/docs/scorecard.mdindex b79ed215f..f0f16eca6 100644--- a/docs/scorecard.md+++ b/docs/scorecard.md@@ -9,7 +9,7 @@ Generated by `cargo xtask scorecard` from `perf/budgets.toml`, `perf/baseline.js| [Performance](#performance) | 3 | 22 | 22 | 56 scenarios: 3 within budget, 22 over budget or failing, 9 tracked only, 15 not run, 7 not measurable yet (baseline 2026-10-05) || [File compatibility](#file-compatibility) | 5 | 11 | 11 | io corpus: oracle ≥ 146/170, round trip ≥ 169/170; psd-tools corpus: oracle ≥ 236/309, round trip ≥ 308/309; photoshop oracles: oracle ≥ 133/256, round trip ≥ 258/256 || [Tools](#tools) | 21 | 15 | 6 | |-| [Workspace and UI](#workspace-and-ui) | 6 | 7 | 10 | settings that do nothing: 45 of 149 (target 0) |+| [Workspace and UI](#workspace-and-ui) | 6 | 7 | 10 | settings that do nothing: 44 of 149 (target 0) || [Type](#type) | 0 | 3 | 6 | || [Automation](#automation) | 3 | 2 | 6 | 628 of 628 menu items live (100.0%) || [Reliability](#reliability) | 5 | 2 | 0 | never-crash lints on 28 of 28 crates; panic_hunt present |@@ -175,9 +175,9 @@ Corpus floors (`crates/io/tests/corpus.rs`): the enforced minimums; the corpus t## Workspace and UI-**Settings that do nothing: 45 of 149** (target 0, #204). Counted by the prefs audit (`xtask/src/scorecard.rs`): a `Preferences` field counts as read when code outside the prefs model (`prefs.rs` except its `impl Session` blocks; tests excluded; the schema-driven dialog never names a field) accesses `section.field`, or `.section` and `.field` in the same file, or calls a section method that reads `self.field`. It is a heuristic lower bound: a generic name can look read when it isn't.+**Settings that do nothing: 44 of 149** (target 0, #204). Counted by the prefs audit (`xtask/src/scorecard.rs`): a `Preferences` field counts as read when code outside the prefs model (`prefs.rs` except its `impl Session` blocks; tests excluded; the schema-driven dialog never names a field) accesses `section.field`, or `.section` and `.field` in the same file, or calls a section method that reads `self.field`. It is a heuristic lower bound: a generic name can look read when it isn't.-Unread: `general.color_picker`, `general.beep_when_done`, `general.resize_image_during_place`, `general.always_create_smart_objects_when_placing`, `general.animated_zoom`, `general.zoom_resizes_windows`, `interface.dynamic_color_sliders`, `workspace.auto_collapse_icon_panels`, `workspace.auto_show_hidden_panels`, `workspace.enable_floating_document_window_docking`, `workspace.enable_narrow_options_bar`, `tools.enable_flick_panning`, `tools.vary_round_brush_hardness_on_hud`, `tools.show_transformation_values`, `file_handling.image_previews`, `file_handling.save_in_background`, `file_handling.ignore_exif_profile_tag`, `file_handling.maximize_psd_compatibility`, `performance.cache_levels`, `performance.legacy_compositing`, `scratch_disks.disks`, `cursors.brush_preview_color`, `units_and_rulers.type_units`, `units_and_rulers.column_width`, `units_and_rulers.gutter`, `units_and_rulers.print_resolution`, `plug_ins.show_extension_panels`, `plug_ins.allow_scripts_to_connect`, `plug_ins.generator_enabled`, `type_.missing_glyph_protection`, `type_.show_font_names_in_english`, `type_.text_engine`, `type_.font_preview`, `type_.recent_fonts`, `enhanced_controls.scrubby_slider_acceleration`, `enhanced_controls.touch_gestures`, `enhanced_controls.zoom_with_trackpad_pinch`, `raw_defaults.color_space`, `raw_defaults.bit_depth`, `raw_defaults.resolution`, `raw_defaults.sharpen_for`, `raw_defaults.open_as_smart_object`, `raw_defaults.apply_auto_tone`, `integrations.allow_agent_control`, `integrations.control_port`.+Unread: `general.color_picker`, `general.beep_when_done`, `general.resize_image_during_place`, `general.always_create_smart_objects_when_placing`, `general.animated_zoom`, `general.zoom_resizes_windows`, `workspace.auto_collapse_icon_panels`, `workspace.auto_show_hidden_panels`, `workspace.enable_floating_document_window_docking`, `workspace.enable_narrow_options_bar`, `tools.enable_flick_panning`, `tools.vary_round_brush_hardness_on_hud`, `tools.show_transformation_values`, `file_handling.image_previews`, `file_handling.save_in_background`, `file_handling.ignore_exif_profile_tag`, `file_handling.maximize_psd_compatibility`, `performance.cache_levels`, `performance.legacy_compositing`, `scratch_disks.disks`, `cursors.brush_preview_color`, `units_and_rulers.type_units`, `units_and_rulers.column_width`, `units_and_rulers.gutter`, `units_and_rulers.print_resolution`, `plug_ins.show_extension_panels`, `plug_ins.allow_scripts_to_connect`, `plug_ins.generator_enabled`, `type_.missing_glyph_protection`, `type_.show_font_names_in_english`, `type_.text_engine`, `type_.font_preview`, `type_.recent_fonts`, `enhanced_controls.scrubby_slider_acceleration`, `enhanced_controls.touch_gestures`, `enhanced_controls.zoom_with_trackpad_pinch`, `raw_defaults.color_space`, `raw_defaults.bit_depth`, `raw_defaults.resolution`, `raw_defaults.sharpen_for`, `raw_defaults.open_as_smart_object`, `raw_defaults.apply_auto_tone`, `integrations.allow_agent_control`, `integrations.control_port`.| Id | Target | Status | Issue | Note ||---|---|---|---|---|