fix(ui): Shift plus a digit sets the Pencil's Opacity (#11967)

This commit is contained in:
rmsff committed 2026-11-09 13:12:54 +03:00
1 parent d06ad73271
commit 248f65d577
3 files changed
+89 -2

No files matched your search

+4 -2
View File
@@ -1,6 +1,7 @@
//! Number keys set opacity (#352): 1 = 10% … 9 = 90%, 0 = 100%; two digits
//! typed quickly set an exact value (4 then 5 = 45%; 0 then 0 = 100% for the Brush and the Pencil, #11812). With the Brush, Pencil or
//! Eraser they set the brush's Opacity (⇧: Flow; swapped while airbrush build-up is on); with the Gradient or Paint Bucket their
//! Eraser they set the brush's Opacity (⇧: Flow, swapped while airbrush build-up is on; the Pencil has no Flow, so its ⇧
//! digits set Opacity too, #11967); with the Gradient or Paint Bucket their
//! Opacity; with tools that have no opacity of their own (Move, the selection tools, Type…) the
//! active layer's Opacity (⇧: Fill); with the Background Eraser its Tolerance (#11907). Tools whose
//! number is a strength or exposure are left alone.
@@ -110,7 +111,8 @@ fn apply(app: &mut PhotocraftApp, percent: f32, shift: bool) {
let build_up = app.session.tools.brush.build_up && !crate::eraser_ui::pencil_mode(app, tool) && !crate::eraser_ui::block_mode(app, tool);
let shift = shift ^ (build_up && matches!(target(tool), Target::Brush { flow: true }));
match (target(app.ui.tool), shift) {
(Target::Brush { .. }, false) => {
// The Pencil has no Flow: its ⇧ digits set Opacity like the plain ones (#11967).
(Target::Brush { flow: false }, _) | (Target::Brush { flow: true }, false) => {
// The painting tools' Opacity fields (and `tools.setBrush`) start at 1%, so `00` sets the
// 1% they actually paint with rather than a 0% they can't do. The Brush's and the
// Pencil's `00` is 100%, as in Photoshop (#11812); only `00` gives 0 here.
+4
View File
@@ -1037,6 +1037,10 @@ mod artboard_options_bar_tests;
mod background_eraser_bar_angle_tests;
#[cfg(test)]
mod brush_opacity_minimum_tests;
#[cfg(test)]
mod pencil_shift_digit_opacity_tests;
#[cfg(test)]
mod doc_tab_menu_tests;
#[cfg(test)]
@@ -0,0 +1,81 @@
//! #11967: the Pencil has no Flow, so ⇧ plus a digit sets its Opacity as a plain digit does
//! (⇧3 = 30%, ⇧0 = 100%, two quick ⇧ digits an exact value). The Brush's ⇧ digits still set Flow,
//! swapped with Opacity while airbrush build-up is on.
use serde_json::json;
use crate::PhotocraftApp;
use crate::opacity_keys::press;
use crate::state::Tool;
fn app(tool: Tool) -> PhotocraftApp {
let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), Default::default());
app.run("file.new", json!({"width": 32, "height": 32})).unwrap();
app.run("layer.new.layer", json!({})).unwrap();
app.ui.tool = tool;
app
}
/// The brush settings' (opacity, flow) in percent.
fn brush(app: &PhotocraftApp) -> (f32, f32) {
let b = &app.session.tools.brush;
((b.opacity * 100.0).round(), (b.flow * 100.0).round())
}
#[test]
fn shift_digits_set_the_pencils_opacity() {
let mut a = app(Tool::Pencil);
let flow = brush(&a).1;
press(&mut a, 3, true, 0.0);
assert_eq!(brush(&a), (30.0, flow), "⇧3");
press(&mut a, 0, true, 5000.0);
assert_eq!(brush(&a), (100.0, flow), "⇧0");
for d in 1..=9u8 {
press(&mut a, d, true, 10000.0 * f64::from(d));
assert_eq!(brush(&a), (f32::from(d) * 10.0, flow), "⇧{d}");
}
}
#[test]
fn two_quick_shift_digits_set_an_exact_opacity() {
let mut a = app(Tool::Pencil);
press(&mut a, 4, true, 0.0);
press(&mut a, 5, true, 300.0);
assert_eq!(brush(&a).0, 45.0);
press(&mut a, 0, true, 5000.0);
press(&mut a, 7, true, 5300.0);
assert_eq!(brush(&a).0, 7.0);
// As a plain `00`, which is 100 % for the Pencil (#11812). Joined, typed slowly or with the
// second press ignored, ⇧0 ⇧0 ends at 100 % either way.
press(&mut a, 0, true, 10000.0);
press(&mut a, 0, true, 10300.0);
assert_eq!(brush(&a).0, 100.0);
}
/// No digit, plain or ⇧, ever changes the Flow while the Pencil is active, build-up on or off.
#[test]
fn the_pencils_flow_stays_untouched() {
for build_up in [false, true] {
let mut a = app(Tool::Pencil);
a.run("tools.setBrush", json!({"brush": {"flow": 0.42}})).unwrap();
a.session.tools.brush.build_up = build_up;
for (i, (d, shift)) in [(3, true), (6, false), (0, true), (8, false)].into_iter().enumerate() {
press(&mut a, d, shift, 10000.0 * i as f64);
assert_eq!(brush(&a).1, 42.0, "build-up {build_up}, digit {d}, ⇧ {shift}");
assert_eq!(a.session.tools.brush.build_up, build_up, "the case under test holds");
}
assert_eq!(brush(&a).0, 80.0, "build-up {build_up}: the last digit set the Opacity");
}
}
#[test]
fn the_brushs_shift_digits_still_set_flow() {
let mut a = app(Tool::Brush);
press(&mut a, 3, true, 0.0);
assert_eq!(brush(&a), (100.0, 30.0), "⇧3 is Flow");
// With airbrush build-up the roles swap: ⇧ digits set Opacity, plain ones Flow.
a.session.tools.brush.build_up = true;
press(&mut a, 6, true, 5000.0);
press(&mut a, 2, false, 10000.0);
assert_eq!(brush(&a), (60.0, 20.0));
}