mirror of
https://github.com/storytold/photocraft.git
synced 2026-11-18 16:04:57 +00:00
Merge pull request #12966 from rmsff/fix/rasterize-prompt-history-name-12888
Rasterize prompt: a painting tool's type prompt adds "Rasterize Layer"
This commit is contained in:
3 files changed
+125
-9
No files matched your search
@@ -207,7 +207,15 @@ pub fn confirm(app: &mut PhotocraftApp, f: &Map<String, Value>) -> Result<Value,
|
||||
if let Some(filter) = f.get("filter").and_then(Value::as_str) {
|
||||
return confirm_filter(app, f, filter, layer);
|
||||
}
|
||||
let revision = app.session.active().map(|st| st.revision);
|
||||
let r = app.run(kind.command(), json!({ "layer": layer }))?;
|
||||
// A painting tool's type prompt names its step as the reference does (#12888); Layer ›
|
||||
// Rasterize › Type keeps "Rasterize Type". Only a step this run added is renamed.
|
||||
if kind == Kind::Type
|
||||
&& let Some(st) = app.session.active_mut().filter(|st| Some(st.revision) != revision)
|
||||
{
|
||||
st.history.set_current_label("Rasterize Layer");
|
||||
}
|
||||
// The press that opened the prompt is not replayed: Photoshop only converts the layer, the
|
||||
// next click paints (#8806).
|
||||
Ok(json!({ "rasterized": r }))
|
||||
@@ -247,3 +255,7 @@ mod rasterize_prompt_text_tests;
|
||||
#[cfg(test)]
|
||||
#[path = "rasterize_prompt_fill_text_tests.rs"]
|
||||
mod rasterize_prompt_fill_text_tests;
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "../rasterize_prompt_history_name_tests.rs"]
|
||||
mod rasterize_prompt_history_name_tests;
|
||||
@@ -6,7 +6,7 @@ use super::*;
|
||||
use crate::canvas::{ToolEvent, tool_event};
|
||||
|
||||
/// A document whose active layer is a `kind` layer over a white Background.
|
||||
fn app_with(kind: Kind) -> PhotocraftApp {
|
||||
pub(super) fn app_with(kind: Kind) -> PhotocraftApp {
|
||||
let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), Default::default());
|
||||
app.run("file.new", json!({"width": 120, "height": 80})).unwrap();
|
||||
match kind {
|
||||
@@ -28,21 +28,21 @@ fn app_with(kind: Kind) -> PhotocraftApp {
|
||||
app
|
||||
}
|
||||
|
||||
fn active_content(app: &PhotocraftApp) -> &'static str {
|
||||
pub(super) fn active_content(app: &PhotocraftApp) -> &'static str {
|
||||
let st = app.session.active().unwrap();
|
||||
st.doc.layer(st.active_layer.unwrap()).unwrap().content.kind_name()
|
||||
}
|
||||
|
||||
fn past(app: &PhotocraftApp) -> usize {
|
||||
pub(super) fn past(app: &PhotocraftApp) -> usize {
|
||||
app.session.active().unwrap().history.past_len()
|
||||
}
|
||||
|
||||
fn click(app: &mut PhotocraftApp, x: f64, y: f64) {
|
||||
pub(super) fn click(app: &mut PhotocraftApp, x: f64, y: f64) {
|
||||
tool_event(app, ToolEvent::Down { x, y, pressure: 1.0 }, Modifiers::NONE);
|
||||
tool_event(app, ToolEvent::Up { x, y }, Modifiers::NONE);
|
||||
}
|
||||
|
||||
fn prompt(app: &PhotocraftApp) -> Option<&crate::state::Dialog> {
|
||||
pub(super) fn prompt(app: &PhotocraftApp) -> Option<&crate::state::Dialog> {
|
||||
app.ui.dialogs.iter().find(|d| owns(&d.fields))
|
||||
}
|
||||
|
||||
@@ -178,14 +178,14 @@ fn the_control_channel_sees_and_confirms_the_prompt() {
|
||||
assert_eq!(active_content(&app), "Pixel");
|
||||
}
|
||||
|
||||
const BLUR: &str = "filter.blur.gaussianBlur";
|
||||
pub(super) const BLUR: &str = "filter.blur.gaussianBlur";
|
||||
|
||||
fn menu(app: &mut PhotocraftApp, id: &str) -> Result<serde_json::Value, String> {
|
||||
pub(super) fn menu(app: &mut PhotocraftApp, id: &str) -> Result<serde_json::Value, String> {
|
||||
crate::menus::invoke(app, &egui::Context::default(), id, json!({}))
|
||||
}
|
||||
|
||||
/// Answers the filter prompt, then the frame runs the queued filter.
|
||||
fn answer(app: &mut PhotocraftApp, id: u64) {
|
||||
pub(super) fn answer(app: &mut PhotocraftApp, id: u64) {
|
||||
crate::dialogs::confirm(app, id).unwrap();
|
||||
run_pending(app, &egui::Context::default());
|
||||
}
|
||||
@@ -276,7 +276,7 @@ fn filters_stay_grey_where_rasterizing_would_not_help() {
|
||||
}
|
||||
|
||||
/// The dialogs, and the filter a prompt queued, frame by frame.
|
||||
fn harness(app: PhotocraftApp) -> egui_kittest::Harness<'static, PhotocraftApp> {
|
||||
pub(super) fn harness(app: PhotocraftApp) -> egui_kittest::Harness<'static, PhotocraftApp> {
|
||||
let h = egui_kittest::Harness::builder().with_size(egui::vec2(1000.0, 700.0)).build_ui_state(
|
||||
|ui, app| {
|
||||
crate::dialogs::show(app, ui.ctx());
|
||||
|
||||
@@ -0,0 +1,104 @@
|
||||
//! #12888: OK on the type-layer prompt a painting tool raises adds one history state named
|
||||
//! "Rasterize Layer", as the reference application does; Layer › Rasterize › Type, Cancel and
|
||||
//! the shape, Smart Object and fill prompts keep their behaviour.
|
||||
|
||||
use egui_kittest::kittest::Queryable;
|
||||
use serde_json::{Value, json};
|
||||
|
||||
use super::tests::{BLUR, active_content, answer, app_with, click, harness, menu, past, prompt};
|
||||
use super::*;
|
||||
|
||||
fn step_name(app: &PhotocraftApp) -> Option<String> {
|
||||
app.session.active()?.history.undo_label().map(str::to_string)
|
||||
}
|
||||
|
||||
fn active_layer_content(app: &PhotocraftApp) -> photocraft_doc::LayerContent {
|
||||
let st = app.session.active().unwrap();
|
||||
st.doc.layer(st.active_layer.unwrap()).unwrap().content.clone()
|
||||
}
|
||||
|
||||
/// A press of `tool` on a `kind` layer, answered with `button` in the dialog.
|
||||
fn answer_prompt(kind: Kind, tool: Tool, button: &str) -> (PhotocraftApp, usize) {
|
||||
let mut app = app_with(kind);
|
||||
app.ui.tool = tool;
|
||||
let before = past(&app);
|
||||
// The harness's first frame installs the fonts, so the press comes after it.
|
||||
let mut h = harness(app);
|
||||
click(h.state_mut(), 30.0, 20.0);
|
||||
assert!(prompt(h.state()).is_some(), "{kind:?}/{tool:?}: the prompt opens");
|
||||
h.run_steps(4);
|
||||
h.get_by_label(button).click();
|
||||
h.run_steps(4);
|
||||
let app = h.into_state();
|
||||
assert!(prompt(&app).is_none(), "{kind:?}/{tool:?}: {button} closes the prompt");
|
||||
(app, before)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ok_from_a_painting_tool_adds_one_rasterize_layer_state() {
|
||||
for tool in [Tool::PatternStamp, Tool::Brush, Tool::HistoryBrush] {
|
||||
let (app, before) = answer_prompt(Kind::Type, tool, "OK");
|
||||
assert_eq!(past(&app), before + 1, "{tool:?}: exactly one state");
|
||||
assert_eq!(step_name(&app).as_deref(), Some("Rasterize Layer"), "{tool:?}");
|
||||
assert_eq!(active_content(&app), "Pixel", "{tool:?}: the layer is rasterized");
|
||||
// Nothing painted: the pixels are the plain rasterized type.
|
||||
let mut plain = app_with(Kind::Type);
|
||||
plain.run("layer.rasterize.type", json!({})).unwrap();
|
||||
assert!(active_layer_content(&app) == active_layer_content(&plain), "{tool:?}: the press painted nothing");
|
||||
// The name belongs to the history state: undone, it is the state to redo.
|
||||
let mut app = app;
|
||||
app.run("edit.undo", json!({})).unwrap();
|
||||
assert_eq!(app.session.active().unwrap().history.redo_labels().next(), Some("Rasterize Layer"), "{tool:?}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cancel_adds_no_state() {
|
||||
for tool in [Tool::PatternStamp, Tool::Brush, Tool::HistoryBrush] {
|
||||
let (app, before) = answer_prompt(Kind::Type, tool, "Cancel");
|
||||
assert_eq!(past(&app), before, "{tool:?}");
|
||||
assert_eq!(active_content(&app), "Type", "{tool:?}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn layer_rasterize_type_keeps_its_step_name() {
|
||||
let mut app = app_with(Kind::Type);
|
||||
crate::menus::invoke(&mut app, &egui::Context::default(), "layer.rasterize.type", json!({})).unwrap();
|
||||
assert_eq!(step_name(&app).as_deref(), Some("Rasterize Type"), "the menu");
|
||||
|
||||
let ctx = egui::Context::default();
|
||||
for (method, params) in [("ui.menu.invoke", json!({"id": "layer.rasterize.type"})), ("engine.execute", json!({"command": "layer.rasterize.type"}))] {
|
||||
let mut app = app_with(Kind::Type);
|
||||
let (req, _rx) = crate::control::ControlRequest::new(method, params);
|
||||
let crate::control::Outcome::Done(r) = crate::control::handle(&mut app, &ctx, &req) else { panic!("{method}: deferred") };
|
||||
assert_ne!(r.get("ok"), Some(&Value::Bool(false)), "{method}: {r}");
|
||||
assert_eq!(active_content(&app), "Pixel", "{method}");
|
||||
assert_eq!(step_name(&app).as_deref(), Some("Rasterize Type"), "{method}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_other_prompts_keep_their_step_names() {
|
||||
for kind in [Kind::Shape, Kind::SmartObject, Kind::Fill] {
|
||||
let mut direct = app_with(kind);
|
||||
direct.run(kind.command(), json!({})).unwrap();
|
||||
let (app, before) = answer_prompt(kind, Tool::Brush, "OK");
|
||||
assert_eq!(past(&app), before + 1, "{kind:?}");
|
||||
assert_eq!(step_name(&app), step_name(&direct), "{kind:?}");
|
||||
assert_ne!(step_name(&app).as_deref(), Some("Rasterize Layer"), "{kind:?}");
|
||||
}
|
||||
}
|
||||
|
||||
/// The filter prompt's Rasterize (#4303) is not measured: its step keeps "Rasterize Type".
|
||||
#[test]
|
||||
fn the_filter_prompt_keeps_rasterize_type() {
|
||||
let mut app = app_with(Kind::Type);
|
||||
let before = past(&app);
|
||||
menu(&mut app, BLUR).unwrap();
|
||||
let id = prompt(&app).expect("the prompt").id;
|
||||
answer(&mut app, id);
|
||||
assert_eq!(active_content(&app), "Pixel");
|
||||
assert_eq!(past(&app), before + 1);
|
||||
assert_eq!(step_name(&app).as_deref(), Some("Rasterize Type"));
|
||||
}
|
||||
Reference in new issue
Block a user