Merge pull request #17821

This commit is contained in:
autocraft-bot[bot] committed 2026-12-01 15:26:27 +00:00
commit 4bdf68a577
2 files changed
+74 -1

No files matched your search

+12 -1
View File
@@ -117,7 +117,14 @@ fn apply(app: &mut PhotocraftApp, percent: f32, shift: bool) {
(Target::Brush { flow: true }, true) => {
let _ = app.run("tools.setBrush", json!({ "brush": { "flow": v.max(0.01) } }));
}
(Target::ToolOpacity, false) => app.ui.tool_options.fill_opacity = percent,
// The field starts at 1%. The Paint Bucket's `00` is 100%, as the Brush's is (#17742); the
// Gradient's was not measured, so it keeps the 1% the field can hold.
(Target::ToolOpacity, false) => {
app.ui.tool_options.fill_opacity = match tool {
Tool::PaintBucket if percent <= 0.0 => 100.0,
_ => percent.max(1.0),
}
}
// The Tolerance field starts at 1%; `00` (0%) keeps today's value rather than guessing.
(Target::BgTolerance, false) if percent >= 1.0 => app.ui.tool_options.bg_tolerance = percent,
// The field starts at 1%; an unmeasured 00 keeps its existing value.
@@ -137,6 +144,10 @@ fn apply(app: &mut PhotocraftApp, percent: f32, shift: bool) {
}
}
#[cfg(test)]
#[path = "opacity_keys_bucket_double_zero_tests.rs"]
mod bucket_double_zero_tests;
#[cfg(test)]
mod tests {
use super::*;
@@ -0,0 +1,62 @@
//! The Paint Bucket's number keys: `0`, `0` typed quickly is 100 %, never the 0 % its Opacity field can't hold (#17742).
use craft::ui::canvas::OpacityDigit as D;
use serde_json::json;
use super::fired;
use crate::PhotocraftApp;
use crate::blend_keys::test_fired;
use crate::state::Tool;
const DIGITS: [D; 10] = [
D::OpacityZero,
D::OpacityOne,
D::OpacityTwo,
D::OpacityThree,
D::OpacityFour,
D::OpacityFive,
D::OpacitySix,
D::OpacitySeven,
D::OpacityEight,
D::OpacityNine,
];
/// The tool's Opacity after typing `digits` 0.1 s apart, from a start of 50 %.
fn typed(tool: Tool, digits: &[usize]) -> f32 {
let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), Default::default());
app.run("file.new", json!({"width": 16, "height": 16})).unwrap();
app.ui.tool = tool;
app.ui.tool_options.fill_opacity = 50.0;
for (i, d) in digits.iter().enumerate() {
let mut f = test_fired(DIGITS[*d].into());
f.time = i as f64 * 0.1;
assert!(fired(&mut app, &f), "{tool:?} takes digit {d}");
}
app.ui.tool_options.fill_opacity
}
#[test]
fn paint_bucket_double_zero_is_full_opacity() {
assert_eq!(typed(Tool::PaintBucket, &[0, 0]), 100.0);
}
#[test]
fn no_digits_leave_the_shared_opacity_below_its_minimum() {
// The Gradient shares the Paint Bucket's Opacity field, which starts at 1 %.
for tool in [Tool::PaintBucket, Tool::Gradient] {
for digits in [&[0, 0][..], &[0], &[0, 1], &[1, 0], &[5, 0]] {
let got = typed(tool, digits);
assert!(got >= 1.0, "{tool:?} {digits:?}: {got}");
}
}
}
#[test]
fn paint_bucket_other_digits_keep_their_values() {
for d in 1..=9 {
assert_eq!(typed(Tool::PaintBucket, &[d]), d as f32 * 10.0, "{d}");
}
for (digits, want) in [(&[0][..], 100.0), (&[4, 5], 45.0), (&[0, 5], 5.0)] {
assert_eq!(typed(Tool::PaintBucket, digits), want, "{digits:?}");
}
}