From f7c9cfd47551147c230ed572b9f0573f5318c724 Mon Sep 17 00:00:00 2001 From: qvest-ssels <214787280+qvest-ssels@users.noreply.github.com> Date: Sun, 29 Nov 2026 21:14:27 +0100 Subject: [PATCH] Paint Bucket: Shift plus a number key sets its Opacity (#17743) The Paint Bucket has no Flow, so its Shift+digits now set Opacity as the plain digits do: Shift+3 is 30 %, Shift+0 100 %, and two fast Shift digits a two-digit value. The Gradient's Shift digits (not measured) and the tools with a Flow keep their behaviour. --- crates/ui-egui/src/input/opacity_keys.rs | 6 ++ .../input/opacity_keys_bucket_shift_tests.rs | 94 +++++++++++++++++++ 2 files changed, 100 insertions(+) create mode 100644 crates/ui-egui/src/input/opacity_keys_bucket_shift_tests.rs diff --git a/crates/ui-egui/src/input/opacity_keys.rs b/crates/ui-egui/src/input/opacity_keys.rs index 0473abe2f3..9af03225bd 100644 --- a/crates/ui-egui/src/input/opacity_keys.rs +++ b/crates/ui-egui/src/input/opacity_keys.rs @@ -99,6 +99,8 @@ fn apply(app: &mut PhotocraftApp, percent: f32, shift: bool) { let tool = app.ui.tool; 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 })); + // The Paint Bucket has no Flow: its ⇧ digits set Opacity like the plain ones (#17743). + let shift = shift && tool != Tool::PaintBucket; match (target(app.ui.tool), shift) { // The Pencil has no Flow: its ⇧ digits set Opacity like the plain ones (#11967). (Target::Brush { flow: false }, _) | (Target::Brush { flow: true }, false) => { @@ -342,3 +344,7 @@ mod tests { assert!(h.state().session.tools.brush.size > size, "] still resizes"); } } + +#[cfg(test)] +#[path = "opacity_keys_bucket_shift_tests.rs"] +mod bucket_shift_tests; diff --git a/crates/ui-egui/src/input/opacity_keys_bucket_shift_tests.rs b/crates/ui-egui/src/input/opacity_keys_bucket_shift_tests.rs new file mode 100644 index 0000000000..1687b5f5c0 --- /dev/null +++ b/crates/ui-egui/src/input/opacity_keys_bucket_shift_tests.rs @@ -0,0 +1,94 @@ +//! #17743: the Paint Bucket has no Flow, so Shift plus a number key sets its Opacity as the plain +//! number keys do: Shift+3 is 30 %, Shift+0 100 %, and two fast Shift digits a two-digit value. +//! Plain digits and the tools with a Flow keep their behaviour. + +use craft::ui::canvas::OpacityDigit as D; +use craft::ui::runtime::commands::CommandRef; +use serde_json::json; + +use super::fired; +use crate::PhotocraftApp; +use crate::blend_keys::test_fired; +use crate::state::Tool; + +fn app(tool: Tool) -> Box { + 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.ui.tool_options.fill_opacity = 50.0; + app +} + +/// Fires `digit` at `now` seconds; whether the tool took it. +fn fire(app: &mut PhotocraftApp, digit: D, now: f64) -> bool { + let mut f = test_fired(CommandRef::from(digit)); + f.time = now; + fired(app, &f) +} + +#[test] +fn shift_digits_set_the_bucket_opacity() { + let rows = [(D::SecondOne, 10.0), (D::SecondThree, 30.0), (D::SecondFive, 50.0), (D::SecondNine, 90.0), (D::SecondZero, 100.0)]; + for (digit, want) in rows { + let mut a = app(Tool::PaintBucket); + a.ui.tool_options.fill_opacity = 42.0; + assert!(fire(&mut a, digit, 0.0), "{digit:?} is taken"); + assert_eq!(a.ui.tool_options.fill_opacity, want, "{digit:?}"); + } +} + +#[test] +fn two_fast_shift_digits_set_a_two_digit_bucket_opacity() { + let mut a = app(Tool::PaintBucket); + fire(&mut a, D::SecondTwo, 0.0); + fire(&mut a, D::SecondFive, 0.1); + assert_eq!(a.ui.tool_options.fill_opacity, 25.0); + // Slow ones are two single values. + fire(&mut a, D::SecondTwo, 5.0); + fire(&mut a, D::SecondFive, 10.0); + assert_eq!(a.ui.tool_options.fill_opacity, 50.0); +} + +#[test] +fn plain_bucket_digits_and_tools_with_a_flow_keep_their_behaviour() { + let mut a = app(Tool::PaintBucket); + fire(&mut a, D::OpacityThree, 0.0); + assert_eq!(a.ui.tool_options.fill_opacity, 30.0, "plain 3"); + fire(&mut a, D::OpacityFour, 5.0); + fire(&mut a, D::OpacityFive, 5.1); + assert_eq!(a.ui.tool_options.fill_opacity, 45.0, "plain 4 then 5"); + + // The Brush's Shift digits still set its Flow, not its Opacity or the bucket's. + let mut b = app(Tool::Brush); + b.run("tools.setBrush", json!({"brush": {"opacity": 1.0, "flow": 1.0}})).unwrap(); + fire(&mut b, D::SecondThree, 0.0); + let brush = &b.session.tools.brush; + assert_eq!((brush.opacity, brush.flow, b.ui.tool_options.fill_opacity), (1.0, 0.3, 50.0)); + + // The Gradient's Shift digits were not measured and still change nothing. + let mut g = app(Tool::Gradient); + fire(&mut g, D::SecondThree, 0.0); + assert_eq!(g.ui.tool_options.fill_opacity, 50.0); +} + +/// Through the whole app: Shift+3 on the canvas (no widget focused) sets the bucket's Opacity. +#[test] +fn shift_number_key_works_in_the_app() { + use egui::{Event, Key, Modifiers}; + use egui_kittest::Harness; + let mut h = Harness::builder().with_size(egui::vec2(1200.0, 800.0)).with_max_steps(64).build_eframe(|cc| { + PhotocraftApp::setup_context(&cc.egui_ctx, Default::default()); + let mut a = PhotocraftApp::with_context(cc.egui_ctx.clone(), photocraft_engine::Session::new(), Default::default()); + a.run("file.new", json!({"width": 32, "height": 32})).unwrap(); + a.ui.tool = Tool::PaintBucket; + a.ui.tool_options.fill_opacity = 50.0; + a + }); + h.run_steps(4); + for pressed in [true, false] { + h.event(Event::Key { key: Key::Num3, physical_key: Some(Key::Num3), pressed, repeat: false, modifiers: Modifiers::SHIFT }); + } + h.run_steps(2); + assert_eq!(h.state().ui.tool_options.fill_opacity, 30.0); +}