Pattern Stamp: grey Behind in the options bar on the Background; Impressionist keeps its pixels (#12879)

- The options bar's Mode dropdown greys Behind when the Background is the
  active layer, as the Shift+right-click menu does: the entry is drawn
  disabled, a click on it picks nothing, and the wheel and the keys step
  past it. On a pixel layer it is enabled. Only the Pattern Stamp's
  dropdown uses the new greyed-option variant of the dropdown widget.
- Behind with Impressionist was not measured, so an Impressionist stroke
  again gives exactly the pixels it gives in Normal, committed and live,
  when Behind is picked. The per-dab Behind code is removed.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
ljkxandClaude Fable 5.2 committed 2026-11-10 23:59:10 +01:00
1 parent 8228c3649c
commit 5d6a491060
9 files changed
+229 -93

No files matched your search

+15
View File
@@ -73,6 +73,21 @@ pub(crate) fn pattern_stamp_choices() -> Vec<((Option<BlendMode>, bool), &'stati
choices().into_iter().filter(|c| c.0 != (None, false)).collect()
}
/// What a pick in the Pattern Stamp's Mode dropdown sets, from `from` to `to` (both `(mode,
/// behind)` of [`pattern_stamp_choices`]). With Behind greyed (`behind_enabled` false, the
/// Background), a wheel notch or a key that lands on Behind steps on to the next mode the same
/// way, so the greyed entry is never picked.
pub(crate) fn pattern_stamp_pick(from: (Option<BlendMode>, bool), to: (Option<BlendMode>, bool), behind_enabled: bool) -> (Option<BlendMode>, bool) {
if behind_enabled || !to.1 {
return to;
}
let list = pattern_stamp_choices();
let at = |m: (Option<BlendMode>, bool)| list.iter().position(|c| c.0 == m);
let (Some(a), Some(b)) = (at(from), at(to)) else { return from };
let next = if a > b { b.checked_sub(1) } else { b.checked_add(1) };
next.and_then(|i| list.get(i)).map_or(from, |c| c.0)
}
/// The blend modes in their menu groups (a separator before Darken, Lighten, Overlay, Difference
/// and Hue), with Behind and/or Clear after Dissolve.
fn blend_items(behind: bool, clear: bool) -> Vec<Item> {
@@ -105,10 +105,13 @@ fn retouch_tools_have_a_mode_dropdown() {
}
/// The Pattern Stamp's Mode dropdown has Behind after Dissolve and no Clear (#12879): the wheel
/// steps Normal, Dissolve, Behind, Darken, and stepping on leaves Behind.
/// steps Normal, Dissolve, Behind, Darken, and stepping on leaves Behind. On a pixel layer: on the
/// Background Behind is greyed and the wheel passes it.
#[test]
fn the_pattern_stamp_mode_dropdown_has_behind() {
let mut h = harness(Tool::PatternStamp);
h.state_mut().run("layer.new.layer", json!({})).unwrap();
h.run_steps(4);
let at = mode_dropdown(&h).center();
wheel(&mut h, at, -1.0);
assert_eq!(brush_mode(&h), BlendMode::Dissolve);
+8 -3
View File
@@ -38,10 +38,15 @@ pub(super) fn paint_mode_dropdown(ui: &mut egui::Ui, id: &str, b: &mut photocraf
/// The Pattern Stamp's Mode dropdown: the blend modes with Behind after Dissolve and no Clear, as
/// the reference application lists them (#12879). Behind is the tool's own brush's, as its mode;
/// picking another mode leaves it. The wheel steps it as it steps the other Mode dropdowns.
pub(super) fn pattern_stamp_mode_dropdown(ui: &mut egui::Ui, id: &str, b: &mut photocraft_engine::BrushSettings) {
/// Without `behind_enabled` (the Background is the active layer) Behind is greyed, as in the
/// Shift+right-click menu, and the wheel and the keys step past it.
pub(super) fn pattern_stamp_mode_dropdown(ui: &mut egui::Ui, id: &str, b: &mut photocraft_engine::BrushSettings, behind_enabled: bool) {
let opts = crate::brush_mode_menu::pattern_stamp_choices();
let mut mode = if b.behind { (None, true) } else { (Some(b.mode), false) };
if !widgets::dropdown_wheel_grouped(ui, id, tl!("Mode"), &mut mode, &opts, 96.0, |m| m.0.is_some_and(starts_blend_group)).0.is_empty() {
let before = if b.behind { (None, true) } else { (Some(b.mode), false) };
let mut mode = before;
let groups = |m: &(Option<BlendMode>, bool)| m.0.is_some_and(starts_blend_group);
if !widgets::dropdown_wheel_grouped_enabled(ui, id, tl!("Mode"), &mut mode, &opts, 96.0, groups, |m| behind_enabled || !m.1).0.is_empty() {
let mode = crate::brush_mode_menu::pattern_stamp_pick(before, mode, behind_enabled);
b.behind = mode.1;
b.mode = mode.0.unwrap_or(BlendMode::Normal);
}
+3 -2
View File
@@ -139,9 +139,10 @@ pub fn options_bar(app: &mut PhotocraftApp, ui: &mut egui::Ui) {
let mut brush = before.clone();
// Mode is the tool's own brush's, kept per tool like its size.
if tool == Tool::PatternStamp {
// Its list has Behind (#12879).
// Its list has Behind, greyed on the Background (#12879).
opt_label(ui, tl!("Mode"));
super::brush_controls::pattern_stamp_mode_dropdown(ui, "retouch-mode", &mut brush);
let behind = crate::brush_mode_menu::enabled(app, crate::brush_mode_menu::Item::Behind);
super::brush_controls::pattern_stamp_mode_dropdown(ui, "retouch-mode", &mut brush, behind);
} else if let Some(modes) = crate::blend_keys::tool_modes(tool) {
opt_label(ui, tl!("Mode"));
if let Some(Some(m)) =
@@ -7,7 +7,7 @@ use egui::{Context, Event, Key, Modifiers, RawInput};
use photocraft_doc::BlendMode;
use serde_json::{Value, json};
use super::{Item, current, enabled, engine_call, items, labels, pattern_stamp_choices};
use super::{Item, current, enabled, engine_call, items, labels, pattern_stamp_choices, pattern_stamp_pick};
use crate::PhotocraftApp;
use crate::control::{ControlRequest, Outcome, handle};
use crate::state::Tool;
@@ -233,3 +233,106 @@ fn a_behind_stroke_paints_only_the_transparent_half() {
assert_ne!(pixel(&app, 16, 32), red, "aligned {aligned}: Normal paints over");
}
}
/// The whole app drawn, with the Pattern Stamp on a new document; with `layer`, on a transparent
/// layer above the Background.
fn harness(layer: bool) -> egui_kittest::Harness<'static, PhotocraftApp> {
let mut h = egui_kittest::Harness::builder().with_size(egui::vec2(1440.0, 900.0)).with_max_steps(64).build_eframe(move |cc| {
PhotocraftApp::setup_context(&cc.egui_ctx, Default::default());
let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default());
app.run("file.new", json!({"width": 64, "height": 48})).unwrap();
if layer {
app.run("layer.new.layer", json!({})).unwrap();
}
app.ui.tool = Tool::PatternStamp;
app
});
h.run_steps(8);
h
}
/// The options bar's Mode dropdown: the highest one showing `Normal` (the Layers panel's is lower).
fn mode_dropdown(h: &egui_kittest::Harness<'_, PhotocraftApp>) -> egui::Rect {
use egui_kittest::kittest::Queryable;
h.query_all_by_role(egui::accesskit::Role::ComboBox)
.filter(|n| n.value().as_deref() == Some("Normal"))
.map(|n| n.rect())
.min_by(|a, b| a.top().total_cmp(&b.top()))
.unwrap()
}
/// Opens the options bar's Mode dropdown with a click.
fn open_dropdown(h: &mut egui_kittest::Harness<'_, PhotocraftApp>) {
use egui_kittest::kittest::Queryable;
let top = mode_dropdown(h).top();
h.query_all_by_role(egui::accesskit::Role::ComboBox).find(|n| n.value().as_deref() == Some("Normal") && n.rect().top() == top).unwrap().click();
h.run_steps(4);
}
/// One wheel notch down (the next mode) over the point `at`.
fn wheel_down(h: &mut egui_kittest::Harness<'_, PhotocraftApp>, at: egui::Pos2) {
h.hover_at(at);
h.run_steps(1);
h.event(Event::MouseWheel {
source: egui::MouseWheelSource::Unknown,
unit: egui::MouseWheelUnit::Line,
delta: egui::vec2(0.0, -1.0),
phase: egui::TouchPhase::Move,
modifiers: Default::default(),
});
h.run_steps(3);
}
/// On the Background the options bar's dropdown greys Behind: the row is disabled, a click on it
/// picks nothing, and the wheel steps from Dissolve straight to Darken.
#[test]
fn the_options_bar_dropdown_greys_behind_on_the_background() {
use egui_kittest::kittest::{NodeT, Queryable};
let mut h = harness(false);
let at = mode_dropdown(&h).center();
open_dropdown(&mut h);
assert!(h.get_by_label("Behind").accesskit_node().is_disabled(), "Behind is greyed");
assert!(!h.get_by_label("Dissolve").accesskit_node().is_disabled());
assert!(!h.get_by_label("Darken").accesskit_node().is_disabled());
let n = h.state().session.journal.len();
h.get_by_label("Behind").click();
h.run_steps(4);
assert_eq!(h.state().session.journal.len(), n, "a greyed entry picks nothing");
assert!(!h.state().session.tools.brush.behind);
assert_eq!(h.state().session.tools.brush.mode, BlendMode::Normal);
// The wheel passes it.
let mut h = harness(false);
wheel_down(&mut h, at);
assert_eq!(h.state().session.tools.brush.mode, BlendMode::Dissolve);
wheel_down(&mut h, at);
assert!(!h.state().session.tools.brush.behind, "the wheel steps past the greyed Behind");
assert_eq!(h.state().session.tools.brush.mode, BlendMode::Darken);
}
/// On a pixel layer the dropdown's Behind is enabled and a click picks it.
#[test]
fn the_options_bar_dropdown_offers_behind_on_a_pixel_layer() {
use egui_kittest::kittest::{NodeT, Queryable};
let mut h = harness(true);
open_dropdown(&mut h);
assert!(!h.get_by_label("Behind").accesskit_node().is_disabled(), "Behind is enabled");
h.get_by_label("Behind").click();
h.run_steps(4);
assert!(h.state().session.tools.brush.behind, "picked");
assert_eq!(current(h.state(), Tool::PatternStamp), Some(Item::Behind));
}
/// What a pick stores: Behind when it is enabled; with it greyed, the mode one step further the
/// same way, whichever way the wheel or a key came.
#[test]
fn a_pick_that_lands_on_a_greyed_behind_steps_on() {
let (normal, dissolve, behind, darken) =
((Some(BlendMode::Normal), false), (Some(BlendMode::Dissolve), false), (None, true), (Some(BlendMode::Darken), false));
assert_eq!(pattern_stamp_pick(dissolve, behind, true), behind);
assert_eq!(pattern_stamp_pick(dissolve, behind, false), darken, "down");
assert_eq!(pattern_stamp_pick(normal, behind, false), darken, "two notches down");
assert_eq!(pattern_stamp_pick(darken, behind, false), dissolve, "up");
assert_eq!(pattern_stamp_pick(normal, darken, false), darken, "other modes are picked as they are");
// Behind chosen earlier on a pixel layer stays until another mode is picked.
assert_eq!(pattern_stamp_pick(behind, dissolve, false), dissolve);
}
+2 -1
View File
@@ -44,7 +44,8 @@ pub use color::{
#[cfg(test)]
use color::{checker_tile_id, checker_uv};
pub use dropdown::{
combo_list, dropdown, dropdown_hovered, dropdown_literal, dropdown_wheel_grouped, dropdown_wheel_hovered, dropdown_with_tooltips, menu_scroll, swatch_popup,
combo_list, dropdown, dropdown_hovered, dropdown_literal, dropdown_wheel_grouped, dropdown_wheel_grouped_enabled, dropdown_wheel_hovered,
dropdown_with_tooltips, menu_scroll, swatch_popup,
};
pub(crate) use fields::compact_wrapping_value_field;
#[cfg(test)]
+32 -5
View File
@@ -11,13 +11,13 @@ pub fn dropdown<T: PartialEq + Clone>(ui: &mut Ui, id: &str, name: &str, current
/// [`dropdown`] whose option labels are shown exactly as given: names the user typed (a channel
/// or layer name) must not be translated, unlike the built-in labels [`dropdown`] translates (#5335).
pub fn dropdown_literal<T: PartialEq + Clone>(ui: &mut Ui, id: &str, name: &str, current: &mut T, options: &[(T, &str)], width: f32) -> bool {
let (chosen, _) = dropdown_with(ui, id, name, current, options, width, false, false, &|_| false);
let (chosen, _) = dropdown_with(ui, id, name, current, options, width, false, false, &|_| false, &|_| true);
!chosen.is_empty()
}
/// [`dropdown`], also returning the option under the pointer in its open list (live previews).
pub fn dropdown_hovered<T: PartialEq + Clone>(ui: &mut Ui, id: &str, name: &str, current: &mut T, options: &[(T, &str)], width: f32) -> (bool, Option<T>) {
let (chosen, hovered) = dropdown_with(ui, id, name, current, options, width, false, true, &|_| false);
let (chosen, hovered) = dropdown_with(ui, id, name, current, options, width, false, true, &|_| false, &|_| true);
(!chosen.is_empty(), hovered)
}
@@ -35,7 +35,7 @@ pub fn dropdown_wheel_hovered<T: PartialEq + Clone>(
options: &[(T, &str)],
width: f32,
) -> (Vec<T>, Option<T>) {
dropdown_with(ui, id, name, current, options, width, true, true, &|_| false)
dropdown_with(ui, id, name, current, options, width, true, true, &|_| false, &|_| true)
}
/// [`dropdown_wheel_hovered`] whose open list draws a line above each option (but the first) that
@@ -50,7 +50,24 @@ pub fn dropdown_wheel_grouped<T: PartialEq + Clone>(
width: f32,
starts_group: impl Fn(&T) -> bool,
) -> (Vec<T>, Option<T>) {
dropdown_with(ui, id, name, current, options, width, true, true, &starts_group)
dropdown_with(ui, id, name, current, options, width, true, true, &starts_group, &|_| true)
}
/// [`dropdown_wheel_grouped`] whose open list greys the options `enabled` refuses: drawn disabled,
/// not picked by the pointer and not previewed. The wheel and the keys still land on them; the
/// caller steps past (#12879, the Pattern Stamp's Behind on the Background).
#[allow(clippy::too_many_arguments)]
pub fn dropdown_wheel_grouped_enabled<T: PartialEq + Clone>(
ui: &mut Ui,
id: &str,
name: &str,
current: &mut T,
options: &[(T, &str)],
width: f32,
starts_group: impl Fn(&T) -> bool,
enabled: impl Fn(&T) -> bool,
) -> (Vec<T>, Option<T>) {
dropdown_with(ui, id, name, current, options, width, true, true, &starts_group, &enabled)
}
#[allow(clippy::too_many_arguments)]
@@ -64,6 +81,7 @@ fn dropdown_with<T: PartialEq + Clone>(
wheel: bool,
translate: bool,
starts_group: &dyn Fn(&T) -> bool,
enabled: &dyn Fn(&T) -> bool,
) -> (Vec<T>, Option<T>) {
let shown = |l: &str| if translate { tl!(l).to_string() } else { l.to_string() };
let label = options.iter().find(|(v, _)| v == current).map(|(_, l)| shown(l)).unwrap_or_else(|| "—".into());
@@ -105,10 +123,19 @@ fn dropdown_with<T: PartialEq + Clone>(
if i > 0 && starts_group(v) {
list_separator(ui);
}
let item = ui.selectable_label(v == current, text.as_str());
let on = enabled(v);
let item = if on {
ui.selectable_label(v == current, text.as_str())
} else {
ui.add_enabled(false, egui::Button::selectable(v == current, text.as_str()))
};
if reveal && v == current {
item.scroll_to_me(None);
}
// A greyed option is neither previewed nor picked.
if !on {
continue;
}
if item.hovered() {
hovered = Some(v.clone());
}