feat(ui): Preset menus for Levels, Exposure, Black & White and Channel Mixer

Fixes #9263, #9265, #9268, #9270. Each of these adjustments gains a
Preset menu at the top of its editor (dialog and Properties), with the
preset names Photoshop uses and Custom once edited; a choice is one edit.

The settings are PhotoCraft's own, designed for each look: Levels
presets lift, lower or stretch the tones; Exposure presets are whole
stops; the Black & White and Channel Mixer "filter" presets follow what a
coloured lens filter does on black-and-white film. None is taken or
measured from another application's presets.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Hector VillarrealandClaude Opus 5.5 committed 2026-10-25 20:34:19 -06:00
1 parent d3b0a76c3f
commit 5a432c2b7e
5 files changed
+252 -1

No files matched your search

+44
View File
@@ -802,6 +802,50 @@ mod tests {
assert_eq!(h.state().session.active().unwrap().history.past_len(), steps + 1);
}
/// #9263, #9265, #9268, #9270: Levels, Exposure, Black & White and Channel Mixer open on the
/// Default preset; choosing another loads its settings (the preview follows) and an edit by
/// hand reads Custom.
#[test]
fn adjustment_preset_menus_load_presets_and_read_custom_after_an_edit() {
use egui_kittest::kittest::{NodeT, Queryable};
for (kind, label, key) in [
("levels", "Increase Contrast 2", "inBlack"),
("exposure", "Plus 1.0", "exposure"),
("blackWhite", "Red Filter", "reds"),
("channelMixer", "Black & White with Red Filter (RGB)", "monochrome"),
] {
let mut h = Harness::builder().with_size(egui::vec2(1200.0, 900.0)).build_ui_state(|ui, app| crate::dialogs::show(app, ui.ctx()), app_with_image());
PhotocraftApp::setup_context(&h.ctx, crate::theme::ThemeKind::ALL[0]);
let id = open(h.state_mut(), &format!("image.adjustments.{kind}")).unwrap();
h.run_steps(4);
let preset = |h: &Harness<'_, PhotocraftApp>| {
h.query_all_by_role(egui::accesskit::Role::ComboBox).next().and_then(|n| n.accesskit_node().value().map(|s| s.to_string()))
};
assert_eq!(preset(&h).as_deref(), Some("Default"), "{kind} opens on Default");
h.query_all_by_role(egui::accesskit::Role::ComboBox).next().unwrap().click();
h.run_steps(2);
h.get_by_label(label).click();
h.run_steps(3);
assert_eq!(preset(&h).as_deref(), Some(label), "{kind}: the menu shows the preset");
let want = crate::adjust_presets::presets(kind, false)
.iter()
.find(|p| p.label == label)
.and_then(|p| crate::adjust_presets::settings(kind, p, false))
.unwrap();
assert_eq!(h.state().ui.dialogs[0].fields[key], want[key], "{kind}: the preset's settings are loaded");
let edit = match kind {
"levels" => ("gamma", json!(1.37)),
"exposure" => ("offset", json!(0.05)),
"blackWhite" => ("blues", json!(33)),
_ => ("gray", json!([90, 10, 0, 0])),
};
h.state_mut().ui.dialog_mut(id).unwrap().fields.insert(edit.0.into(), edit.1);
h.run_steps(3);
assert_eq!(preset(&h).as_deref(), Some("Custom"), "{kind}: an edit is Custom");
crate::dialogs::confirm(h.state_mut(), id).unwrap();
}
}
#[test]
fn curves_pointer_drag_previews_until_confirm_and_cancel_preserves_document() {
for confirm in [false, true] {
+33
View File
@@ -112,6 +112,39 @@ pub fn editor(ui: &mut egui::Ui, kind: &str, v: &mut Value, cx: &EditorCx) -> Ed
if !v.is_object() {
*v = json!({});
}
let mut e = preset_row(ui, kind, v, cx);
e.add(kind_editor(ui, kind, v, cx));
e
}
/// The Preset menu above Levels, Exposure, Black & White and Channel Mixer (#9263, #9265, #9268,
/// #9270): PhotoCraft's own presets (`adjust_presets`), Custom once edited; a choice is one edit.
fn preset_row(ui: &mut egui::Ui, kind: &str, v: &mut Value, cx: &EditorCx) -> Edit {
let list = crate::adjust_presets::presets(kind, cx.gray);
if list.is_empty() || (kind == "levels" && space_of(v) != ToneSpace::Rgb) {
return Edit::default();
}
let mut e = Edit::default();
ui.horizontal(|ui| {
label(ui, tl!("Preset:"));
let current = crate::adjust_presets::matching(kind, v, cx.gray).map_or("custom", |p| p.id);
let mut options: Vec<(&str, &str)> = list.iter().map(|p| (p.id, tl!(p.label))).collect();
if current == "custom" {
options.push(("custom", tl!("Custom")));
}
let mut picked = current;
if widgets::dropdown(ui, &format!("{kind}-preset"), &mut picked, &options, ui.available_width().min(220.0))
&& picked != current
&& let Some(settings) = list.iter().find(|p| p.id == picked).and_then(|p| crate::adjust_presets::settings(kind, p, cx.gray))
{
*v = settings;
e.add(Edit::discrete(true));
}
});
e
}
fn kind_editor(ui: &mut egui::Ui, kind: &str, v: &mut Value, cx: &EditorCx) -> Edit {
match kind {
"brightnessContrast" => brightness_contrast(ui, v),
"levels" => levels(ui, v, cx),
+172
View File
@@ -0,0 +1,172 @@
//! Preset menus for Levels, Exposure, Black & White and Channel Mixer (#9263, #9265, #9268,
//! #9270): starting settings named for the looks they give, as the Preset menu at the top of
//! these adjustments in Photoshop.
//!
//! The settings are PhotoCraft's own. Each was designed for its look: Levels presets lift, lower or
//! stretch the tones; Exposure presets are whole stops; the Black & White "filter" presets follow
//! what a coloured lens filter does on black-and-white film (it lightens its own colour and darkens
//! its complement); the Channel Mixer presets mix the channels a filter would let through. None is
//! taken or measured from another application's preset files.
use photocraft_doc::ColorMode;
use photocraft_engine::adjust_params::{from_params, to_params};
use serde_json::{Value, json};
/// A preset: its id (the menu value), label and the adjustment params it sets (the rest default).
pub struct AdjustPreset {
pub id: &'static str,
pub label: &'static str,
pub params: fn() -> Value,
}
macro_rules! preset {
($id:literal, $label:literal, $params:tt) => {
AdjustPreset { id: $id, label: $label, params: || json!($params) }
};
}
const LEVELS: &[AdjustPreset] = &[
preset!("default", "Default", {}),
// The whole image darker: the white output comes down.
preset!("darker", "Darker", {"outWhite": 220}),
// Black and white input points pulled in, a step further each time.
preset!("increaseContrast1", "Increase Contrast 1", {"inBlack": 12, "inWhite": 243}),
preset!("increaseContrast2", "Increase Contrast 2", {"inBlack": 24, "inWhite": 231}),
preset!("increaseContrast3", "Increase Contrast 3", {"inBlack": 36, "inWhite": 219}),
// Shadows lifted off black and opened up a little; highlights left where they are.
preset!("lightenShadows", "Lighten Shadows", {"outBlack": 20, "gamma": 1.1}),
// The whole image lighter: the white input point comes in.
preset!("lighter", "Lighter", {"inWhite": 220}),
// The midtones alone, up or down; black and white stay put.
preset!("midtonesBrighter", "Midtones Brighter", {"gamma": 1.3}),
preset!("midtonesDarker", "Midtones Darker", {"gamma": 0.77}),
];
const EXPOSURE: &[AdjustPreset] = &[
preset!("default", "Default", {}),
preset!("minus1", "Minus 1.0", {"exposure": -1.0}),
preset!("minus2", "Minus 2.0", {"exposure": -2.0}),
preset!("plus1", "Plus 1.0", {"exposure": 1.0}),
preset!("plus2", "Plus 2.0", {"exposure": 2.0}),
];
// Black & White weights per colour range: reds, yellows, greens, cyans, blues, magentas.
const BLACK_WHITE: &[AdjustPreset] = &[
preset!("default", "Default", {}),
// A blue filter: blues and cyans light, reds and yellows dark.
preset!("blueFilter", "Blue Filter", {"reds": 0, "yellows": 20, "greens": 40, "cyans": 100, "blues": 110, "magentas": 80}),
// Every colour a little darker.
preset!("darker", "Darker", {"reds": 20, "yellows": 40, "greens": 20, "cyans": 40, "blues": 0, "magentas": 60}),
// A green filter: greens light (foliage), reds and magentas dark.
preset!("greenFilter", "Green Filter", {"reds": 10, "yellows": 80, "greens": 110, "cyans": 60, "blues": 20, "magentas": 0}),
// The blue filter pushed further: deep reds, glowing blues.
preset!("highContrastBlueFilter", "High Contrast Blue Filter", {"reds": -40, "yellows": 0, "greens": 40, "cyans": 140, "blues": 160, "magentas": 100}),
// The red filter pushed further: near-white reds, near-black blue skies.
preset!("highContrastRedFilter", "High Contrast Red Filter", {"reds": 140, "yellows": 120, "greens": 0, "cyans": -40, "blues": -60, "magentas": 80}),
// Infrared film: foliage greens and yellows glow, skies go dark.
preset!("infrared", "Infrared", {"reds": -20, "yellows": 190, "greens": 200, "cyans": -30, "blues": -60, "magentas": 40}),
// Every colour a little lighter.
preset!("lighter", "Lighter", {"reds": 60, "yellows": 80, "greens": 60, "cyans": 80, "blues": 40, "magentas": 100}),
// Colours as dark as they go.
preset!("maximumBlack", "Maximum Black", {"reds": 0, "yellows": 0, "greens": 0, "cyans": 0, "blues": 0, "magentas": 0}),
// Colours as light as they go.
preset!("maximumWhite", "Maximum White", {"reds": 150, "yellows": 150, "greens": 150, "cyans": 150, "blues": 150, "magentas": 150}),
// A neutral filter: every colour weighed the same.
preset!("neutralDensity", "Neutral Density", {"reds": 50, "yellows": 50, "greens": 50, "cyans": 50, "blues": 50, "magentas": 50}),
// A red filter: reds and yellows light, blues and cyans dark (dramatic skies).
preset!("redFilter", "Red Filter", {"reds": 110, "yellows": 100, "greens": 0, "cyans": -20, "blues": -30, "magentas": 70}),
// A yellow filter: a gentle darkening of blue skies.
preset!("yellowFilter", "Yellow Filter", {"reds": 70, "yellows": 100, "greens": 50, "cyans": 30, "blues": 0, "magentas": 50}),
];
// Channel Mixer monochrome mixes `[red %, green %, blue %, constant %]`: what a filter lets through.
const CHANNEL_MIXER: &[AdjustPreset] = &[
preset!("default", "Default", {}),
preset!("bwInfrared", "Black & White Infrared (RGB)", {"monochrome": true, "gray": [-60, 190, -30, 0]}),
preset!("bwBlueFilter", "Black & White with Blue Filter (RGB)", {"monochrome": true, "gray": [0, 0, 100, 0]}),
preset!("bwGreenFilter", "Black & White with Green Filter (RGB)", {"monochrome": true, "gray": [0, 100, 0, 0]}),
preset!("bwOrangeFilter", "Black & White with Orange Filter (RGB)", {"monochrome": true, "gray": [50, 50, 0, 0]}),
preset!("bwRedFilter", "Black & White with Red Filter (RGB)", {"monochrome": true, "gray": [100, 0, 0, 0]}),
preset!("bwYellowFilter", "Black & White with Yellow Filter (RGB)", {"monochrome": true, "gray": [34, 66, 0, 0]}),
];
/// The presets of adjustment `kind` for a document (`gray`: Grayscale, where the colour presets
/// don't apply); empty for a kind without a Preset menu.
pub fn presets(kind: &str, gray: bool) -> &'static [AdjustPreset] {
match kind {
"levels" => LEVELS,
"exposure" => EXPOSURE,
"blackWhite" if !gray => BLACK_WHITE,
"channelMixer" if !gray => CHANNEL_MIXER,
_ => &[],
}
}
fn mode(gray: bool) -> ColorMode {
if gray { ColorMode::Grayscale } else { ColorMode::Rgb }
}
/// `params` as the engine reads them: every key, defaults filled in.
fn normal(kind: &str, params: &Value, gray: bool) -> Option<Value> {
from_params(kind, params, None, mode(gray)).ok().map(|a| to_params(&a))
}
/// The settings `preset` gives, with every other key at its default.
pub fn settings(kind: &str, preset: &AdjustPreset, gray: bool) -> Option<Value> {
normal(kind, &(preset.params)(), gray)
}
/// The preset the values `v` are (Default for untouched values), or `None` (Custom).
pub fn matching(kind: &str, v: &Value, gray: bool) -> Option<&'static AdjustPreset> {
let now = normal(kind, v, gray)?;
presets(kind, gray).iter().find(|p| settings(kind, p, gray).as_ref() == Some(&now))
}
#[cfg(test)]
mod tests {
use super::*;
/// Every preset is valid, distinct and recognised once applied; an edit makes it Custom.
#[test]
fn presets_apply_and_are_recognised() {
for kind in ["levels", "exposure", "blackWhite", "channelMixer"] {
let all = presets(kind, false);
assert!(all.len() >= 5 && all[0].id == "default", "{kind}");
for p in all {
let s = settings(kind, p, false).unwrap_or_else(|| panic!("{kind} {}: valid params", p.id));
assert_eq!(matching(kind, &s, false).map(|m| m.id), Some(p.id), "{kind} {}", p.id);
}
let distinct: std::collections::HashSet<String> = all.iter().map(|p| settings(kind, p, false).unwrap().to_string()).collect();
assert_eq!(distinct.len(), all.len(), "{kind}: no two presets are the same");
assert_eq!(matching(kind, &json!({}), false).map(|p| p.id), Some("default"), "{kind}: untouched is Default");
}
let mut v = settings("levels", &LEVELS[3], false).unwrap();
v["gamma"] = json!(1.37);
assert!(matching("levels", &v, false).is_none(), "an edit is Custom");
assert!(presets("blackWhite", true).is_empty() && presets("channelMixer", true).is_empty(), "colour presets need colour");
assert_eq!(presets("levels", true).len(), LEVELS.len());
}
/// The looks hold: contrast steps widen, filters lighten their own colour and darken the
/// complement, exposure presets are whole stops.
#[test]
fn presets_give_their_looks() {
let lv = |id: &str| settings("levels", LEVELS.iter().find(|p| p.id == id).unwrap(), false).unwrap();
let span = |v: &Value| v["inWhite"].as_f64().unwrap() - v["inBlack"].as_f64().unwrap();
assert!(span(&lv("increaseContrast1")) > span(&lv("increaseContrast2")) && span(&lv("increaseContrast2")) > span(&lv("increaseContrast3")));
assert!(lv("midtonesBrighter")["gamma"].as_f64().unwrap() > 1.0 && lv("midtonesDarker")["gamma"].as_f64().unwrap() < 1.0);
let bw = |id: &str| settings("blackWhite", BLACK_WHITE.iter().find(|p| p.id == id).unwrap(), false).unwrap();
let w = |v: &Value, k: &str| v[k].as_f64().unwrap();
assert!(w(&bw("redFilter"), "reds") > w(&bw("redFilter"), "cyans"), "a red filter lightens reds over cyans");
assert!(w(&bw("blueFilter"), "blues") > w(&bw("blueFilter"), "yellows"), "a blue filter lightens blues over yellows");
assert!(
w(&bw("highContrastRedFilter"), "reds") - w(&bw("highContrastRedFilter"), "blues") > w(&bw("redFilter"), "reds") - w(&bw("redFilter"), "blues")
);
let ex = |id: &str| settings("exposure", EXPOSURE.iter().find(|p| p.id == id).unwrap(), false).unwrap()["exposure"].as_f64().unwrap();
assert_eq!([ex("minus2"), ex("minus1"), ex("plus1"), ex("plus2")], [-2.0, -1.0, 1.0, 2.0]);
for p in &CHANNEL_MIXER[1..] {
let s = settings("channelMixer", p, false).unwrap();
assert_eq!(s["monochrome"], json!(true), "{}", p.id);
}
}
}
+1
View File
@@ -17,6 +17,7 @@ macro_rules! tl {
pub mod actions;
pub mod adjust_dialog;
pub mod adjust_editors;
pub(crate) mod adjust_presets;
pub mod adjust_preview;
pub mod adjust_ui;
mod align_bar;
+2 -1
View File
@@ -1,6 +1,6 @@
# UI parity: tools, handles, modifiers and feel
> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-10-25 · **Change:** minor (12 of 178 preferences do nothing, from the scorecard; Art History Brush in the History group of the Y flyout, partial, TOOL-213-20, #1610; Histogram panel: Compact / Expanded / All Channels views, Luminosity and Colors channels, Source, range statistics, Uncached Refresh, live adjustment overlay, Cache Levels preference; the font menu opens on the current family, marked in the recent group when it is a recent one, #9160; Type options bar alignment and direction follow the target paragraph; a swatch click recolours selected type and shape layers with any tool, #9238; UI scale presets done: 105–120% steps, #3222; ⇧⌥ blend mode letters; painting tool Mode menus; ⌥ + an adjustment's shortcut reopens it at its last settings, ⌥⌘L / ⌥⌘M, #8900; Crop default mode: moving the image under the box snaps the frame's edges and centre, #8580; View › Extras hides the Move transform controls, #6699; adjustment clipping stays visible in compact Properties, #5231; Color panel modes from its panel menu, the same in every theme, UI-217-17, #6000; a picked colour recolours the selected type and shapes; Hand tool ⌘ / ⌥ are Zoom In / Zoom Out while held, #6434; the wheel steps value fields, #5473; a dragged guide shows its X or Y beside the pointer, #7680; Type options bar "T" icon scrubs the font size, #6437; Move tool: dragged selected pixels take their own outline as the selection, #7538; artboard backgrounds remain below child Free Transform previews; ⌫/Delete removes the selected smart filter, #4751; Object Finder foreground/background discrimination (#6548); rounded triangle, polygon and star corners; shape Fill/Stroke popovers accept hex RGB values, #6176; a guide let go over either ruler is removed, #6286; Crop rows corrected: saved crop presets and Delete Cropped Pixels off are done, #6562; marching ants in device pixels, #7489; Animated Zoom: holding the Zoom tool zooms continuously, #6210; shape Density and Feather, TOOL-214-12, #5846; Pen Auto Add/Delete on the path being drawn, #6140; Show Transform Controls frames every selected layer; guide keys and clicks; menu bar from the keyboard, #4988; Crop tool Content-Aware Fill; on-canvas corner radius widgets, TOOL-214-12; Curvature Pen edits the active path; Clip Thumbnails to Layer Bounds; Pen ⇧ 45°; last selected tool restored at launch; Layers panel filter-type dropdown with Kind, Name and Mode, #5048; Free Transform box and marching ants follow the selection, #5297; History: the trash deletes the selected snapshot, rows drag onto the trash, #5324; smart filter reordering by drag; smart object perspective row corrected to done, #426; Free Transform H/V skew fields; toolbar tool shortcuts can be reassigned; ⇧-dragged guides land on ruler ticks; layer and selection keys; tool keys; spring-loaded tool letters; type formatting keys; Pen Auto Add/Delete, #4144; smart filter rows; stale missing-tool rows corrected: Color Replacement, Red Eye and the Add/Delete Anchor Point pair are live toolbar tools, Frame landed; no percentage changed; selection-modifier and ⌥-wheel rows match their tests; Properties › Transform shows a shape's path geometry, without its stroke) · **Target:** Adobe Photoshop 2026
> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-10-25 · **Change:** minor (Preset menus for Levels, Exposure, Black & White and Channel Mixer, #9263 #9265 #9268 #9270; 12 of 178 preferences do nothing, from the scorecard; Art History Brush in the History group of the Y flyout, partial, TOOL-213-20, #1610; Histogram panel: Compact / Expanded / All Channels views, Luminosity and Colors channels, Source, range statistics, Uncached Refresh, live adjustment overlay, Cache Levels preference; the font menu opens on the current family, marked in the recent group when it is a recent one, #9160; Type options bar alignment and direction follow the target paragraph; a swatch click recolours selected type and shape layers with any tool, #9238; UI scale presets done: 105–120% steps, #3222; ⇧⌥ blend mode letters; painting tool Mode menus; ⌥ + an adjustment's shortcut reopens it at its last settings, ⌥⌘L / ⌥⌘M, #8900; Crop default mode: moving the image under the box snaps the frame's edges and centre, #8580; View › Extras hides the Move transform controls, #6699; adjustment clipping stays visible in compact Properties, #5231; Color panel modes from its panel menu, the same in every theme, UI-217-17, #6000; a picked colour recolours the selected type and shapes; Hand tool ⌘ / ⌥ are Zoom In / Zoom Out while held, #6434; the wheel steps value fields, #5473; a dragged guide shows its X or Y beside the pointer, #7680; Type options bar "T" icon scrubs the font size, #6437; Move tool: dragged selected pixels take their own outline as the selection, #7538; artboard backgrounds remain below child Free Transform previews; ⌫/Delete removes the selected smart filter, #4751; Object Finder foreground/background discrimination (#6548); rounded triangle, polygon and star corners; shape Fill/Stroke popovers accept hex RGB values, #6176; a guide let go over either ruler is removed, #6286; Crop rows corrected: saved crop presets and Delete Cropped Pixels off are done, #6562; marching ants in device pixels, #7489; Animated Zoom: holding the Zoom tool zooms continuously, #6210; shape Density and Feather, TOOL-214-12, #5846; Pen Auto Add/Delete on the path being drawn, #6140; Show Transform Controls frames every selected layer; guide keys and clicks; menu bar from the keyboard, #4988; Crop tool Content-Aware Fill; on-canvas corner radius widgets, TOOL-214-12; Curvature Pen edits the active path; Clip Thumbnails to Layer Bounds; Pen ⇧ 45°; last selected tool restored at launch; Layers panel filter-type dropdown with Kind, Name and Mode, #5048; Free Transform box and marching ants follow the selection, #5297; History: the trash deletes the selected snapshot, rows drag onto the trash, #5324; smart filter reordering by drag; smart object perspective row corrected to done, #426; Free Transform H/V skew fields; toolbar tool shortcuts can be reassigned; ⇧-dragged guides land on ruler ticks; layer and selection keys; tool keys; spring-loaded tool letters; type formatting keys; Pen Auto Add/Delete, #4144; smart filter rows; stale missing-tool rows corrected: Color Replacement, Red Eye and the Add/Delete Anchor Point pair are live toolbar tools, Frame landed; no percentage changed; selection-modifier and ⌥-wheel rows match their tests; Properties › Transform shows a shape's path geometry, without its stroke) · **Target:** Adobe Photoshop 2026
How PhotoCraft's direct manipulation compares with Photoshop 2026 (27.11.0): the toolbox, the
handles and modifier keys of each gesture, nudging, snapping, numeric precision, navigation,
@@ -246,6 +246,7 @@ Paragraph; the rest open as in-app floating windows.
| Date | Change | Summary |
|---|---|---|
| 2026-10-24 | minor | Levels, Exposure, Black & White and Channel Mixer gain a Preset menu (Custom after an edit) in the dialog and Properties, with the preset names Photoshop uses. The settings are PhotoCraft's own, designed for each look, not Photoshop's preset data (#9263, #9265, #9268, #9270). Scores unchanged. |
| 2026-10-25 | minor | Every preference takes effect: 12 of 178 do nothing, the scorecard's count (it still said 46 of 149) |
| 2026-10-25 | minor | Art History Brush is in the History group of the Y flyout (partial, TOOL-213-20, #1610) |
| 2026-10-24 | minor | Swatches: a click recolours the selected type layers and shape fills whatever the tool, as Photoshop 2025 does (measured with the Move and Brush tools); the Color panel still recolours them only with a Type, shape or Pen tool (#9238). Scores unchanged. |