mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
Merge #17527 into the merge queue batch
Fill: Content-Aware is greyed in Contents without a selection (#17462)
This commit is contained in:
commit
509ddc847c
2 files changed
+94
-1
No files matched your search
@@ -43,8 +43,13 @@ pub(crate) fn hex(c: [f32; 3]) -> String {
|
||||
/// The dialog's rows, with the Preserve Transparency the target forces.
|
||||
fn rows(app: &PhotocraftApp, foreground: [f32; 3], first_pattern: Option<String>, preserve: Option<bool>) -> Vec<Param> {
|
||||
let contents = CONTENTS.iter().map(|(k, l)| (k.to_string(), Label::from(tl!(l)))).collect();
|
||||
let mut contents = Param::new("contents", tl!("Contents:"), ParamKind::choice(contents, Some("foreground".into())));
|
||||
// Content-Aware fills a selection from around it: without one it is listed greyed, as in the reference (#17462).
|
||||
if app.session.active().is_none_or(|st| st.doc.selection.is_none()) {
|
||||
contents = contents.disabled_options(["contentAware"]);
|
||||
}
|
||||
let mut rows = vec![
|
||||
Param::new("contents", tl!("Contents:"), ParamKind::choice(contents, Some("foreground".into()))),
|
||||
contents,
|
||||
Param::new("color", tl!("Color:"), ParamKind::color(Some(foreground))).visible_when("contents", "color"),
|
||||
Param::new("pattern", tl!("Custom Pattern:"), ParamKind::pattern(first_pattern)).visible_when("contents", "pattern"),
|
||||
Param::new("colorAdaptation", tl!("Color Adaptation"), ParamKind::bool(true)).visible_when("contents", "contentAware"),
|
||||
@@ -168,6 +173,8 @@ pub(crate) fn run(app: &mut PhotocraftApp, ctx: &egui::Context, result: ParamRes
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod content_aware_greyed_tests;
|
||||
#[cfg(test)]
|
||||
mod opacity_alert_tests;
|
||||
#[cfg(test)]
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
//! #17462: without a selection the Fill dialog's Contents list shows Content-Aware greyed (listed, never chosen); the
|
||||
//! other eight entries stay enabled in the same order. With a selection every entry is enabled.
|
||||
|
||||
use craft::ui::patterns::form_dialogs::HostedParamDialog;
|
||||
use serde_json::json;
|
||||
|
||||
use super::*;
|
||||
use crate::smart_filter_dialog::tests::cancel;
|
||||
|
||||
/// A white 40×30 document with a pixel layer "Paint" active, and a selection when `selected`.
|
||||
fn app(selected: bool) -> Box<PhotocraftApp> {
|
||||
let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), Default::default());
|
||||
app.run("file.new", json!({"width": 40, "height": 30, "background": "white"})).unwrap();
|
||||
app.run("layer.new.layer", json!({"name": "Paint"})).unwrap();
|
||||
if selected {
|
||||
app.run("select.rect", json!({"x": 5, "y": 5, "width": 20, "height": 15})).unwrap();
|
||||
}
|
||||
app
|
||||
}
|
||||
|
||||
/// The Contents row of the dialog `app` would open.
|
||||
fn contents_row(app: &PhotocraftApp) -> Param {
|
||||
rows(app, [0.0; 3], None, None).into_iter().find(|r| r.key == "contents").expect("a Contents row")
|
||||
}
|
||||
|
||||
/// The keys of a choice row, in order.
|
||||
fn keys(row: &Param) -> Vec<String> {
|
||||
let ParamKind::Choice { options, .. } = &row.kind else { panic!("Contents is a choice row") };
|
||||
options.iter().map(|(k, _)| k.clone()).collect()
|
||||
}
|
||||
|
||||
/// Whether the open dialog `id` takes `contents` set to `key`.
|
||||
fn choosable(app: &mut PhotocraftApp, id: DialogId, key: &str) -> bool {
|
||||
let ctx = app.ctx().clone();
|
||||
app.framework.dialogs.set_json_field(&ctx, id, "contents", json!(key)).is_ok()
|
||||
}
|
||||
|
||||
fn contents(app: &PhotocraftApp, id: DialogId) -> String {
|
||||
let dialog = app.framework.dialogs.get_by_id::<HostedParamDialog>(id).expect("a hosted dialog");
|
||||
dialog.fields().text("contents").expect("a Contents value").to_string()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn without_a_selection_content_aware_is_greyed_and_the_rest_enabled() {
|
||||
let app = app(false);
|
||||
let row = contents_row(&app);
|
||||
let order: Vec<String> = CONTENTS.iter().map(|(k, _)| k.to_string()).collect();
|
||||
assert_eq!(keys(&row), order, "every entry listed, in the same order");
|
||||
for (key, _) in CONTENTS {
|
||||
assert_eq!(row.option_enabled(key), key != "contentAware", "{key}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn with_a_selection_every_entry_is_enabled() {
|
||||
let app = app(true);
|
||||
let row = contents_row(&app);
|
||||
for (key, _) in CONTENTS {
|
||||
assert!(row.option_enabled(key), "{key}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_open_dialog_refuses_content_aware_only_without_a_selection() {
|
||||
let mut app = app(false);
|
||||
let id = open(&mut app);
|
||||
assert!(!choosable(&mut app, id, "contentAware"), "greyed: cannot be chosen");
|
||||
assert_eq!(contents(&app, id), "foreground", "the choice is unchanged");
|
||||
for key in ["background", "pattern", "history", "black", "gray", "white", "foreground"] {
|
||||
assert!(choosable(&mut app, id, key), "{key} can be chosen");
|
||||
}
|
||||
cancel(&mut app, id);
|
||||
|
||||
app.run("select.rect", json!({"x": 5, "y": 5, "width": 20, "height": 15})).unwrap();
|
||||
let id = open(&mut app);
|
||||
assert!(choosable(&mut app, id, "contentAware"), "with a selection it can be chosen");
|
||||
assert_eq!(contents(&app, id), "contentAware");
|
||||
cancel(&mut app, id);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_command_keeps_its_error_without_a_selection() {
|
||||
let mut app = app(false);
|
||||
let err = app.run(COMMAND, json!({"contents": "contentAware"})).unwrap_err().to_string();
|
||||
assert!(err.contains("selection"), "{err}");
|
||||
}
|
||||
Reference in new issue
Block a user