mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-03 06:31:42 +01:00
Merge pull request #18216
Co-authored-by: autocraft-bot[bot] <354215646+autocraft-bot[bot]@users.noreply.github.com>
This commit is contained in:
commit
412085a7ca
3 files changed
+158
-2
No files matched your search
@@ -362,6 +362,11 @@ real_name = "Sven Lafebre"
|
||||
[people.kirubhakaran12]
|
||||
sync_github_name = true
|
||||
|
||||
[people.qvest-ssels]
|
||||
real_name = "Stefan Sels"
|
||||
display_name = "tronicum"
|
||||
sync_github_name = false
|
||||
|
||||
[people.MMexicann]
|
||||
display_name = "mexicann"
|
||||
|
||||
|
||||
@@ -92,6 +92,30 @@ pub(crate) const PAINT_BUCKET_OPACITY_ALERT: &str = "An integer between 1% and 1
|
||||
/// the framework's wording of a whole-number range without a unit.
|
||||
pub(crate) const PAINT_BUCKET_TOLERANCE_ALERT: &str = "An integer between 0 and 255 is required. Closest value inserted.";
|
||||
|
||||
/// Whether the active document is in Indexed Color mode, where the Paint Bucket's bar reads Threshold and greys
|
||||
/// Anti-alias (#17748).
|
||||
fn bucket_indexed(app: &PhotocraftApp) -> bool {
|
||||
app.session.active().is_some_and(|st| st.doc.mode == photocraft_doc::ColorMode::Indexed)
|
||||
}
|
||||
|
||||
/// The Paint Bucket's Mode list. In an Indexed Color document Normal reads "Threshold" and only Threshold and
|
||||
/// Dissolve are enabled, Behind and Clear greyed too, as the reference shows it; the stored mode is unchanged
|
||||
/// (#17748). Other modes keep the list as it was.
|
||||
pub(crate) fn bucket_mode_entries(app: &PhotocraftApp) -> Vec<Entry<PaintMode>> {
|
||||
let indexed = bucket_indexed(app);
|
||||
let entries = mode_entries(Tool::PaintBucket, crate::brush_mode_menu::enabled(app, crate::brush_mode_menu::Item::Behind), indexed);
|
||||
if !indexed {
|
||||
return entries;
|
||||
}
|
||||
entries
|
||||
.into_iter()
|
||||
.map(|entry| match entry.value() {
|
||||
Some(PaintMode::Blend(BlendMode::Normal | BlendMode::Dissolve)) | None => entry,
|
||||
Some(_) => entry.enabled(false),
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// The Paint Bucket's members: Fill source, Mode, Opacity, Tolerance, Anti-alias, Contiguous and All Layers. Opacity
|
||||
/// takes whole percents 1..100 and Tolerance whole numbers 0..255; a value typed past either range becomes the
|
||||
/// closest one with the reference's alert, as does a fraction typed in Tolerance; a fraction typed in Opacity rounds
|
||||
@@ -100,7 +124,8 @@ pub(super) fn members(app: &mut PhotocraftApp, ui: &mut egui::Ui) {
|
||||
if app.ui.tool != Tool::PaintBucket {
|
||||
return;
|
||||
}
|
||||
let entries = mode_entries(Tool::PaintBucket, crate::brush_mode_menu::enabled(app, crate::brush_mode_menu::Item::Behind), false);
|
||||
let indexed = bucket_indexed(app);
|
||||
let entries = bucket_mode_entries(app);
|
||||
let sources = [Entry::new(false, tl!("Foreground").to_owned()), Entry::new(true, tl!("Pattern").to_owned())];
|
||||
// The Source dropdown stands alone, without a caption, as in the reference.
|
||||
Select::new(tl!("Source").to_owned(), bind_tracked!(app.ui.tool_options => bucket_fill_pattern), &sources)
|
||||
@@ -149,7 +174,8 @@ pub(super) fn members(app: &mut PhotocraftApp, ui: &mut egui::Ui) {
|
||||
.tooltip(tl!("Range of colors to fill"))
|
||||
.show(ui);
|
||||
let (anti_alias, contiguous, all_layers) = bind_tracked!(app.ui.tool_options => anti_alias, contiguous, sample_all.paint_bucket);
|
||||
Checkbox::new(anti_alias).label(tl!("Anti-alias").to_owned()).tooltip(tl!("Smoothes edge transition").to_owned()).show(ui);
|
||||
// An Indexed Color document greys Anti-alias and keeps its checked state (#17748).
|
||||
Checkbox::new(anti_alias).label(tl!("Anti-alias").to_owned()).tooltip(tl!("Smoothes edge transition").to_owned()).enabled(!indexed).show(ui);
|
||||
Checkbox::new(contiguous).label(tl!("Contiguous").to_owned()).tooltip(tl!("Fill only contiguous pixels").to_owned()).show(ui);
|
||||
Checkbox::new(all_layers).label(tl!("All Layers").to_owned()).tooltip(tl!("Fill composite image").to_owned()).show(ui);
|
||||
if opacity.is_some() {
|
||||
@@ -162,3 +188,7 @@ pub(super) fn members(app: &mut PhotocraftApp, ui: &mut egui::Ui) {
|
||||
let _ = crate::dialogs::alerts::alert(app, tl!(PAINT_BUCKET_TOLERANCE_ALERT));
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "paint_bucket_indexed_bar_tests.rs"]
|
||||
mod paint_bucket_indexed_bar_tests;
|
||||
@@ -0,0 +1,121 @@
|
||||
//! #17748: in an Indexed Color document the Paint Bucket's Mode reads "Threshold" with only Threshold and Dissolve
|
||||
//! enabled, and Anti-alias keeps its checked state greyed. Opacity, Tolerance and Contiguous stay enabled; RGB, CMYK,
|
||||
//! Lab and Grayscale documents keep today's bar.
|
||||
|
||||
use egui::accesskit::Role;
|
||||
use egui_kittest::kittest::{NodeT, Queryable};
|
||||
use egui_kittest::{Harness, Node};
|
||||
use photocraft_doc::BlendMode;
|
||||
use serde_json::json;
|
||||
|
||||
use super::bucket_mode_entries;
|
||||
use crate::PhotocraftApp;
|
||||
use crate::options_bar_mode_wheel_tests::harness;
|
||||
use crate::panels::options_bar::paint::PaintMode;
|
||||
use crate::state::Tool;
|
||||
|
||||
const INDEXED: &str = "image.mode.indexedColor";
|
||||
|
||||
/// The Paint Bucket in a new RGB document; `convert` runs a mode command on it first.
|
||||
fn bar(convert: Option<(&str, serde_json::Value)>) -> Harness<'static, Box<PhotocraftApp>> {
|
||||
let mut h = harness(Tool::PaintBucket);
|
||||
if let Some((id, params)) = convert {
|
||||
h.state_mut().run(id, params).unwrap();
|
||||
}
|
||||
h.run_steps(4);
|
||||
h
|
||||
}
|
||||
|
||||
fn indexed() -> Harness<'static, Box<PhotocraftApp>> {
|
||||
bar(Some((INDEXED, json!({"palette": "exact", "forced": "none", "dither": "none"}))))
|
||||
}
|
||||
|
||||
/// The Mode list as (label, enabled), a separator as "|".
|
||||
fn rows(app: &PhotocraftApp) -> Vec<(String, bool)> {
|
||||
bucket_mode_entries(app).iter().map(|e| if e.is_separator() { ("|".into(), false) } else { (e.label().as_str().to_owned(), e.is_enabled()) }).collect()
|
||||
}
|
||||
|
||||
/// The options bar's control named `name` ("Opacity:" in the Photoshop-look themes).
|
||||
fn control<'a>(h: &'a Harness<'_, Box<PhotocraftApp>>, role: Role, name: &str) -> Node<'a> {
|
||||
h.query_all_by_role(role).find(|n| n.accesskit_node().label().is_some_and(|l| l.trim_end_matches(':') == name)).unwrap_or_else(|| panic!("{name}"))
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn indexed_mode_list_reads_threshold_with_only_threshold_and_dissolve_enabled() {
|
||||
let h = indexed();
|
||||
let rows = rows(h.state());
|
||||
let labels: Vec<&str> = rows.iter().map(|(l, _)| l.as_str()).collect();
|
||||
assert_eq!(
|
||||
labels,
|
||||
[
|
||||
"Threshold",
|
||||
"Dissolve",
|
||||
"Behind",
|
||||
"Clear",
|
||||
"|",
|
||||
"Darken",
|
||||
"Multiply",
|
||||
"Color Burn",
|
||||
"Linear Burn",
|
||||
"Darker Color",
|
||||
"|",
|
||||
"Lighten",
|
||||
"Screen",
|
||||
"Color Dodge",
|
||||
"Linear Dodge (Add)",
|
||||
"Lighter Color",
|
||||
"|",
|
||||
"Overlay",
|
||||
"Soft Light",
|
||||
"Hard Light",
|
||||
"Vivid Light",
|
||||
"Linear Light",
|
||||
"Pin Light",
|
||||
"Hard Mix",
|
||||
"|",
|
||||
"Difference",
|
||||
"Exclusion",
|
||||
"Subtract",
|
||||
"Divide",
|
||||
"|",
|
||||
"Hue",
|
||||
"Saturation",
|
||||
"Color",
|
||||
"Luminosity"
|
||||
]
|
||||
);
|
||||
let enabled: Vec<&str> = rows.iter().filter(|(_, on)| *on).map(|(l, _)| l.as_str()).collect();
|
||||
assert_eq!(enabled, ["Threshold", "Dissolve"]);
|
||||
let shown = h.query_all_by_role(Role::ComboBox).find(|n| n.value().as_deref() == Some("Threshold"));
|
||||
assert!(shown.is_some(), "the Mode dropdown reads Threshold");
|
||||
let o = &h.state().ui.tool_options;
|
||||
assert_eq!((o.bucket_blend_mode, o.bucket_behind, o.bucket_clear), (BlendMode::Normal, false, false), "the stored mode stays Normal");
|
||||
assert!(bucket_mode_entries(h.state()).iter().any(|e| e.value() == Some(&PaintMode::Blend(BlendMode::Normal))));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn indexed_greys_anti_alias_and_keeps_the_other_controls() {
|
||||
let h = indexed();
|
||||
assert!(h.state().ui.tool_options.anti_alias, "Anti-alias keeps its checked state");
|
||||
let aa = control(&h, Role::CheckBox, "Anti-alias");
|
||||
assert!(aa.accesskit_node().is_disabled(), "Anti-alias is greyed");
|
||||
assert!(!control(&h, Role::CheckBox, "Contiguous").accesskit_node().is_disabled());
|
||||
for name in ["Opacity", "Tolerance"] {
|
||||
let node = h.query_all_by_label_contains(name).next().unwrap_or_else(|| panic!("{name}"));
|
||||
assert!(!node.accesskit_node().is_disabled(), "{name} stays enabled");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn other_modes_keep_the_bar() {
|
||||
let cases: [Option<(&str, serde_json::Value)>; 4] =
|
||||
[None, Some(("image.mode.cmyk", json!({}))), Some(("image.mode.lab", json!({}))), Some(("image.mode.grayscale", json!({})))];
|
||||
for convert in cases {
|
||||
let what = format!("{convert:?}");
|
||||
let h = bar(convert);
|
||||
let rows = rows(h.state());
|
||||
assert_eq!(rows.first().map(|(l, _)| l.as_str()), Some("Normal"), "{what}");
|
||||
assert!(rows.iter().filter(|(l, _)| l != "|" && l != "Behind" && l != "Clear").all(|(_, on)| *on), "{what}: every blend mode enabled");
|
||||
assert!(!control(&h, Role::CheckBox, "Anti-alias").accesskit_node().is_disabled(), "{what}: Anti-alias enabled");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user