Merge remote-tracking branch 'origin/main' into fix/13241-line-tool-defaults
# Conflicts: # crates/ui-egui/src/tools.rs
No files matched your search
@@ -118,7 +118,7 @@ People trust PhotoCraft with their work, and a crash loses it. A malformed file,
|
||||
3. **Clean-room.** We studied Photoshop and other proprietary editors for *behaviour and look only*. Never copy their code, shaders, profiles or assets. Implement from public specs (Adobe PSD spec, ICC, ISO 32000 blend modes, papers) and observation. Third-party assets must be permissively licensed, keep their license file next to them, and get a row in `ATTRIBUTION.md` (path, title, author, source, license) in the same change; so do original assets. The ArtCraft logos in `docs/brand/` are not open source (`docs/brand/LICENSE-brand.txt`). **Never commit font files:** fonts live in [storytold/craft-fonts](https://github.com/storytold/craft-fonts). PhotoCraft uses it through the optional build input `CRAFT_FONTS_DIR=<craft-fonts checkout>` (read by `crates/text/build.rs`, exposed as `photocraft_text::CRAFT_FONTS`; empty without it, and everything must still work). Build with it: `CRAFT_FONTS_DIR="$PWD/../craft-fonts" cargo build`; details in `docs/development.md` › Fonts.
|
||||
4. **Tests are the gate.** Every change comes with tests. Format crates use round-trip, synthetic-generator, oracle and fuzz tests. Keep the PSD corpus results and the parity floor (`crates/ui-egui/src/parity.rs`) from regressing.
|
||||
5. **The UI is thin and data-driven.** UI state lives in `ui-egui/src/state.rs` (serde), so the control channel can read and drive it. Colours and radii come from `theme::Tokens`, never hard-coded.
|
||||
6. **Verify UI changes visually.** Render offscreen with `cargo run -p photocraft-ui-egui --example snapshot` (no window, no focus stealing), or launch with `--control` and take `ui.screenshot`. Look at the PNG. Demo images must be public-domain art, never personal photos. When fetching assets, never put a person's name, email or other personal details in requests (User-Agent, headers, URLs); use a generic `Photocraft-dev` User-Agent.
|
||||
6. **Verify UI changes visually.** Render offscreen with `cargo run -p photocraft-ui-egui --example snapshot` (no window, no focus stealing), or launch with `--control` and take `ui.screenshot`. Look at the PNG. **Screenshots that show a PR's change (before/after evidence) go in the PR description, never in the repo:** `docs/images/` holds only images the README or a doc displays (a doc's own before/after comparison included), so a PR adds an image there only together with the doc that shows it. Demo images must be public-domain art, never personal photos. When fetching assets, never put a person's name, email or other personal details in requests (User-Agent, headers, URLs); use a generic `Photocraft-dev` User-Agent.
|
||||
7. **Never break wasm.** L0–L6 must `cargo check --target wasm32-unknown-unknown` (run `cargo xtask wasm`). File-system code is `cfg(not(target_arch = "wasm32"))` or goes through the platform services.
|
||||
8. **Performance is a feature.** Benchmark heavy operations on a 24–36 MP image in release. Work per tile in parallel (rayon), skip empty tiles, never scan a full surface per frame (cache per revision), and record before/after timings in the dev log.
|
||||
|
||||
|
||||
@@ -81,12 +81,8 @@ The other built-in ICC profiles and the generated LUT looks are produced by code
|
||||
|---|---|---|---|---|
|
||||
| `docs/brand/` (all files) | ArtCraft name, wordmark and mark | ArtCraft Team | getartcraft.com | Not open source; trademarks of the ArtCraft Team, [`docs/brand/LICENSE-brand.txt`](docs/brand/LICENSE-brand.txt) |
|
||||
| `docs/images/photocraft-*.jpg` | PhotoCraft screenshots | PhotoCraft contributors (UI) | Rendered offscreen with the `snapshot` example | MIT OR Apache-2.0 (UI); the artwork in each is public domain, listed below |
|
||||
| `docs/images/native-pipette-macos-*.png` | Text Color Picker on macOS before and after the native pipette fix (synthetic text, no artwork) | PhotoCraft contributors (UI); @SvenCarstensen (captures) | Local macOS screenshot and PhotoCraft control-channel capture | MIT OR Apache-2.0 |
|
||||
| `docs/images/preferences-apply-*.png` | Preferences before and after adding Apply (no artwork) | PhotoCraft contributors | PhotoCraft control-channel capture and offscreen `snapshot` example | MIT OR Apache-2.0 |
|
||||
| `docs/images/guide-position-*-tab.png` | New Guide before and after focusing Position with Tab (no artwork) | PhotoCraft contributors | Offscreen `snapshot` example with `ui.key Tab` | MIT OR Apache-2.0 |
|
||||
| `docs/images/embedded-vector-editor-en.png` | Embedded AI/PDF/EPS conversion warning and editor chooser (no artwork) | Don Omondi | Offscreen `smart_svg_ui::tests::capture_embedded_vector_conversion_prompt` with authored bytes and mock services | MIT OR Apache-2.0 |
|
||||
| `docs/images/embedded-vector-tabs-linux.png` | Shared VectorCraft window after a portal editor save and ordinary document launch | Don Omondi | Local Linux GUI acceptance with authored orange rectangle/blue circle SVGs; no private artwork | MIT OR Apache-2.0 |
|
||||
| `docs/images/gradient-overlay-method-*.png` | Gradient Overlay Method selector, before and after (synthetic gradient) | @oRE-o | Rendered offscreen with the `snapshot` example; no external artwork | MIT OR Apache-2.0 |
|
||||
| `docs/images/preset-invalid-choice-before.png` | Gradient preset import before validation, with the collision dialog closed | @yoriswind | Offscreen PhotoCraft capture with the synthetic `Fire.grd` gradient fixture | MIT OR Apache-2.0 |
|
||||
| `docs/images/preset-invalid-choice-after.png` | Gradient preset import after validation, with the collision dialog still open | @yoriswind | Offscreen PhotoCraft capture with the synthetic `Fire.grd` gradient fixture | MIT OR Apache-2.0 |
|
||||
| `docs/images/cpu-pixel-alignment/*.png` | CPU canvas pixel alignment, before and after #8321 | PhotoCraft contributors | Original synthetic noise rendered with the offscreen `snapshot` example; see the adjacent README | MIT OR Apache-2.0, adjacent `LICENSE-MIT` and `LICENSE-APACHE` |
|
||||
|
||||
@@ -5324,7 +5324,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "photocraft"
|
||||
version = "0.20.1"
|
||||
version = "0.23.0"
|
||||
dependencies = [
|
||||
"arboard",
|
||||
"async-io",
|
||||
@@ -5379,7 +5379,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "photocraft-affinity"
|
||||
version = "0.20.1"
|
||||
version = "0.23.0"
|
||||
dependencies = [
|
||||
"crc32fast",
|
||||
"flate2",
|
||||
@@ -5389,7 +5389,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "photocraft-algo"
|
||||
version = "0.20.1"
|
||||
version = "0.23.0"
|
||||
dependencies = [
|
||||
"criterion",
|
||||
"photocraft-color",
|
||||
@@ -5404,7 +5404,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "photocraft-automation"
|
||||
version = "0.20.1"
|
||||
version = "0.23.0"
|
||||
dependencies = [
|
||||
"base64 0.23.1",
|
||||
"cap-std",
|
||||
@@ -5437,7 +5437,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "photocraft-cli"
|
||||
version = "0.20.1"
|
||||
version = "0.23.0"
|
||||
dependencies = [
|
||||
"clap",
|
||||
"clap_complete",
|
||||
@@ -5463,7 +5463,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "photocraft-cms"
|
||||
version = "0.20.1"
|
||||
version = "0.23.0"
|
||||
dependencies = [
|
||||
"moxcms",
|
||||
"rayon",
|
||||
@@ -5471,7 +5471,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "photocraft-codecs"
|
||||
version = "0.20.1"
|
||||
version = "0.23.0"
|
||||
dependencies = [
|
||||
"craft-heif",
|
||||
"craft-jpeg",
|
||||
@@ -5495,7 +5495,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "photocraft-color"
|
||||
version = "0.20.1"
|
||||
version = "0.23.0"
|
||||
dependencies = [
|
||||
"photocraft-cms",
|
||||
"serde",
|
||||
@@ -5503,7 +5503,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "photocraft-compose"
|
||||
version = "0.20.1"
|
||||
version = "0.23.0"
|
||||
dependencies = [
|
||||
"criterion",
|
||||
"photocraft-cms",
|
||||
@@ -5519,7 +5519,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "photocraft-doc"
|
||||
version = "0.20.1"
|
||||
version = "0.23.0"
|
||||
dependencies = [
|
||||
"photocraft-color",
|
||||
"photocraft-geom",
|
||||
@@ -5530,7 +5530,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "photocraft-engine"
|
||||
version = "0.20.1"
|
||||
version = "0.23.0"
|
||||
dependencies = [
|
||||
"base64 0.22.1",
|
||||
"blake3",
|
||||
@@ -5573,7 +5573,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "photocraft-format"
|
||||
version = "0.20.1"
|
||||
version = "0.23.0"
|
||||
dependencies = [
|
||||
"blake3",
|
||||
"craft-pcraft-format",
|
||||
@@ -5597,14 +5597,14 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "photocraft-geom"
|
||||
version = "0.20.1"
|
||||
version = "0.23.0"
|
||||
dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "photocraft-gpu"
|
||||
version = "0.20.1"
|
||||
version = "0.23.0"
|
||||
dependencies = [
|
||||
"bytemuck",
|
||||
"half",
|
||||
@@ -5625,7 +5625,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "photocraft-io"
|
||||
version = "0.20.1"
|
||||
version = "0.23.0"
|
||||
dependencies = [
|
||||
"blake3",
|
||||
"craft-docpath",
|
||||
@@ -5665,18 +5665,18 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "photocraft-ipp"
|
||||
version = "0.20.1"
|
||||
version = "0.23.0"
|
||||
|
||||
[[package]]
|
||||
name = "photocraft-ops"
|
||||
version = "0.20.1"
|
||||
version = "0.23.0"
|
||||
dependencies = [
|
||||
"photocraft-doc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "photocraft-paint"
|
||||
version = "0.20.1"
|
||||
version = "0.23.0"
|
||||
dependencies = [
|
||||
"photocraft-cms",
|
||||
"photocraft-color",
|
||||
@@ -5690,7 +5690,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "photocraft-plugins"
|
||||
version = "0.20.1"
|
||||
version = "0.23.0"
|
||||
dependencies = [
|
||||
"photocraft-color",
|
||||
"photocraft-geom",
|
||||
@@ -5706,7 +5706,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "photocraft-psd"
|
||||
version = "0.20.1"
|
||||
version = "0.23.0"
|
||||
dependencies = [
|
||||
"encoding_rs",
|
||||
"flate2",
|
||||
@@ -5718,7 +5718,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "photocraft-raster"
|
||||
version = "0.20.1"
|
||||
version = "0.23.0"
|
||||
dependencies = [
|
||||
"crc32fast",
|
||||
"lz4_flex",
|
||||
@@ -5734,7 +5734,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "photocraft-raw"
|
||||
version = "0.20.1"
|
||||
version = "0.23.0"
|
||||
dependencies = [
|
||||
"flate2",
|
||||
"image",
|
||||
@@ -5749,7 +5749,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "photocraft-tablet"
|
||||
version = "0.20.1"
|
||||
version = "0.23.0"
|
||||
dependencies = [
|
||||
"block2 0.6.2",
|
||||
"log",
|
||||
@@ -5764,7 +5764,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "photocraft-testkit"
|
||||
version = "0.20.1"
|
||||
version = "0.23.0"
|
||||
dependencies = [
|
||||
"memory-stats",
|
||||
"serde_json",
|
||||
@@ -5772,7 +5772,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "photocraft-text"
|
||||
version = "0.20.1"
|
||||
version = "0.23.0"
|
||||
dependencies = [
|
||||
"flate2",
|
||||
"parley",
|
||||
@@ -5787,7 +5787,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "photocraft-ui-egui"
|
||||
version = "0.20.1"
|
||||
version = "0.23.0"
|
||||
dependencies = [
|
||||
"base64 0.23.1",
|
||||
"chrono",
|
||||
@@ -5836,7 +5836,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "photocraft-vector"
|
||||
version = "0.20.1"
|
||||
version = "0.23.0"
|
||||
dependencies = [
|
||||
"photocraft-color",
|
||||
"photocraft-doc",
|
||||
@@ -5847,7 +5847,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "photocraft-web"
|
||||
version = "0.20.1"
|
||||
version = "0.23.0"
|
||||
dependencies = [
|
||||
"eframe",
|
||||
"egui",
|
||||
@@ -5870,7 +5870,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "photocraft-web-boot"
|
||||
version = "0.20.1"
|
||||
version = "0.23.0"
|
||||
dependencies = [
|
||||
"flate2",
|
||||
"js-sys",
|
||||
@@ -9756,7 +9756,7 @@ checksum = "ec7a2a501ed189703dba8b08142f057e887dfc4b2cc4db2d343ac6376ba3e0b9"
|
||||
|
||||
[[package]]
|
||||
name = "xtask"
|
||||
version = "0.20.1"
|
||||
version = "0.23.0"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"craft-i18n",
|
||||
|
||||
@@ -4,7 +4,7 @@ members = ["crates/*", "apps/*", "xtask"]
|
||||
default-members = ["crates/*", "apps/photocraft", "apps/photocraft-cli", "xtask"]
|
||||
|
||||
[workspace.package]
|
||||
version = "0.20.1"
|
||||
version = "0.23.0"
|
||||
edition = "2024"
|
||||
license = "MIT OR Apache-2.0"
|
||||
rust-version = "1.95"
|
||||
|
||||
@@ -9,7 +9,7 @@ use super::*;
|
||||
use crate::canvas::{ToolEvent, tool_event};
|
||||
|
||||
/// A 64 × 64 document with a painted layer active, black foreground, `tool`.
|
||||
pub(super) fn app(tool: Tool) -> PhotocraftApp {
|
||||
pub(in crate::tools) fn app(tool: Tool) -> PhotocraftApp {
|
||||
let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default());
|
||||
app.run("file.new", json!({"width": 64, "height": 64})).unwrap();
|
||||
app.run("layer.new.layer", json!({})).unwrap();
|
||||
@@ -24,22 +24,22 @@ pub(super) fn active(app: &PhotocraftApp) -> u64 {
|
||||
app.session.active().unwrap().active_layer.unwrap().0
|
||||
}
|
||||
|
||||
pub(super) fn steps(app: &PhotocraftApp) -> usize {
|
||||
pub(in crate::tools) fn steps(app: &PhotocraftApp) -> usize {
|
||||
app.session.active().unwrap().history.past_len()
|
||||
}
|
||||
|
||||
/// A press, a short drag and the release with the active tool.
|
||||
pub(super) fn stroke(app: &mut PhotocraftApp) {
|
||||
pub(in crate::tools) fn stroke(app: &mut PhotocraftApp) {
|
||||
tool_event(app, ToolEvent::Down { x: 20.0, y: 32.0, pressure: 1.0 }, Modifiers::NONE);
|
||||
tool_event(app, ToolEvent::Move { x: 44.0, y: 32.0, pressure: 1.0 }, Modifiers::NONE);
|
||||
tool_event(app, ToolEvent::Up { x: 44.0, y: 32.0 }, Modifiers::NONE);
|
||||
}
|
||||
|
||||
pub(super) fn alerts(app: &PhotocraftApp) -> Vec<String> {
|
||||
pub(in crate::tools) fn alerts(app: &PhotocraftApp) -> Vec<String> {
|
||||
app.ui.dialogs.iter().filter(|d| d.kind == DialogKind::Error).filter_map(|d| d.fields.get("message").and_then(Value::as_str).map(str::to_string)).collect()
|
||||
}
|
||||
|
||||
pub(super) fn refused(app: &mut PhotocraftApp, want: &str) {
|
||||
pub(in crate::tools) fn refused(app: &mut PhotocraftApp, want: &str) {
|
||||
let before = steps(app);
|
||||
stroke(app);
|
||||
assert_eq!(alerts(app), [want], "the alert, once");
|
||||
|
||||
@@ -1955,12 +1955,15 @@ fn draw_default_tool_cursor(app: &mut PhotocraftApp, ui: &mut egui::Ui, input: &
|
||||
}
|
||||
// The Color Sampler (#11744):
|
||||
// - Over a sampler: arrow with the sampler target, or with Alt the arrow with scissors.
|
||||
// Dragging one keeps the arrow with the sampler target until release, though the stored
|
||||
// point stays behind, and without scissors: Alt removes only on the press (#13063).
|
||||
// - Off a sampler: eyedropper with the sampler target at its top-left, or the crosshair
|
||||
// for precise Other Cursors.
|
||||
Tool::ColorSampler => {
|
||||
let [x, y] = xf.to_doc(p);
|
||||
if crate::analysis_ui::sampler_at(app, [x, y]).is_some() {
|
||||
sampler_hover_cursor(ui.ctx(), p, alt || app.ui.shell.sticky_alt)
|
||||
let dragging = matches!(app.ui.analysis.drag, Some(crate::analysis_ui::Drag::Sampler(..)));
|
||||
if dragging || crate::analysis_ui::sampler_at(app, [x, y]).is_some() {
|
||||
sampler_hover_cursor(ui.ctx(), p, !dragging && (alt || app.ui.shell.sticky_alt))
|
||||
} else if precise_other_cursor(app) {
|
||||
egui::CursorIcon::Crosshair
|
||||
} else {
|
||||
|
||||
@@ -458,24 +458,38 @@ pub const HAND_MENU: &[Row] = &[
|
||||
/// the view itself.
|
||||
pub const FILL_SCREEN: &str = "view.fillScreen";
|
||||
|
||||
/// A selection menu: the rows every selection menu shares, with `$fills` (the rows between
|
||||
/// Transform Selection and Last Filter) in its own order.
|
||||
macro_rules! selection_menu {
|
||||
($($fills:expr),* $(,)?) => {
|
||||
&[
|
||||
Some(("Deselect", "select.deselect")),
|
||||
Some(("Select Inverse", "select.inverse")),
|
||||
Some(("Feather…", "select.modify.feather")),
|
||||
Some(("Select and Mask…", "select.selectAndMask")),
|
||||
None,
|
||||
Some(("Save Selection…", "select.saveSelection")),
|
||||
Some(("Make Work Path…", "select.toWorkPath")),
|
||||
None,
|
||||
Some(("Layer Via Copy", "layer.new.layerViaCopy")),
|
||||
Some(("Layer Via Cut", "layer.new.layerViaCut")),
|
||||
Some(("New Layer…", "layer.new.layer")),
|
||||
None,
|
||||
Some(("Free Transform", "edit.freeTransform")),
|
||||
Some(("Transform Selection", "select.transformSelection")),
|
||||
$($fills,)*
|
||||
None,
|
||||
Some(("Last Filter", "filter.lastFilter")),
|
||||
None,
|
||||
Some(("Fade…", "edit.fade")),
|
||||
]
|
||||
};
|
||||
}
|
||||
|
||||
/// Photoshop's selection-tool context menu with an active selection, in its order. Its Generative
|
||||
/// Fill row has no PhotoCraft command and is left out. Rows stay visible and grey out exactly like
|
||||
/// their menu-bar twins.
|
||||
pub const SELECTION_MENU: &[Row] = &[
|
||||
Some(("Deselect", "select.deselect")),
|
||||
Some(("Select Inverse", "select.inverse")),
|
||||
Some(("Feather…", "select.modify.feather")),
|
||||
Some(("Select and Mask…", "select.selectAndMask")),
|
||||
None,
|
||||
Some(("Save Selection…", "select.saveSelection")),
|
||||
Some(("Make Work Path…", "select.toWorkPath")),
|
||||
None,
|
||||
Some(("Layer Via Copy", "layer.new.layerViaCopy")),
|
||||
Some(("Layer Via Cut", "layer.new.layerViaCut")),
|
||||
Some(("New Layer…", "layer.new.layer")),
|
||||
None,
|
||||
Some(("Free Transform", "edit.freeTransform")),
|
||||
Some(("Transform Selection", "select.transformSelection")),
|
||||
pub const SELECTION_MENU: &[Row] = selection_menu![
|
||||
Some(("Distort", "edit.transform.distort")),
|
||||
Some(("Perspective", "edit.transform.perspective")),
|
||||
None,
|
||||
@@ -483,10 +497,6 @@ pub const SELECTION_MENU: &[Row] = &[
|
||||
Some(("Fill…", "edit.fill")),
|
||||
Some(("Stroke…", "edit.stroke")),
|
||||
Some(("Content-Aware Fill…", "edit.contentAwareFill")),
|
||||
None,
|
||||
Some(("Last Filter", "filter.lastFilter")),
|
||||
None,
|
||||
Some(("Fade…", "edit.fade")),
|
||||
];
|
||||
|
||||
/// The selection tools' context menu with nothing selected: making a selection.
|
||||
@@ -498,8 +508,8 @@ pub const NO_SELECTION_MENU: &[Row] = &[
|
||||
Some(("Load Selection…", "select.loadSelection")),
|
||||
];
|
||||
|
||||
/// The Count tool's canvas menu (#11772): Photoshop's generic layer menu, on a marker or off one,
|
||||
/// in its order for a pixel layer without a selection. Each row is enabled as the Layers panel
|
||||
/// Photoshop's generic layer menu, in its order for a pixel layer without a selection: the Count
|
||||
/// tool's canvas menu on a marker or off one (#11772), and the Red Eye tool's without a selection. Each row is enabled as the Layers panel
|
||||
/// menu enables it for the active layer (`menus::is_enabled`) and runs like the menu item.
|
||||
pub const COUNT_MENU: &[Row] = &[
|
||||
Some(("Blending Options…", "layer.layerStyle.blendingOptions")),
|
||||
@@ -524,6 +534,16 @@ pub const COUNT_MENU: &[Row] = &[
|
||||
/// Right-click with the Content-Aware Move tool inside an active selection (#12194).
|
||||
pub const CAM_INSIDE_SELECTION_MENU: &[Row] = &[Some(("Color Range…", "select.colorRange")), Some(("Load Selection…", "select.loadSelection"))];
|
||||
|
||||
/// The selection menu as measured in the reference application with the Red Eye tool (#12577):
|
||||
/// no Distort or Perspective, and Delete and Fill Selection after the fills.
|
||||
pub const MEASURED_SELECTION_MENU: &[Row] = selection_menu![
|
||||
None,
|
||||
Some(("Fill…", "edit.fill")),
|
||||
Some(("Stroke…", "edit.stroke")),
|
||||
Some(("Content-Aware Fill…", "edit.contentAwareFill")),
|
||||
Some(("Delete and Fill Selection", "edit.deleteAndFillSelection")),
|
||||
];
|
||||
|
||||
/// The Eyedropper's copy rows (#11747).
|
||||
pub const EYEDROPPER_COPY_HTML: &str = "canvasMenu.eyedropper.copyHtml";
|
||||
pub const EYEDROPPER_COPY_HEX: &str = "canvasMenu.eyedropper.copyHex";
|
||||
@@ -674,8 +694,31 @@ fn cam_allowed(app: &PhotocraftApp) -> bool {
|
||||
app.session.active().is_some_and(|s| !matches!(s.doc.mode, ColorMode::Bitmap | ColorMode::Duotone | ColorMode::Multichannel))
|
||||
}
|
||||
|
||||
/// Is document point `d` on the image and inside the active selection?
|
||||
fn selected_at(app: &PhotocraftApp, d: [f64; 2]) -> bool {
|
||||
d.iter().all(|v| v.is_finite())
|
||||
&& d[0] >= 0.0
|
||||
&& d[1] >= 0.0
|
||||
&& app.session.active().is_some_and(|s| {
|
||||
d[0] < f64::from(s.doc.size.width)
|
||||
&& d[1] < f64::from(s.doc.size.height)
|
||||
&& s.doc.selection.as_ref().is_some_and(|sel| sel.sample_channel(d[0].floor() as i32, d[1].floor() as i32, 0) >= 0.5)
|
||||
})
|
||||
}
|
||||
|
||||
/// Does a Red Eye right-click at `doc` open a menu (#12577)? Only where the reference application
|
||||
/// was measured: an RGB document whose one layer is a pixel layer, with no selection or the pointer
|
||||
/// inside it. Elsewhere it keeps opening nothing.
|
||||
fn red_eye_measured(app: &PhotocraftApp, doc: Option<[f64; 2]>) -> bool {
|
||||
app.session.active().is_some_and(|s| {
|
||||
s.doc.mode == ColorMode::Rgb
|
||||
&& matches!(s.doc.layers.as_slice(), [l] if matches!(l.content, LayerContent::Raster(_)) && l.frame.is_none())
|
||||
&& (s.doc.selection.is_none() || doc.is_some_and(|d| selected_at(app, d)))
|
||||
})
|
||||
}
|
||||
|
||||
/// Tools whose plain canvas right-click opens a menu: the selection tools' actions, the
|
||||
/// Content-Aware Move menu, the path menu and the Color Sampler's.
|
||||
/// Content-Aware Move menu, the path menu, the Color Sampler's and the Red Eye tool's.
|
||||
pub fn applies(tool: Tool) -> bool {
|
||||
matches!(
|
||||
tool,
|
||||
@@ -697,6 +740,8 @@ pub fn applies(tool: Tool) -> bool {
|
||||
// Sample Size and Copy Color (#11747).
|
||||
| Tool::Eyedropper
|
||||
| Tool::ContentAwareMove
|
||||
// The layer or selection menu, where measured (#12577).
|
||||
| Tool::RedEye
|
||||
) || path_menu(tool)
|
||||
}
|
||||
|
||||
@@ -750,6 +795,8 @@ pub fn rows(menu: &CanvasToolMenu) -> &'static [Row] {
|
||||
SAMPLER_MENU
|
||||
} else if menu.tool == Tool::Count {
|
||||
COUNT_MENU
|
||||
} else if menu.tool == Tool::RedEye {
|
||||
if menu.has_selection { MEASURED_SELECTION_MENU } else { COUNT_MENU }
|
||||
} else if menu.tool == Tool::Eyedropper {
|
||||
EYEDROPPER_MENU
|
||||
} else if inside_selection(menu) {
|
||||
@@ -1193,23 +1240,16 @@ pub fn open_at(app: &mut PhotocraftApp, ctx: &Context, tool: Tool, pos: [f32; 2]
|
||||
crate::color_hud::release(&mut app.ui);
|
||||
return false;
|
||||
}
|
||||
if tool == Tool::RedEye && !red_eye_measured(app, doc) {
|
||||
return false;
|
||||
}
|
||||
app.ui.brush_picker = None;
|
||||
app.ui.layer_menu = None;
|
||||
let has_selection = app.session.active().is_some_and(|s| s.doc.selection.is_some());
|
||||
let has_path = crate::vector_ui::active_path_name(app).is_some() || app.ui.pen.as_ref().is_some_and(|p| p.knots.len() >= 2);
|
||||
let path_name = crate::vector_ui::active_path_name(app);
|
||||
let spelling = if text { doc.and_then(|d| spelling_at(app, d)) } else { None };
|
||||
let inside_selection = tool == Tool::ContentAwareMove
|
||||
&& doc.is_some_and(|d| {
|
||||
d.iter().all(|v| v.is_finite())
|
||||
&& d[0] >= 0.0
|
||||
&& d[1] >= 0.0
|
||||
&& app.session.active().is_some_and(|s| {
|
||||
d[0] < f64::from(s.doc.size.width)
|
||||
&& d[1] < f64::from(s.doc.size.height)
|
||||
&& s.doc.selection.as_ref().is_some_and(|sel| sel.sample_channel(d[0].floor() as i32, d[1].floor() as i32, 0) >= 0.5)
|
||||
})
|
||||
});
|
||||
let inside_selection = tool == Tool::ContentAwareMove && doc.is_some_and(|d| selected_at(app, d));
|
||||
let sampler = if tool == Tool::ColorSampler { doc.and_then(|d| crate::analysis_ui::sampler_at(app, d)) } else { None };
|
||||
let sampler_at = sampler.and_then(|i| Some((app.session.active_index()?, *app.session.active()?.color_samplers.get(i)?)));
|
||||
// The Eyedropper reads the colour now, under the right-click: all layers, with the Sample
|
||||
@@ -1703,10 +1743,10 @@ pub fn menu_rect_if_open(app: &PhotocraftApp, ctx: &Context) -> Option<egui::Rec
|
||||
#[cfg(test)]
|
||||
mod cam_menu_tests;
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
pub(crate) mod tests;
|
||||
|
||||
#[cfg(test)]
|
||||
mod count_tests;
|
||||
pub(crate) mod count_tests;
|
||||
|
||||
#[cfg(test)]
|
||||
mod hand_menu_entries_tests;
|
||||
|
||||
@@ -18,7 +18,7 @@ fn app() -> (PhotocraftApp, egui::Context) {
|
||||
(app, egui::Context::default())
|
||||
}
|
||||
|
||||
fn call(app: &mut PhotocraftApp, ctx: &egui::Context, method: &str, params: Value) -> Value {
|
||||
pub(crate) fn call(app: &mut PhotocraftApp, ctx: &egui::Context, method: &str, params: Value) -> Value {
|
||||
let (req, _rx) = ControlRequest::new(method, params);
|
||||
match handle(app, ctx, &req) {
|
||||
Outcome::Done(v) => v,
|
||||
@@ -26,13 +26,13 @@ fn call(app: &mut PhotocraftApp, ctx: &egui::Context, method: &str, params: Valu
|
||||
}
|
||||
}
|
||||
|
||||
fn right_click(app: &mut PhotocraftApp, ctx: &egui::Context, x: f64, y: f64) {
|
||||
pub(crate) fn right_click(app: &mut PhotocraftApp, ctx: &egui::Context, x: f64, y: f64) {
|
||||
let r = call(app, ctx, "ui.pointer", json!({"button": "secondary", "events": [{"kind": "down", "x": x, "y": y}, {"kind": "up", "x": x, "y": y}]}));
|
||||
assert_eq!(r["ok"], true, "{r}");
|
||||
}
|
||||
|
||||
/// The open menu's rows as `ui.inspect` lists them: ids, with "―" for separators.
|
||||
fn listed(app: &mut PhotocraftApp, ctx: &egui::Context) -> Vec<String> {
|
||||
pub(crate) fn listed(app: &mut PhotocraftApp, ctx: &egui::Context) -> Vec<String> {
|
||||
let inspected = call(app, ctx, "ui.inspect", json!({}));
|
||||
let entries = inspected.pointer("/result/canvasToolMenu/entries").and_then(Value::as_array).cloned().unwrap_or_default();
|
||||
entries.iter().map(|e| e["id"].as_str().map_or_else(|| "―".to_string(), str::to_string)).collect()
|
||||
|
||||
@@ -28,7 +28,7 @@ pub(super) fn choose_open(app: &mut PhotocraftApp, command: &str) {
|
||||
choose(app, &Context::default(), command);
|
||||
}
|
||||
|
||||
pub(super) fn harness(mut app: PhotocraftApp) -> Harness<'static, PhotocraftApp> {
|
||||
pub(crate) fn harness(mut app: PhotocraftApp) -> Harness<'static, PhotocraftApp> {
|
||||
app.sync_views();
|
||||
let mut h = Harness::builder().with_size(vec2(1000.0, 700.0)).build_ui_state(
|
||||
|ui, app: &mut PhotocraftApp| {
|
||||
@@ -45,7 +45,7 @@ pub(super) fn harness(mut app: PhotocraftApp) -> Harness<'static, PhotocraftApp>
|
||||
h
|
||||
}
|
||||
|
||||
pub(super) fn right_click(h: &mut Harness<'static, PhotocraftApp>, p: Pos2, modifiers: Modifiers) {
|
||||
pub(crate) fn right_click(h: &mut Harness<'static, PhotocraftApp>, p: Pos2, modifiers: Modifiers) {
|
||||
h.event(egui::Event::ModifiersChanged(modifiers));
|
||||
h.event(egui::Event::PointerMoved(p));
|
||||
h.run_steps(1);
|
||||
|
||||
@@ -49,7 +49,9 @@ pub fn sync_tool_brush(app: &mut PhotocraftApp) {
|
||||
}
|
||||
None => {
|
||||
let opacity = if tool == Tool::ArtHistoryBrush { BrushSettings::default().opacity } else { current.opacity };
|
||||
BrushSettings { smoothing: first_smoothing(), mode: photocraft_color::BlendMode::Normal, opacity, ..current }
|
||||
// The Remove tool starts at its measured 19 px; the rest is the current brush (#12548).
|
||||
let size = if tool == Tool::Remove { REMOVE_TOOL_SIZE } else { current.size };
|
||||
BrushSettings { smoothing: first_smoothing(), mode: photocraft_color::BlendMode::Normal, opacity, size, ..current }
|
||||
}
|
||||
};
|
||||
// The picked preset was the outgoing tool's brush: forget it, so Update Brush can't overwrite
|
||||
@@ -85,12 +87,16 @@ const HEALING_BRUSH_TIP: (f32, f32, f32) = (19.0, 1.0, 0.25);
|
||||
const TONING_TOOL_TIP: (f32, f32, f32) = (65.0, 0.0, 0.25);
|
||||
/// The Clone Stamp's tip after Reset Tool (#12601): a 21 px soft round at 25 % spacing.
|
||||
const CLONE_STAMP_TIP: (f32, f32, f32) = (21.0, 0.0, 0.25);
|
||||
/// The Remove tool's size after Reset Tool (#12548): 19 px. Its hardness and spacing are not
|
||||
/// measured, so they stay the default brush's.
|
||||
const REMOVE_TOOL_SIZE: f32 = 19.0;
|
||||
|
||||
/// `tool`'s brush as it starts out (Reset Tool, #2825): the default brush at Photoshop's
|
||||
/// smoothing, with the session's own fields of `current`. The Brush tool's tip is
|
||||
/// [`BRUSH_TOOL_TIP`], the Background Eraser's [`BACKGROUND_ERASER_TIP`], the Healing Brush's
|
||||
/// [`HEALING_BRUSH_TIP`], the Burn, Dodge and Sponge tools' [`TONING_TOOL_TIP`], the Clone Stamp's
|
||||
/// [`CLONE_STAMP_TIP`] with no smoothing; the other tools keep the default tip.
|
||||
/// [`CLONE_STAMP_TIP`] with no smoothing, the Remove tool's size [`REMOVE_TOOL_SIZE`]; the other
|
||||
/// tools keep the default tip.
|
||||
pub(crate) fn fresh_brush(tool: Tool, current: &BrushSettings) -> BrushSettings {
|
||||
let mut brush = BrushSettings { smoothing: first_smoothing(), ..BrushSettings::default() };
|
||||
match tool {
|
||||
@@ -102,6 +108,7 @@ pub(crate) fn fresh_brush(tool: Tool, current: &BrushSettings) -> BrushSettings
|
||||
(brush.size, brush.hardness, brush.spacing) = CLONE_STAMP_TIP;
|
||||
brush.smoothing.amount = 0.0;
|
||||
}
|
||||
Tool::Remove => brush.size = REMOVE_TOOL_SIZE,
|
||||
_ => {}
|
||||
}
|
||||
session_fields(current, &brush)
|
||||
|
||||
@@ -15,6 +15,7 @@ fn harness(tool: Tool) -> Harness<'static, PhotocraftApp> {
|
||||
let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default());
|
||||
app.run("file.new", json!({"width": 400, "height": 300})).unwrap();
|
||||
app.ui.tool = tool;
|
||||
crate::paint_mouse::sync_tool_brush(&mut app);
|
||||
app.run("tools.setBrush", json!({"brush": {"size": 40, "hardness": 1.0}})).unwrap();
|
||||
app.sync_views();
|
||||
app.ui.extras.rulers = false;
|
||||
|
||||
@@ -182,3 +182,40 @@ fn cursor_follows_sampler_hit_test_tolerance() {
|
||||
assert_eq!(samplers.len(), 1, "dragging within tolerance moved the existing sampler");
|
||||
assert!((samplers[0][0] - 170.0).abs() < 1.0, "moved to 170");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn dragging_a_sampler_past_its_tolerance_keeps_the_sampler_cursor_until_release() {
|
||||
// #13063: the stored point stays where it was until release, so the hit test alone would show
|
||||
// the placement eyedropper once the pointer leaves the 7 px tolerance mid-drag.
|
||||
let mut h = harness();
|
||||
h.state_mut().run("view.colorSamplers.add", json!({"x": 150.0, "y": 150.0})).unwrap();
|
||||
|
||||
let p = screen(&h, 150.0, 150.0);
|
||||
h.event(egui::Event::PointerMoved(p));
|
||||
h.run_steps(1);
|
||||
h.event(egui::Event::PointerButton { pos: p, button: PointerButton::Primary, pressed: true, modifiers: Modifiers::NONE });
|
||||
h.run_steps(1);
|
||||
let q = screen(&h, 200.0, 150.0);
|
||||
h.event(egui::Event::PointerMoved(q));
|
||||
h.run_steps(2);
|
||||
assert_eq!(h.output().platform_output.cursor_icon, egui::CursorIcon::Default, "the drag keeps the arrow pointer");
|
||||
assert!(cursor_badge_visible(&h, "sampler"), "the drag keeps the sampler target badge");
|
||||
assert!(!pipette_shown(&h) && !cursor_area_visible(&h, "pc-sampler-badge"), "no placement eyedropper mid-drag");
|
||||
|
||||
// Alt removes only on the press; the release still moves the point, so no scissors mid-drag.
|
||||
h.event(egui::Event::ModifiersChanged(Modifiers::ALT));
|
||||
h.run_steps(2);
|
||||
assert!(cursor_badge_visible(&h, "sampler"), "Alt mid-drag keeps the sampler target");
|
||||
assert!(!cursor_badge_visible(&h, "scissors"), "Alt mid-drag shows no scissors");
|
||||
h.event(egui::Event::ModifiersChanged(Modifiers::NONE));
|
||||
|
||||
h.event(egui::Event::PointerButton { pos: q, button: PointerButton::Primary, pressed: false, modifiers: Modifiers::NONE });
|
||||
h.run_steps(2);
|
||||
let samplers = h.state().session.active().unwrap().color_samplers.clone();
|
||||
assert!((samplers[0][0] - 200.0).abs() < 1.0, "the release moved the sampler to 200");
|
||||
|
||||
// After release, off a sampler is the placement eyedropper again.
|
||||
hover_at(&mut h, 100.0, 100.0, Modifiers::NONE);
|
||||
assert!(pipette_shown(&h) && cursor_area_visible(&h, "pc-sampler-badge"), "the placement eyedropper returns after release");
|
||||
assert!(!cursor_badge_visible(&h, "sampler"));
|
||||
}
|
||||
@@ -3141,8 +3141,9 @@ fn retouch_drags_show_the_footprint_without_wedges() {
|
||||
let ctx = egui::Context::default();
|
||||
let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), Default::default());
|
||||
app.run("file.new", json!({"width": 120, "height": 60})).unwrap();
|
||||
app.run("tools.setBrush", json!({"brush": {"size": 30, "hardness": hardness}})).unwrap();
|
||||
app.ui.tool = Tool::Remove;
|
||||
crate::paint_mouse::sync_tool_brush(&mut app);
|
||||
app.run("tools.setBrush", json!({"brush": {"size": 30, "hardness": hardness}})).unwrap();
|
||||
tool_event(&mut app, ToolEvent::Down { x: 20.0, y: 30.0, pressure: 1.0 }, egui::Modifiers::NONE);
|
||||
for i in 1..80 {
|
||||
let t = f64::from(i) * 0.5;
|
||||
|
||||
@@ -544,7 +544,12 @@ pub(super) fn tool_event_with_view(app: &mut PhotocraftApp, ev: ToolEvent, mods:
|
||||
if !sets_source && press_refused(app, tool) {
|
||||
return;
|
||||
}
|
||||
if !sets_source && (crate::rasterize_prompt::intercept(app, tool, x, y, pressure) || refuse_group(app, tool)) {
|
||||
// The Clone Stamp's no-source alert opens at the press, after any rasterize prompt.
|
||||
if !sets_source
|
||||
&& (crate::rasterize_prompt::intercept(app, tool, x, y, pressure)
|
||||
|| refuse_group(app, tool)
|
||||
|| crate::retouch_ui::clone_stamp_without_source(app, tool))
|
||||
{
|
||||
return;
|
||||
}
|
||||
// ⌘ with a selection tool is the Move tool for the drag: outside the selection (or
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
//! #12609: a Clone Stamp press before any Alt-click opens the reference application's alert with
|
||||
//! OK at the press, instead of a status-bar line, and paints nothing. The Healing Brush keeps its
|
||||
//! own behaviour.
|
||||
|
||||
use egui::Modifiers;
|
||||
use serde_json::json;
|
||||
|
||||
use crate::PhotocraftApp;
|
||||
use crate::canvas::{ToolEvent, tool_event};
|
||||
use crate::control::{ControlRequest, Outcome, handle};
|
||||
use crate::state::{DialogKind, Tool};
|
||||
use crate::tools::brush_refusal::brush_refusal_alert_tests::{alerts, app, refused, steps, stroke};
|
||||
|
||||
const MESSAGE: &str = if cfg!(target_os = "macos") {
|
||||
"Could not use the clone stamp tool because the area to clone has not been defined (Option-click to define a source point)."
|
||||
} else {
|
||||
"Could not use the clone stamp tool because the area to clone has not been defined (Alt-click to define a source point)."
|
||||
};
|
||||
|
||||
/// The active layer's pixels.
|
||||
fn pixels(app: &PhotocraftApp) -> Vec<f32> {
|
||||
let st = app.session.active().unwrap();
|
||||
st.doc.layer(st.active_layer.unwrap()).unwrap().surface().unwrap().read_region(st.doc.bounds())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_stroke_without_a_source_alerts_once_and_paints_nothing() {
|
||||
let mut app = app(Tool::CloneStamp);
|
||||
let before = pixels(&app);
|
||||
refused(&mut app, MESSAGE);
|
||||
assert!(!app.ui.status_error, "no status-bar error as well: {}", app.ui.status);
|
||||
assert!(pixels(&app) == before, "after OK the document is unchanged");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_alert_opens_at_the_press_and_the_drag_and_release_add_none() {
|
||||
let mut app = app(Tool::CloneStamp);
|
||||
tool_event(&mut app, ToolEvent::Down { x: 20.0, y: 32.0, pressure: 1.0 }, Modifiers::NONE);
|
||||
assert_eq!(alerts(&app), [MESSAGE], "at the press, before any move");
|
||||
assert!(app.drag.is_none() && app.live_stroke.is_none(), "the press starts no stroke");
|
||||
// Closed before the drag, so an alert from the move or the release would show.
|
||||
let id = app.ui.dialogs.iter().find(|d| d.kind == DialogKind::Error).map(|d| d.id).unwrap();
|
||||
crate::dialogs::confirm(&mut app, id).unwrap();
|
||||
tool_event(&mut app, ToolEvent::Move { x: 44.0, y: 32.0, pressure: 1.0 }, Modifiers::NONE);
|
||||
tool_event(&mut app, ToolEvent::Up { x: 44.0, y: 32.0 }, Modifiers::NONE);
|
||||
assert!(alerts(&app).is_empty(), "neither the drag nor the release alerts");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_second_press_while_the_alert_is_up_adds_none() {
|
||||
let mut app = app(Tool::CloneStamp);
|
||||
stroke(&mut app);
|
||||
stroke(&mut app);
|
||||
assert_eq!(alerts(&app), [MESSAGE]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_alert_is_listed_and_confirmed_over_the_control_channel() {
|
||||
let ctx = egui::Context::default();
|
||||
let mut app = app(Tool::CloneStamp);
|
||||
stroke(&mut app);
|
||||
let (inspect, _rx) = ControlRequest::new("ui.inspect", json!({}));
|
||||
let Outcome::Done(inspect) = handle(&mut app, &ctx, &inspect) else { panic!("ui.inspect replies at once") };
|
||||
let dialog = &inspect["result"]["dialogs"][0];
|
||||
assert_eq!(dialog["fields"]["message"], MESSAGE, "{inspect}");
|
||||
let (confirm, _rx) = ControlRequest::new("ui.dialog.confirm", json!({"dialog": dialog["id"]}));
|
||||
assert!(matches!(handle(&mut app, &ctx, &confirm), Outcome::Done(v) if v["ok"] == true));
|
||||
assert!(alerts(&app).is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn after_an_alt_click_the_clone_stamp_paints_without_an_alert() {
|
||||
let mut app = app(Tool::CloneStamp);
|
||||
// A white band around the source on the red layer, so the clone has something to copy.
|
||||
app.run("select.rect", json!({"x": 0, "y": 0, "width": 64, "height": 20})).unwrap();
|
||||
app.run("edit.fill", json!({"color": "#ffffff"})).unwrap();
|
||||
app.run("select.deselect", json!({})).unwrap();
|
||||
tool_event(&mut app, ToolEvent::Down { x: 10.0, y: 10.0, pressure: 1.0 }, Modifiers::ALT);
|
||||
tool_event(&mut app, ToolEvent::Up { x: 10.0, y: 10.0 }, Modifiers::ALT);
|
||||
let before = steps(&app);
|
||||
stroke(&mut app);
|
||||
assert!(alerts(&app).is_empty());
|
||||
assert_eq!(steps(&app), before + 1, "one Clone Stamp state");
|
||||
let st = app.session.active().unwrap();
|
||||
let on_stroke = st.doc.layer(st.active_layer.unwrap()).unwrap().surface().unwrap().rgba(32, 32);
|
||||
assert!(on_stroke[1] > 0.5, "the stroke copies the white source onto the red: {on_stroke:?}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_healing_brush_keeps_its_status_line() {
|
||||
let mut app = app(Tool::Healing);
|
||||
stroke(&mut app);
|
||||
assert!(alerts(&app).is_empty());
|
||||
assert!(app.ui.status_error && app.ui.status.contains("source point to clone from"), "{}", app.ui.status);
|
||||
}
|
||||
@@ -286,7 +286,10 @@ pub(crate) fn close_box(ui: &mut egui::Ui, rect: egui::Rect) -> bool {
|
||||
/// The delete confirmations: a layer from the Layers panel's trash, a note (#11788), or all notes
|
||||
/// (#11791).
|
||||
fn delete_prompt(fields: &Fields) -> bool {
|
||||
crate::delete_layer_prompt::owns(fields) || crate::analysis_ui::owns_delete_note(fields) || crate::analysis_ui::owns_clear_notes(fields)
|
||||
crate::delete_layer_prompt::owns(fields)
|
||||
|| crate::analysis_ui::owns_delete_note(fields)
|
||||
|| crate::analysis_ui::owns_clear_notes(fields)
|
||||
|| live_shape_prompt::owns(fields)
|
||||
}
|
||||
|
||||
fn delete_prompt_body(ui: &mut egui::Ui, fields: &mut Fields) {
|
||||
@@ -294,6 +297,8 @@ fn delete_prompt_body(ui: &mut egui::Ui, fields: &mut Fields) {
|
||||
crate::analysis_ui::clear_notes_body(ui);
|
||||
} else if crate::analysis_ui::owns_delete_note(fields) {
|
||||
crate::analysis_ui::delete_note_body(ui, fields);
|
||||
} else if live_shape_prompt::owns(fields) {
|
||||
live_shape_prompt::body(ui, fields);
|
||||
} else {
|
||||
crate::delete_layer_prompt::body(ui, fields);
|
||||
}
|
||||
@@ -493,7 +498,7 @@ fn button_row(
|
||||
tl!("Reset")
|
||||
} else if d.kind == DialogKind::NewDocument {
|
||||
tl!("Close")
|
||||
} else if crate::analysis_ui::owns_delete_note(fields) {
|
||||
} else if crate::analysis_ui::owns_delete_note(fields) || live_shape_prompt::owns(fields) {
|
||||
tl!("No")
|
||||
} else {
|
||||
tl!("Cancel")
|
||||
@@ -564,7 +569,7 @@ fn ok_label(d: &Dialog) -> &'static str {
|
||||
tl!("Continue")
|
||||
} else if crate::delete_layer_prompt::owns(&d.fields) {
|
||||
tl!("Delete")
|
||||
} else if crate::analysis_ui::owns_delete_note(&d.fields) {
|
||||
} else if crate::analysis_ui::owns_delete_note(&d.fields) || live_shape_prompt::owns(&d.fields) {
|
||||
tl!("Yes")
|
||||
} else if crate::disk_change_prompt::owns(&d.fields) || crate::replace_prompt::owns(&d.fields) {
|
||||
tl!("Replace")
|
||||
@@ -899,6 +904,7 @@ const ROUTES: &[fn(&Fields) -> bool] = &[
|
||||
crate::delete_layer_prompt::owns,
|
||||
crate::analysis_ui::owns_delete_note,
|
||||
crate::analysis_ui::owns_clear_notes,
|
||||
live_shape_prompt::owns,
|
||||
crate::disk_change_prompt::owns,
|
||||
crate::actions::owns_stop_message,
|
||||
crate::actions::owns_insert_stop,
|
||||
@@ -1146,6 +1152,7 @@ fn confirm_command_more(app: &mut PhotocraftApp, d: Dialog) -> Result<Value, Str
|
||||
_ if merge_channels_ui::owns(&d.fields) => merge_channels_ui::confirm(app, &d.fields),
|
||||
_ if crate::analysis_ui::owns_delete_note(&d.fields) => crate::analysis_ui::confirm_delete_note(app, &d.fields),
|
||||
_ if crate::analysis_ui::owns_clear_notes(&d.fields) => crate::analysis_ui::confirm_clear_notes(app, &d.fields),
|
||||
_ if live_shape_prompt::owns(&d.fields) => live_shape_prompt::confirm(app, &d.fields),
|
||||
_ if crate::file_ui::owns(&d.fields) => crate::file_ui::confirm(app, &d.fields),
|
||||
_ if crate::new_guide_ui::owns(&d.fields) => crate::new_guide_ui::confirm(app, &d.fields),
|
||||
_ if crate::color_picker_ui::owns(&d.fields) => {
|
||||
@@ -1319,6 +1326,7 @@ mod label_column_tests;
|
||||
pub mod layer_picker;
|
||||
pub mod layer_style;
|
||||
pub mod liquify_ui;
|
||||
pub mod live_shape_prompt;
|
||||
pub mod mask_trash_prompt;
|
||||
pub mod merge_channels_ui;
|
||||
pub mod new_doc_ui;
|
||||
|
||||
@@ -5,14 +5,27 @@
|
||||
//! round. The Angle range is -359.99..359.99, wide, so today's wide-range rounding to one
|
||||
//! decimal decided the dialog's value; only this field now keeps hundredths.
|
||||
|
||||
use super::filter_dialog::{body, open, params_of};
|
||||
use super::filter_dialog::{body, open, params_of, reset_fields};
|
||||
use crate::PhotocraftApp;
|
||||
use serde_json::{Map, Value, json};
|
||||
|
||||
/// Draw a dialog body once, as a live dialog does every frame: the drawn fields are what
|
||||
/// the dialog shows and what OK sends.
|
||||
fn drawn(f: &mut Map<String, Value>) {
|
||||
egui::Context::default().run_ui(Default::default(), |ui| body(ui, f)).textures_delta.clear();
|
||||
drawn_texts(f);
|
||||
}
|
||||
|
||||
/// [`drawn`], returning the text the frame painted.
|
||||
fn drawn_texts(f: &mut Map<String, Value>) -> Vec<String> {
|
||||
let mut out = egui::Context::default().run_ui(Default::default(), |ui| body(ui, f));
|
||||
out.textures_delta.clear();
|
||||
out.shapes
|
||||
.iter()
|
||||
.filter_map(|s| match &s.shape {
|
||||
egui::Shape::Text(t) => Some(t.galley.text().to_string()),
|
||||
_ => None,
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// A 318 px square document (the size `ok_runs_the_two_decimal_angle` measures on), a ruler
|
||||
@@ -83,6 +96,29 @@ fn the_ruler_angle_rounds_at_full_precision_before_the_field_narrows() {
|
||||
assert_eq!(f["direction"], json!("ccw"));
|
||||
}
|
||||
|
||||
/// #13067: the 43x27 ruler's first drawn frame, after opening and again after Alt+Reset,
|
||||
/// shows the 32.12 the dialog stores (the unrounded pre-fill narrowed to exactly 32.125
|
||||
/// and drew 32.13 until the next repaint), and the dialog keeps that 32.12 as the exact
|
||||
/// f64 OK sends, not the 32.1199989 an f32 field value widens to.
|
||||
#[test]
|
||||
fn the_ruler_angle_shows_and_sends_the_exact_rounded_value() {
|
||||
let (mut app, id, mut f) = ruler_dialog([143, 127]);
|
||||
let check = |f: &mut Map<String, Value>, when: &str| {
|
||||
let shown = drawn_texts(f);
|
||||
assert!(shown.iter().any(|t| t == "32.12"), "{when}: the Angle field shows 32.12, drew {shown:?}");
|
||||
assert!(!shown.iter().any(|t| t == "32.13"), "{when}: the Angle field must not show 32.13, drew {shown:?}");
|
||||
assert_eq!(f["angle"].as_f64(), Some(32.12), "{when}: the dialog keeps the exact rounded angle");
|
||||
assert_eq!(params_of(f)["angle"].as_f64(), Some(32.12), "{when}: OK sends the exact rounded angle");
|
||||
};
|
||||
// `ruler_dialog` drew one frame already: the first frame draws the fields as opened.
|
||||
check(&mut app.ui.dialog_mut(id).unwrap().fields.clone(), "after opening");
|
||||
check(&mut f, "on the next frame");
|
||||
// Move off the pre-fill first, so only the reset can bring 32.12 back.
|
||||
f.insert("angle".into(), json!(5.0));
|
||||
reset_fields(&app, &mut f);
|
||||
check(&mut f, "after Alt+Reset");
|
||||
}
|
||||
|
||||
/// The fix is per-field: unrelated number fields keep the precision they have today —
|
||||
/// wide ranges round to one decimal (in another dialog, and under the same key name),
|
||||
/// small ranges keep their two.
|
||||
@@ -111,3 +147,19 @@ fn other_number_fields_keep_their_precision() {
|
||||
let x = f["centerX"].as_f64().unwrap();
|
||||
assert!((x - 0.12).abs() < 1e-5, "the Radial Blur centre {x} keeps its two decimals");
|
||||
}
|
||||
|
||||
/// The pre-fill is rounded before any frame draws: `ui.dialog.open` then `ui.dialog.confirm`
|
||||
/// can run without a draw between them, and the 43x27 ruler's raw 32.1249984 must not reach
|
||||
/// the command, after opening or after Alt+Reset.
|
||||
#[test]
|
||||
fn the_ruler_angle_is_rounded_before_the_first_frame() {
|
||||
let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default());
|
||||
app.run("file.new", json!({"width": 318, "height": 318})).unwrap();
|
||||
app.run("image.analysis.rulerTool", json!({"start": [100, 100], "end": [143, 127]})).unwrap();
|
||||
let id = open(&mut app, "image.rotation.arbitrary").unwrap();
|
||||
let mut f = app.ui.dialog_mut(id).unwrap().fields.clone();
|
||||
assert_eq!(params_of(&f)["angle"].as_f64(), Some(32.12), "undrawn, OK sends the rounded angle");
|
||||
f.insert("angle".into(), json!(5.0));
|
||||
reset_fields(&app, &mut f);
|
||||
assert_eq!(params_of(&f)["angle"].as_f64(), Some(32.12), "undrawn after Alt+Reset, OK sends the rounded angle");
|
||||
}
|
||||
@@ -47,6 +47,11 @@ pub fn closed(app: &mut PhotocraftApp, d: &Dialog) {
|
||||
if d.fields.get("skip").and_then(Value::as_bool) != Some(true) {
|
||||
return;
|
||||
}
|
||||
remember(app, pref);
|
||||
}
|
||||
|
||||
/// Keep "Don't show again" for the question remembered as `pref`, with the other dialog preferences.
|
||||
pub fn remember(app: &mut PhotocraftApp, pref: &str) {
|
||||
app.session.edit_prefs(|prefs| {
|
||||
prefs.dialogs.insert(pref.into(), json!({"skip": true}));
|
||||
});
|
||||
|
||||
@@ -693,7 +693,10 @@ fn straighten_defaults(app: &PhotocraftApp, fields: &mut Map<String, Value>) {
|
||||
if !rot.is_finite() {
|
||||
return;
|
||||
}
|
||||
fields.insert("angle".into(), json!(rot.abs()));
|
||||
// Rounded here, in f64, to the field's two decimals: `ui.dialog.open` then `ui.dialog.confirm`
|
||||
// can run with no frame drawn between them, and only a drawn frame rounds (#13067).
|
||||
let scale = 10f64.powi(wide_field_decimals("image.rotation.arbitrary", "angle").unwrap_or(2).min(6) as i32);
|
||||
fields.insert("angle".into(), json!((rot.abs() * scale).round() / scale));
|
||||
fields.insert("direction".into(), json!(if rot < 0.0 { "ccw" } else { "cw" }));
|
||||
}
|
||||
|
||||
@@ -1158,7 +1161,16 @@ pub fn body(ui: &mut egui::Ui, f: &mut Map<String, Value>) {
|
||||
}
|
||||
match p.kind {
|
||||
Kind::Range { min, max, default } => {
|
||||
let src = f.get(&p.key).and_then(Value::as_f64);
|
||||
// The field's shown precision: small ranges keep their two decimals, and so
|
||||
// does the Arbitrary angle; the other wide fields round to one (#12035).
|
||||
let scale = field_scale(&cmd, &p.key, min, max);
|
||||
let wide_decimals = wide_field_decimals(&cmd, &p.key).is_some();
|
||||
let round64 = |x: f64| (x * f64::from(scale)).round() / f64::from(scale);
|
||||
// A wide field showing two decimals rounds while the value is still f64, before
|
||||
// the widget narrows it: a 43x27 ruler is 32.1249984°, whose f32 cast lands
|
||||
// exactly on 32.125, and the field drew that half-away as 32.13 on the first
|
||||
// frame after opening or Alt+Reset, over the 32.12 it stored (#13067).
|
||||
let src = f.get(&p.key).and_then(Value::as_f64).map(|x| if wide_decimals { round64(x) } else { x });
|
||||
let mut v = src.unwrap_or(default as f64) as f32;
|
||||
// A widget edit this frame makes the field's f32 value authoritative (#12035).
|
||||
let mut edited = false;
|
||||
@@ -1209,18 +1221,15 @@ pub fn body(ui: &mut egui::Ui, f: &mut Map<String, Value>) {
|
||||
.changed();
|
||||
}
|
||||
});
|
||||
// The field's shown precision: small ranges keep their two decimals, and so
|
||||
// does the Arbitrary angle; the other wide fields round to one (#12035).
|
||||
let scale = field_scale(&cmd, &p.key, min, max);
|
||||
// A field showing two decimals rounds while the value is still f64: a 43x27
|
||||
// ruler is 32.1249984°, whose f32 cast lands exactly on 32.125, and rounding
|
||||
// that widened value half-away shows 32.13 where the pre-fill says 32.12.
|
||||
// Values the user typed or dragged are f32 already, so they round as before.
|
||||
let w = match (wide_field_decimals(&cmd, &p.key), src) {
|
||||
(Some(_), Some(raw)) if !edited => ((raw * f64::from(scale)).round() / f64::from(scale)) as f32,
|
||||
_ => (v * scale).round() / scale,
|
||||
// Such a field also keeps its rounded value as f64: stored as f32, 32.12 widens to
|
||||
// 32.1199989 and OK sends that to the command (#13067). A value the user typed or
|
||||
// dragged this frame is the widget's f32, so it rounds from that.
|
||||
let w = match (wide_decimals, src) {
|
||||
(true, Some(rounded)) if !edited => json!(rounded),
|
||||
(true, _) => json!(round64(f64::from(v))),
|
||||
(false, _) => json!((v * scale).round() / scale),
|
||||
};
|
||||
f.insert(p.key, json!(w));
|
||||
f.insert(p.key, w);
|
||||
}
|
||||
Kind::Choice { options, default } => {
|
||||
ui.horizontal(|ui| {
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
//! The question the Delete Anchor Point tool asks before it turns a live shape into a regular path
|
||||
//! (#12768): "This operation will turn a live shape into a regular path. Continue?", Yes (the
|
||||
//! default) and No, and a "Don't show again" box kept with the other dialog preferences. Yes runs
|
||||
//! the `path.deleteAnchor` the click would have run; No changes nothing.
|
||||
|
||||
use serde_json::{Map, Value, json};
|
||||
|
||||
use super::dont_show_again;
|
||||
use crate::PhotocraftApp;
|
||||
use crate::direct_select::{DirectSelection, PathRef};
|
||||
use crate::state::DialogKind;
|
||||
use photocraft_doc::{LayerContent, LayerId};
|
||||
|
||||
/// Marks the question; the dialog's fields carry the layer and the command's parameters.
|
||||
const MARK: &str = "__liveShapeDeleteAnchor";
|
||||
|
||||
/// Its "Don't show again", under `Preferences::dialogs`.
|
||||
pub const PREF: &str = "path.deleteAnchor.liveShape";
|
||||
|
||||
pub fn owns(fields: &Map<String, Value>) -> bool {
|
||||
fields.contains_key(MARK)
|
||||
}
|
||||
|
||||
/// Whether `r` is a live shape layer, such as a rectangle from the Rectangle tool in Shape mode.
|
||||
fn is_live(app: &PhotocraftApp, r: PathRef) -> bool {
|
||||
let PathRef::Layer(id) = r else { return false };
|
||||
app.session.active().and_then(|st| st.doc.layer(LayerId(id))).is_some_and(|layer| matches!(&layer.content, LayerContent::Shape(sh) if sh.live.is_some()))
|
||||
}
|
||||
|
||||
/// Ask before `path.deleteAnchor` with `params` runs on `r`. True when the question is open (or
|
||||
/// already was), so the caller stops; false when the deletion goes ahead: `r` is not a live shape
|
||||
/// or "Don't show again" was ticked.
|
||||
pub fn ask(app: &mut PhotocraftApp, r: PathRef, params: &Value) -> bool {
|
||||
let PathRef::Layer(layer) = r else { return false };
|
||||
let Some((document, revision)) = app.session.active().map(|st| (st.doc.id.0, st.revision)) else { return false };
|
||||
if !is_live(app, r) || dont_show_again::dismissed(app, PREF) {
|
||||
return false;
|
||||
}
|
||||
if app.ui.dialogs.iter().any(|d| owns(&d.fields)) {
|
||||
return true;
|
||||
}
|
||||
let mut f = Map::new();
|
||||
f.insert(MARK.into(), json!(true));
|
||||
f.insert("__command".into(), json!("path.deleteAnchor"));
|
||||
f.insert("__label".into(), json!(tl!("Delete Anchor Point")));
|
||||
f.insert("layer".into(), json!(layer));
|
||||
// The layer id means something only in this document (another may become active meanwhile),
|
||||
// and the knot index only in this revision of it (an edit meanwhile can shift the anchors).
|
||||
f.insert("__document".into(), json!(document));
|
||||
f.insert("__revision".into(), json!(revision));
|
||||
f.insert("params".into(), params.clone());
|
||||
f.insert("__dontShowAgain".into(), json!(PREF));
|
||||
f.insert("skip".into(), json!(false));
|
||||
app.ui.open_dialog(DialogKind::Command, f);
|
||||
true
|
||||
}
|
||||
|
||||
pub fn body(ui: &mut egui::Ui, fields: &mut Map<String, Value>) {
|
||||
ui.label(tl!("This operation will turn a live shape into a regular path. Continue?"));
|
||||
dont_show_again::body(ui, fields);
|
||||
}
|
||||
|
||||
/// Yes: the anchor goes in one "Delete Anchor Point" step, and a ticked "Don't show again" is kept.
|
||||
pub fn confirm(app: &mut PhotocraftApp, fields: &Map<String, Value>) -> Result<Value, String> {
|
||||
let layer = fields.get("layer").and_then(Value::as_u64).ok_or(tl!("No anchor to delete"))?;
|
||||
let params = fields.get("params").cloned().ok_or(tl!("No anchor to delete"))?;
|
||||
let asked = fields.get("__document").and_then(Value::as_u64).zip(fields.get("__revision").and_then(Value::as_u64));
|
||||
if asked.is_none() || app.session.active().map(|st| (st.doc.id.0, st.revision)) != asked {
|
||||
return Err(tl!("No anchor to delete").into());
|
||||
}
|
||||
let result = app.run("path.deleteAnchor", params)?;
|
||||
// The anchors shift: a Direct Selection on this path would point at the wrong ones.
|
||||
let r = PathRef::Layer(layer);
|
||||
if app.ui.direct_selection.target.as_ref() == Some(&r) {
|
||||
app.ui.direct_selection = DirectSelection { target: Some(r), ..Default::default() };
|
||||
}
|
||||
if fields.get("skip").and_then(Value::as_bool) == Some(true) {
|
||||
dont_show_again::remember(app, PREF);
|
||||
}
|
||||
Ok(result)
|
||||
}
|
||||
@@ -1097,3 +1097,6 @@ mod background_eraser_digit_keys_tests;
|
||||
mod clone_stamp_reset_tip_tests;
|
||||
#[cfg(test)]
|
||||
mod sponge_default_tip_tests;
|
||||
|
||||
#[cfg(test)]
|
||||
mod red_eye_context_menu_tests;
|
||||
@@ -92,7 +92,13 @@ pub fn options_bar(app: &mut PhotocraftApp, ui: &mut egui::Ui) {
|
||||
crate::chrome_ui::home_button(app, ui);
|
||||
widgets::vline(ui, 22.0);
|
||||
}
|
||||
let tool_icon = icons::button(ui, icons::tool_icon(app.ui.tool), if t.pro { 26.0 } else { 28.0 }, !t.pro, tl!(app.ui.tool.label()));
|
||||
// The tool preset picker is greyed while warping, as in the reference (#12503).
|
||||
let warping = app.ui.transform.as_ref().is_some_and(|s| s.warp.is_some());
|
||||
let tool_icon = ui
|
||||
.add_enabled_ui(!warping, |ui| {
|
||||
icons::button(ui, icons::tool_icon(app.ui.tool), if t.pro { 26.0 } else { 28.0 }, !t.pro, tl!(app.ui.tool.label()))
|
||||
})
|
||||
.inner;
|
||||
// Photoshop: right-click the tool icon for Reset Tool / Reset All Tools (#2825).
|
||||
let mut reset = None;
|
||||
tool_icon.context_menu(|ui| {
|
||||
|
||||
@@ -0,0 +1,205 @@
|
||||
//! #12577: a right-click on the canvas with the Red Eye tool opens the layer menu, or the
|
||||
//! selection menu with the pointer inside a selection, as measured in the reference application on
|
||||
//! a plain one-layer RGB document. The rows grey out like their menu-bar twins and run their
|
||||
//! commands; the right-click itself corrects no red eye and adds no history state. The cases that
|
||||
//! weren't measured keep opening nothing.
|
||||
|
||||
use egui::Modifiers;
|
||||
use serde_json::{Value, json};
|
||||
|
||||
use crate::PhotocraftApp;
|
||||
use crate::canvas_tool_menu::count_tests::{call, listed, right_click};
|
||||
use crate::canvas_tool_menu::{entry_enabled, rows};
|
||||
use crate::state::Tool;
|
||||
|
||||
/// A 64 × 48 RGB document with its one Background layer red, after a cleared selection (so
|
||||
/// Reselect has one to restore). The Red Eye tool is the tool.
|
||||
fn app() -> (PhotocraftApp, egui::Context) {
|
||||
let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default());
|
||||
app.run("file.new", json!({"width": 64, "height": 48, "background": "white"})).unwrap();
|
||||
app.run("edit.fill", json!({"contents": "color", "color": "#d01818"})).unwrap();
|
||||
app.run("select.rect", json!({"x": 4, "y": 4, "width": 10, "height": 10})).unwrap();
|
||||
app.run("select.deselect", json!({})).unwrap();
|
||||
app.sync_views();
|
||||
app.ui.tool = Tool::RedEye;
|
||||
(app, egui::Context::default())
|
||||
}
|
||||
|
||||
/// The open menu's rows as `ui.inspect` lists them: (label, enabled), "―" for separators.
|
||||
fn entries(app: &mut PhotocraftApp, ctx: &egui::Context) -> Vec<(String, bool)> {
|
||||
let inspected = call(app, ctx, "ui.inspect", json!({}));
|
||||
let entries = inspected.pointer("/result/canvasToolMenu/entries").and_then(Value::as_array).cloned().unwrap_or_default();
|
||||
entries.iter().map(|e| (e["label"].as_str().unwrap_or("―").to_string(), e["enabled"] != false)).collect()
|
||||
}
|
||||
|
||||
/// `want` as (label, enabled): the rows named in `grey` disabled, separators as "―".
|
||||
fn expected(want: &[&str], grey: &[&str]) -> Vec<(String, bool)> {
|
||||
want.iter().map(|l| (l.to_string(), *l == "―" || !grey.contains(l))).collect()
|
||||
}
|
||||
|
||||
/// The document's revision, history depth and journal length.
|
||||
fn state(app: &PhotocraftApp) -> (u64, usize, usize) {
|
||||
let st = app.session.active().unwrap();
|
||||
(st.revision, st.history.past_len(), app.session.journal.len())
|
||||
}
|
||||
|
||||
const NO_SELECTION: [&str; 17] = [
|
||||
"Blending Options…",
|
||||
"―",
|
||||
"Duplicate Layer…",
|
||||
"Delete Layer",
|
||||
"Group from Layers…",
|
||||
"―",
|
||||
"Convert to Smart Object",
|
||||
"Convert to Layers",
|
||||
"―",
|
||||
"Rasterize Layer",
|
||||
"Rasterize Layer Style",
|
||||
"―",
|
||||
"Free Transform",
|
||||
"―",
|
||||
"Color Range…",
|
||||
"Load Selection…",
|
||||
"Reselect",
|
||||
];
|
||||
|
||||
/// The reference also greys Group from Layers… and Load Selection…, but their menu-bar twins are
|
||||
/// live here (as in the Count tool's menu), and the rows follow the twins.
|
||||
const NO_SELECTION_GREY: [&str; 5] = ["Blending Options…", "Convert to Layers", "Rasterize Layer", "Rasterize Layer Style", "Free Transform"];
|
||||
|
||||
const IN_SELECTION: [&str; 23] = [
|
||||
"Deselect",
|
||||
"Select Inverse",
|
||||
"Feather…",
|
||||
"Select and Mask…",
|
||||
"―",
|
||||
"Save Selection…",
|
||||
"Make Work Path…",
|
||||
"―",
|
||||
"Layer Via Copy",
|
||||
"Layer Via Cut",
|
||||
"New Layer…",
|
||||
"―",
|
||||
"Free Transform",
|
||||
"Transform Selection",
|
||||
"―",
|
||||
"Fill…",
|
||||
"Stroke…",
|
||||
"Content-Aware Fill…",
|
||||
"Delete and Fill Selection",
|
||||
"―",
|
||||
"Last Filter",
|
||||
"―",
|
||||
"Fade…",
|
||||
];
|
||||
|
||||
fn select(app: &mut PhotocraftApp) {
|
||||
app.run("select.rect", json!({"x": 10, "y": 10, "width": 20, "height": 20})).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn without_a_selection_the_layer_menu_opens_in_order_with_the_reference_greys() {
|
||||
let (mut app, ctx) = app();
|
||||
right_click(&mut app, &ctx, 40.0, 30.0);
|
||||
assert_eq!(entries(&mut app, &ctx), expected(&NO_SELECTION, &NO_SELECTION_GREY));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn inside_a_selection_the_selection_menu_opens_in_order_with_the_reference_greys() {
|
||||
let (mut app, ctx) = app();
|
||||
select(&mut app);
|
||||
right_click(&mut app, &ctx, 20.0, 20.0);
|
||||
assert_eq!(entries(&mut app, &ctx), expected(&IN_SELECTION, &["Last Filter", "Fade…"]));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rows_grey_out_like_their_menu_bar_twins() {
|
||||
for selection in [false, true] {
|
||||
let (mut app, ctx) = app();
|
||||
if selection {
|
||||
select(&mut app);
|
||||
}
|
||||
right_click(&mut app, &ctx, 20.0, 20.0);
|
||||
let menu = app.ui.canvas_tool_menu.clone().unwrap();
|
||||
for (_, id) in rows(&menu).iter().flatten() {
|
||||
assert_eq!(entry_enabled(&app, &menu, id), crate::menus::is_enabled(&app, id), "{id} (selection: {selection})");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn picking_a_row_runs_its_command() {
|
||||
let (mut app, ctx) = app();
|
||||
select(&mut app);
|
||||
right_click(&mut app, &ctx, 20.0, 20.0);
|
||||
assert_eq!(call(&mut app, &ctx, "ui.context.choose", json!({"id": "select.deselect"}))["ok"], true);
|
||||
assert!(app.session.active().unwrap().doc.selection.is_none(), "Deselect deselected");
|
||||
assert!(app.ui.canvas_tool_menu.is_none(), "the pick closes the menu");
|
||||
right_click(&mut app, &ctx, 20.0, 20.0);
|
||||
assert_eq!(call(&mut app, &ctx, "ui.context.choose", json!({"id": "select.reselect"}))["ok"], true);
|
||||
assert!(app.session.active().unwrap().doc.selection.is_some(), "Reselect brought it back");
|
||||
// A row the open menu doesn't have is refused.
|
||||
right_click(&mut app, &ctx, 20.0, 20.0);
|
||||
assert_eq!(call(&mut app, &ctx, "ui.context.choose", json!({"id": "select.colorRange"}))["ok"], false);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_right_click_corrects_no_red_eye_and_adds_no_history_state() {
|
||||
for selection in [false, true] {
|
||||
let (mut app, ctx) = app();
|
||||
if selection {
|
||||
select(&mut app);
|
||||
}
|
||||
let before = state(&app);
|
||||
right_click(&mut app, &ctx, 20.0, 20.0);
|
||||
assert!(app.ui.canvas_tool_menu.is_some(), "the menu is open (selection: {selection})");
|
||||
assert_eq!(state(&app), before, "nothing ran (selection: {selection})");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_mouse_right_click_on_the_canvas_opens_the_layer_menu() {
|
||||
let (app, _) = app();
|
||||
let mut h = crate::canvas_tool_menu::tests::harness(app);
|
||||
let before = state(h.state());
|
||||
let center = h.state().last_canvas_rect.center();
|
||||
crate::canvas_tool_menu::tests::right_click(&mut h, center, Modifiers::NONE);
|
||||
let menu = h.state().ui.canvas_tool_menu.clone().expect("the menu opens");
|
||||
let labels: Vec<&str> = rows(&menu).iter().map(|r| r.map_or("―", |(l, _)| l)).collect();
|
||||
assert_eq!(labels, NO_SELECTION);
|
||||
assert_eq!(state(h.state()), before, "no correction, no history state");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_cases_not_measured_keep_opening_nothing() {
|
||||
type Setup = fn(&mut PhotocraftApp);
|
||||
let cases: [(&str, Setup); 5] = [
|
||||
("outside the selection", |app| app.run("select.rect", json!({"x": 40, "y": 30, "width": 10, "height": 10})).map(drop).unwrap()),
|
||||
("a second layer", |app| app.run("layer.new.layer", json!({"name": "Ink"})).map(drop).unwrap()),
|
||||
("a smart object", |app| app.run("layer.smartObjects.convertToSmartObject", json!({})).map(drop).unwrap()),
|
||||
("a type layer", |app| {
|
||||
let background = app.session.active().unwrap().doc.layers[0].id.0;
|
||||
app.run("type.create", json!({"text": "Eyes", "size": 12, "x": 4, "y": 20})).unwrap();
|
||||
app.run("layer.select", json!({"layer": background})).unwrap();
|
||||
app.run("layer.delete", json!({})).unwrap();
|
||||
}),
|
||||
("Grayscale", |app| app.run("image.mode.grayscale", json!({})).map(drop).unwrap()),
|
||||
];
|
||||
for (what, setup) in cases {
|
||||
let (mut app, ctx) = app();
|
||||
setup(&mut app);
|
||||
let before = state(&app);
|
||||
right_click(&mut app, &ctx, 20.0, 20.0);
|
||||
assert!(app.ui.canvas_tool_menu.is_none(), "{what}: no menu");
|
||||
assert!(listed(&mut app, &ctx).is_empty(), "{what}");
|
||||
assert_eq!(state(&app), before, "{what}: nothing ran");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn outside_the_image_with_a_selection_the_pasteboard_menu_opens_as_before() {
|
||||
let (mut app, ctx) = app();
|
||||
select(&mut app);
|
||||
right_click(&mut app, &ctx, -10.0, 20.0);
|
||||
assert!(app.ui.canvas_tool_menu.as_ref().is_some_and(|m| m.pasteboard), "the pasteboard colour menu");
|
||||
}
|
||||
@@ -73,3 +73,6 @@ mod gradient_options_bar_mode_tests;
|
||||
mod gradient_refusal_messages_tests;
|
||||
#[cfg(test)]
|
||||
mod line_tool_defaults_tests;
|
||||
|
||||
#[cfg(test)]
|
||||
mod remove_default_size_tests;
|
||||
@@ -213,6 +213,10 @@ fn apply(app: &mut PhotocraftApp, r: PathRef, hit: Hit, p: [f64; 2]) {
|
||||
if let (Some(o), Some(t)) = (params.as_object_mut(), r.params(app).as_object()) {
|
||||
o.extend(t.clone());
|
||||
}
|
||||
// A live shape becomes a regular path: ask first (#12768).
|
||||
if id == "path.deleteAnchor" && crate::dialogs::live_shape_prompt::ask(app, r, ¶ms) {
|
||||
return;
|
||||
}
|
||||
match app.run(id, params) {
|
||||
Ok(v) if coalesce.is_some() => {
|
||||
let n = |f: &str| v["anchor"][f].as_u64().and_then(|v| usize::try_from(v).ok());
|
||||
@@ -275,6 +279,8 @@ mod add_anchor_lock_tests;
|
||||
#[cfg(test)]
|
||||
mod add_anchor_targeted_path_tests;
|
||||
#[cfg(test)]
|
||||
mod delete_anchor_live_shape_tests;
|
||||
#[cfg(test)]
|
||||
mod delete_anchor_lock_tests;
|
||||
#[cfg(test)]
|
||||
pub(crate) mod delete_anchor_targeted_path_tests;
|
||||
|
||||
@@ -0,0 +1,184 @@
|
||||
//! #12768: a click with the Delete Anchor Point tool on an anchor of a live shape asks "This
|
||||
//! operation will turn a live shape into a regular path. Continue?" first: Yes deletes it, No
|
||||
//! changes nothing, and "Don't show again" skips the question later.
|
||||
|
||||
use egui_kittest::kittest::Queryable;
|
||||
use serde_json::{Value, json};
|
||||
|
||||
use super::delete_anchor_targeted_path_tests::{click, select_layer, select_saved_path, setup_asking, shape_path, steps};
|
||||
use crate::PhotocraftApp;
|
||||
use crate::state::Tool;
|
||||
|
||||
const QUESTION: &str = "This operation will turn a live shape into a regular path. Continue?";
|
||||
/// The live rectangle's bottom-right corner.
|
||||
const CORNER: [f64; 2] = [650.0, 250.0];
|
||||
|
||||
/// The tool with the live rectangle active.
|
||||
fn live(tool: Tool) -> (PhotocraftApp, u64) {
|
||||
let (mut app, shape) = setup_asking(tool);
|
||||
select_layer(&mut app, shape);
|
||||
(app, shape)
|
||||
}
|
||||
|
||||
fn info(app: &mut PhotocraftApp, shape: u64) -> Value {
|
||||
app.run("shape.info", json!({"layer": shape})).unwrap()
|
||||
}
|
||||
|
||||
fn question(app: &PhotocraftApp) -> Option<u64> {
|
||||
app.ui.dialogs.iter().find(|d| d.fields.get("__command").and_then(Value::as_str) == Some("path.deleteAnchor")).map(|d| d.id)
|
||||
}
|
||||
|
||||
fn corners(app: &mut PhotocraftApp, shape: u64) -> usize {
|
||||
shape_path(app, shape)["subpaths"][0]["knots"].as_array().unwrap().len()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_click_on_a_live_shape_anchor_asks_with_yes_no_and_an_unticked_box() {
|
||||
let (mut app, shape) = live(Tool::DeleteAnchorPoint);
|
||||
let (before, n) = (info(&mut app, shape), steps(&app));
|
||||
click(&mut app, CORNER);
|
||||
let id = question(&app).expect("the question");
|
||||
assert_eq!(info(&mut app, shape), before, "nothing goes before the answer");
|
||||
assert_eq!(steps(&app), n);
|
||||
assert_eq!(app.ui.dialog_mut(id).unwrap().fields["skip"], json!(false));
|
||||
// Like the Preferences kittest: the dialog draws in the semibold family, which a build without the fonts lacks.
|
||||
let has_fonts = |ctx: &egui::Context| ctx.fonts(|f| f.families().contains(&egui::FontFamily::Name("semibold".into())));
|
||||
let mut h = egui_kittest::Harness::builder().with_size(egui::vec2(1000.0, 700.0)).build_ui_state(
|
||||
move |ui, app| {
|
||||
if has_fonts(ui.ctx()) {
|
||||
crate::dialogs::show(app, ui.ctx());
|
||||
}
|
||||
},
|
||||
app,
|
||||
);
|
||||
PhotocraftApp::setup_context(&h.ctx, Default::default());
|
||||
h.run_steps(5);
|
||||
if !has_fonts(&h.ctx) {
|
||||
return;
|
||||
}
|
||||
h.get_by_label(QUESTION);
|
||||
h.get_by_label("Yes");
|
||||
h.get_by_label("No");
|
||||
h.get_by_label("Don't show again");
|
||||
// Enter is Yes.
|
||||
h.key_press(egui::Key::Enter);
|
||||
h.run_steps(5);
|
||||
let app = h.state_mut();
|
||||
assert!(question(app).is_none());
|
||||
assert_eq!(info(app, shape)["live"], Value::Null);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn yes_deletes_the_anchor_and_the_layer_is_no_longer_live() {
|
||||
let (mut app, shape) = live(Tool::DeleteAnchorPoint);
|
||||
let n = steps(&app);
|
||||
click(&mut app, CORNER);
|
||||
let id = question(&app).expect("the question");
|
||||
crate::dialogs::confirm(&mut app, id).unwrap();
|
||||
assert_eq!(corners(&mut app, shape), 3);
|
||||
let info = info(&mut app, shape);
|
||||
assert_eq!((&info["live"], &info["kind"]), (&Value::Null, &json!("path")));
|
||||
assert_eq!(steps(&app), n + 1);
|
||||
assert_eq!(app.session.active().unwrap().history.undo_label(), Some("Delete Anchor Point"));
|
||||
}
|
||||
|
||||
/// The question belongs to the document it was asked in: Yes after another document became active
|
||||
/// is refused and changes nothing there (layer ids are unique in a session, so this guards the
|
||||
/// binding the way the Color Picker's `__document` does), and the question's own document keeps
|
||||
/// its shape.
|
||||
#[test]
|
||||
fn yes_after_another_document_became_active_deletes_nothing() {
|
||||
let (mut app, shape) = live(Tool::DeleteAnchorPoint);
|
||||
click(&mut app, CORNER);
|
||||
let id = question(&app).expect("the question");
|
||||
let first = app.session.active_index();
|
||||
app.session.execute("file.new", json!({"width": 800, "height": 600})).unwrap();
|
||||
app.sync_views();
|
||||
let other = app.run("shape.create", json!({"kind": "rect", "rect": [450, 100, 200, 150], "fill": "#3070c0"})).unwrap()["layer"].as_u64().unwrap();
|
||||
assert_ne!(app.session.active_index(), first, "the new document is active");
|
||||
let (before, n) = (shape_path(&mut app, other), steps(&app));
|
||||
assert!(crate::dialogs::confirm(&mut app, id).is_err());
|
||||
assert_eq!((shape_path(&mut app, other), steps(&app)), (before, n));
|
||||
assert!(app.session.set_active(first.unwrap()));
|
||||
app.sync_views();
|
||||
assert_eq!(corners(&mut app, shape), 4, "the first document's shape keeps its corner");
|
||||
}
|
||||
|
||||
/// The question's knot index belongs to the path as it was asked: an anchor added before the
|
||||
/// corner meanwhile (through the control channel; the question is modal on screen) shifts it, so Yes
|
||||
/// is refused instead of deleting another anchor.
|
||||
#[test]
|
||||
fn yes_after_the_path_changed_deletes_nothing() {
|
||||
let (mut app, shape) = live(Tool::DeleteAnchorPoint);
|
||||
click(&mut app, CORNER);
|
||||
let id = question(&app).expect("the question");
|
||||
app.run("path.addAnchor", json!({"name": "layer", "layer": shape, "subpath": 0, "knot": 0, "t": 0.5})).unwrap();
|
||||
let (before, n) = (shape_path(&mut app, shape), steps(&app));
|
||||
assert!(crate::dialogs::confirm(&mut app, id).is_err());
|
||||
assert_eq!((shape_path(&mut app, shape), steps(&app)), (before, n));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn no_leaves_the_shape_its_parameters_and_history_unchanged() {
|
||||
let (mut app, shape) = live(Tool::DeleteAnchorPoint);
|
||||
let (before, n) = (info(&mut app, shape), steps(&app));
|
||||
click(&mut app, CORNER);
|
||||
let id = question(&app).expect("the question");
|
||||
crate::dialogs::cancel(&mut app, id).unwrap();
|
||||
assert_eq!(info(&mut app, shape), before);
|
||||
assert_ne!(before["live"], Value::Null);
|
||||
assert_eq!(steps(&app), n);
|
||||
// Not recorded: the next click asks again.
|
||||
click(&mut app, CORNER);
|
||||
assert!(question(&app).is_some());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn yes_with_dont_show_again_deletes_later_clicks_at_once() {
|
||||
let (mut app, shape) = live(Tool::DeleteAnchorPoint);
|
||||
click(&mut app, CORNER);
|
||||
let id = question(&app).expect("the question");
|
||||
app.ui.dialog_mut(id).unwrap().fields.insert("skip".into(), json!(true));
|
||||
crate::dialogs::confirm(&mut app, id).unwrap();
|
||||
// A second live shape: its anchor goes at once.
|
||||
let other = app.run("shape.create", json!({"kind": "rect", "rect": [100, 100, 100, 100], "fill": "#c03030"})).unwrap()["layer"].as_u64().unwrap();
|
||||
assert_ne!(info(&mut app, other)["live"], Value::Null);
|
||||
let n = steps(&app);
|
||||
click(&mut app, [200.0, 200.0]);
|
||||
assert!(question(&app).is_none());
|
||||
assert_eq!(corners(&mut app, other), 3);
|
||||
assert_eq!(info(&mut app, other)["live"], Value::Null);
|
||||
assert_eq!(steps(&app), n + 1);
|
||||
assert_eq!(corners(&mut app, shape), 3);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_shape_that_is_not_live_or_a_saved_path_deletes_without_the_question() {
|
||||
let (mut app, shape) = live(Tool::DeleteAnchorPoint);
|
||||
let path = json!({"subpaths": [{"closed": true, "knots": [[450, 100], [650, 100], [650, 250], [450, 250]]}]});
|
||||
app.run("shape.edit", json!({"layer": shape, "path": path})).unwrap();
|
||||
assert_eq!(info(&mut app, shape)["live"], Value::Null);
|
||||
let n = steps(&app);
|
||||
click(&mut app, CORNER);
|
||||
assert!(question(&app).is_none());
|
||||
assert_eq!(corners(&mut app, shape), 3);
|
||||
assert_eq!(steps(&app), n + 1);
|
||||
// A saved path.
|
||||
let (mut app, _) = live(Tool::DeleteAnchorPoint);
|
||||
select_saved_path(&mut app);
|
||||
let n = steps(&app);
|
||||
click(&mut app, [150.0, 550.0]);
|
||||
assert!(question(&app).is_none());
|
||||
assert_eq!(steps(&app), n + 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn add_anchor_point_on_a_live_shape_converts_it_without_the_question() {
|
||||
let (mut app, shape) = live(Tool::AddAnchorPoint);
|
||||
let n = steps(&app);
|
||||
click(&mut app, [550.0, 100.0]);
|
||||
assert!(question(&app).is_none());
|
||||
assert_eq!(corners(&mut app, shape), 5);
|
||||
assert_eq!(info(&mut app, shape)["live"], Value::Null);
|
||||
assert_eq!(steps(&app), n + 1);
|
||||
}
|
||||
@@ -12,6 +12,14 @@ use crate::state::Tool;
|
||||
/// 800 x 600, white Background, pixel layer "Red" active, and a shape layer from (450,100) to
|
||||
/// (650,250) below it in the stack's activity (Red stays the active layer).
|
||||
pub(crate) fn setup(tool: Tool) -> (PhotocraftApp, u64) {
|
||||
let (mut app, shape) = setup_asking(tool);
|
||||
// These tests predate the live-shape question (#12768) and keep testing targeting and locks.
|
||||
crate::dialogs::dont_show_again::remember(&mut app, crate::dialogs::live_shape_prompt::PREF);
|
||||
(app, shape)
|
||||
}
|
||||
|
||||
/// [`setup`] with the live-shape question still on.
|
||||
pub(super) fn setup_asking(tool: Tool) -> (PhotocraftApp, u64) {
|
||||
let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default());
|
||||
app.session.execute("file.new", json!({"width": 800, "height": 600})).unwrap();
|
||||
app.sync_views();
|
||||
|
||||
@@ -90,7 +90,7 @@ pub fn prompt(app: &mut PhotocraftApp, message: &str) {
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "../brush_refusal_alert_tests.rs"]
|
||||
mod brush_refusal_alert_tests;
|
||||
pub(super) mod brush_refusal_alert_tests;
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "../sharpen_refusal_alert_tests.rs"]
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
//! #12548: the Remove tool starts, and comes back after Reset Tool, with the reference
|
||||
//! application's 19 px brush. Its hardness and spacing are not measured and keep today's values:
|
||||
//! the default brush's after a reset, the current brush's on a first use. Other tools' starting
|
||||
//! sizes are unchanged.
|
||||
|
||||
use serde_json::json;
|
||||
|
||||
use crate::PhotocraftApp;
|
||||
use crate::burn_default_tip_tests::{app, invoke, pick};
|
||||
use crate::state::Tool;
|
||||
|
||||
/// Size, hardness and spacing of the live brush, as `brush.get` reports them.
|
||||
fn tip(app: &mut PhotocraftApp) -> [f64; 3] {
|
||||
let b = app.run("brush.get", json!({})).unwrap();
|
||||
["size", "hardness", "spacing"].map(|k| (b[k].as_f64().unwrap() * 1e4).round() / 1e4)
|
||||
}
|
||||
|
||||
/// A brush no tool starts with, so a reset or a first use has something to change.
|
||||
fn scramble(app: &mut PhotocraftApp) {
|
||||
let b = &mut app.session.tools.brush;
|
||||
(b.size, b.hardness, b.spacing) = (57.0, 0.4, 0.6);
|
||||
}
|
||||
|
||||
/// 19 px, with the default brush's hardness and spacing (what Reset Tool gave it before).
|
||||
const REMOVE_TIP: [f64; 3] = [19.0, 1.0, 0.1];
|
||||
|
||||
#[test]
|
||||
fn reset_tool_gives_the_remove_tool_a_19_px_brush() {
|
||||
let mut app = app();
|
||||
pick(&mut app, Tool::Remove);
|
||||
scramble(&mut app);
|
||||
invoke(&mut app, "tool.reset", json!({}));
|
||||
assert_eq!(tip(&mut app), REMOVE_TIP);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_first_use_starts_at_19_px() {
|
||||
// No stored tool brushes, as on a fresh install: the Remove tool's first pick, after another
|
||||
// tool's brush.
|
||||
let mut app = app();
|
||||
pick(&mut app, Tool::Pencil);
|
||||
scramble(&mut app);
|
||||
pick(&mut app, Tool::Remove);
|
||||
// Only the size is measured: the hardness and spacing are still the previous tool's.
|
||||
assert_eq!(tip(&mut app), [19.0, 0.4, 0.6]);
|
||||
// Its own size is then kept across tool switches.
|
||||
app.session.tools.brush.size = 42.0;
|
||||
pick(&mut app, Tool::Pencil);
|
||||
pick(&mut app, Tool::Remove);
|
||||
assert_eq!(tip(&mut app)[0], 42.0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn reset_all_tools_gives_it_19_px_active_or_picked_later() {
|
||||
let mut app = app();
|
||||
pick(&mut app, Tool::Remove);
|
||||
scramble(&mut app);
|
||||
invoke(&mut app, "tool.resetAll", json!({"confirmed": true}));
|
||||
assert_eq!(tip(&mut app), REMOVE_TIP, "active");
|
||||
let mut app = self::app();
|
||||
pick(&mut app, Tool::Remove);
|
||||
scramble(&mut app);
|
||||
pick(&mut app, Tool::Pencil);
|
||||
invoke(&mut app, "tool.resetAll", json!({"confirmed": true}));
|
||||
pick(&mut app, Tool::Remove);
|
||||
assert_eq!(tip(&mut app), REMOVE_TIP, "picked after the reset");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn other_tools_keep_their_reset_sizes() {
|
||||
for (tool, want) in
|
||||
[(Tool::Brush, 13.0), (Tool::Pencil, 20.0), (Tool::Eraser, 20.0), (Tool::SpotHealing, 20.0), (Tool::Healing, 19.0), (Tool::CloneStamp, 21.0)]
|
||||
{
|
||||
let mut a = app();
|
||||
pick(&mut a, tool);
|
||||
scramble(&mut a);
|
||||
invoke(&mut a, "tool.reset", json!({}));
|
||||
assert_eq!(tip(&mut a)[0], want, "{tool:?}");
|
||||
}
|
||||
// The Spot Healing Brush's first use still takes the current brush, as before.
|
||||
let mut a = app();
|
||||
pick(&mut a, Tool::Pencil);
|
||||
scramble(&mut a);
|
||||
pick(&mut a, Tool::SpotHealing);
|
||||
assert_eq!(tip(&mut a)[0], 57.0, "Spot Healing Brush, first use");
|
||||
}
|
||||
@@ -198,6 +198,21 @@ pub(crate) fn stroke_seed(points: &[[f64; 3]]) -> u64 {
|
||||
photocraft_engine::paint::rng::seed_from_bytes(first.as_bytes())
|
||||
}
|
||||
|
||||
/// A Clone Stamp press with no source point yet: the reference application's alert, opened at
|
||||
/// the press (#12609) and once while it is up. Returns whether it refused the stroke.
|
||||
pub(crate) fn clone_stamp_without_source(app: &mut PhotocraftApp, tool: Tool) -> bool {
|
||||
if tool != Tool::CloneStamp || clone_params(app).is_some() {
|
||||
return false;
|
||||
}
|
||||
let message = if cfg!(target_os = "macos") {
|
||||
tl!("Could not use the clone stamp tool because the area to clone has not been defined (Option-click to define a source point).")
|
||||
} else {
|
||||
tl!("Could not use the clone stamp tool because the area to clone has not been defined (Alt-click to define a source point).")
|
||||
};
|
||||
open_alert_once(app, message);
|
||||
true
|
||||
}
|
||||
|
||||
/// Finish a stroke with a retouching tool. Returns false if `tool` isn't one.
|
||||
pub fn finish_stroke(app: &mut PhotocraftApp, tool: Tool, points: &[[f64; 3]], mods: egui::Modifiers, line: bool) -> bool {
|
||||
finish_stroke_with(app, tool, points, mods, line, None)
|
||||
@@ -224,6 +239,9 @@ pub(crate) fn finish_stroke_with(app: &mut PhotocraftApp, tool: Tool, points: &[
|
||||
return true;
|
||||
}
|
||||
let Some(p) = clone_params(app) else {
|
||||
if clone_stamp_without_source(app, tool) {
|
||||
return true;
|
||||
}
|
||||
// Option-click on the Mac, Alt-click on Windows.
|
||||
app.ui.status = if cfg!(target_os = "macos") {
|
||||
tl!("Option-click to define a source point to clone from")
|
||||
@@ -783,7 +801,8 @@ fn cam_amount_slider(ui: &mut egui::Ui, name: &str, value: &mut f32, lo: f32, hi
|
||||
});
|
||||
}
|
||||
|
||||
fn open_cam_range_alert(app: &mut PhotocraftApp, message: &str) {
|
||||
/// Opens the alert with `message` (English, translated here) unless it is already up.
|
||||
fn open_alert_once(app: &mut PhotocraftApp, message: &str) {
|
||||
let message = tl!(message).to_owned();
|
||||
let shown =
|
||||
app.ui.dialogs.iter().any(|d| d.kind == crate::state::DialogKind::Error && d.fields.get("message").and_then(|m| m.as_str()) == Some(message.as_str()));
|
||||
@@ -807,11 +826,11 @@ fn content_aware_move_bar(app: &mut PhotocraftApp, ui: &mut egui::Ui) {
|
||||
}
|
||||
opt(ui, tl!("Structure:"));
|
||||
if cam_integer_popup(ui, "cam-structure", "Structure", &mut app.ui.tool_options.cam_structure, 1.0, 7.0, STRUCTURE_TIP) {
|
||||
open_cam_range_alert(app, STRUCTURE_RANGE_ALERT);
|
||||
open_alert_once(app, STRUCTURE_RANGE_ALERT);
|
||||
}
|
||||
opt(ui, tl!("Color:"));
|
||||
if cam_integer_popup(ui, "cam-color", "Color", &mut app.ui.tool_options.cam_color, 0.0, 10.0, COLOR_TIP) {
|
||||
open_cam_range_alert(app, COLOR_RANGE_ALERT);
|
||||
open_alert_once(app, COLOR_RANGE_ALERT);
|
||||
}
|
||||
crate::widgets::checkbox(ui, &mut app.ui.tool_options.sample_all.content_aware_move, tl!("Sample All Layers"))
|
||||
.on_hover_text(tl!("Enable to remix all layers"));
|
||||
@@ -1207,3 +1226,7 @@ mod sponge_flow_field_tests;
|
||||
#[cfg(test)]
|
||||
#[path = "../healing_indexed_alert_tests.rs"]
|
||||
mod healing_indexed_alert_tests;
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "../clone_stamp_no_source_alert_tests.rs"]
|
||||
mod clone_stamp_no_source_alert_tests;
|
||||
@@ -225,15 +225,15 @@ fn paint_bucket_mode_reaches_the_fill() {
|
||||
|
||||
#[test]
|
||||
fn clone_without_a_source_names_the_platform_modifier() {
|
||||
// Option-click on the Mac, Alt-click elsewhere (#251).
|
||||
for tool in [Tool::CloneStamp, Tool::Healing] {
|
||||
let mut app = app();
|
||||
app.ui.tool = tool;
|
||||
assert!(finish_stroke(&mut app, tool, &[[10.0, 30.0, 1.0], [50.0, 30.0, 1.0]], egui::Modifiers::NONE, false));
|
||||
assert!(app.ui.status_error, "{tool:?}");
|
||||
let want = if cfg!(target_os = "macos") { "Option-click" } else { "Alt-click" };
|
||||
assert!(app.ui.status.starts_with(want), "{tool:?}: {}", app.ui.status);
|
||||
}
|
||||
// Option-click on the Mac, Alt-click elsewhere (#251). The Clone Stamp says it in an alert
|
||||
// (#12609, clone_stamp_no_source_alert_tests.rs).
|
||||
let tool = Tool::Healing;
|
||||
let mut app = app();
|
||||
app.ui.tool = tool;
|
||||
assert!(finish_stroke(&mut app, tool, &[[10.0, 30.0, 1.0], [50.0, 30.0, 1.0]], egui::Modifiers::NONE, false));
|
||||
assert!(app.ui.status_error);
|
||||
let want = if cfg!(target_os = "macos") { "Option-click" } else { "Alt-click" };
|
||||
assert!(app.ui.status.starts_with(want), "{}", app.ui.status);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -824,6 +824,7 @@ fn waiting_remove_strokes_keep_their_own_brush() {
|
||||
let mut app = app();
|
||||
app.run("paint.pencil", json!({"points": [[0, 30], [100, 30]], "size": 200, "color": "#808080"})).unwrap();
|
||||
app.ui.tool = Tool::Remove;
|
||||
crate::paint_mouse::sync_tool_brush(&mut app);
|
||||
app.ui.tool_options.remove_after_each_stroke = false;
|
||||
let m = egui::Modifiers::NONE;
|
||||
let stroke = |app: &mut PhotocraftApp, x: f64| {
|
||||
|
||||
@@ -267,7 +267,7 @@ fn reference_point_toggle(ui: &mut egui::Ui, on: &mut bool) -> bool {
|
||||
// The catalogue's "Toggle reference point" (sentence case, like the grid's tooltip).
|
||||
let label = tl!("Toggle reference point");
|
||||
resp.widget_info(|| egui::WidgetInfo::selected(egui::Role::CheckBox, true, *on, label));
|
||||
resp.on_hover_text(label);
|
||||
resp.on_hover_text(label).on_disabled_hover_text(label);
|
||||
*on
|
||||
}
|
||||
|
||||
@@ -374,7 +374,7 @@ fn anchor_grid_widget(ui: &mut egui::Ui, current_anchor: Option<usize>, enabled:
|
||||
painter.rect_filled(pt_rect, 0.5, if enabled { color } else { color.gamma_multiply(0.4) });
|
||||
}
|
||||
}
|
||||
resp.on_hover_text(tl!("Reference point location"));
|
||||
resp.on_hover_text(tl!("Reference point location")).on_disabled_hover_text(tl!("Reference point location"));
|
||||
clicked
|
||||
}
|
||||
|
||||
@@ -467,6 +467,14 @@ fn warp_fields(app: &mut PhotocraftApp, ui: &mut egui::Ui, w: &Warp) {
|
||||
let on_type = warps_type(app);
|
||||
// A cylinder has no splits or grid either (#4112): its handles are its own.
|
||||
let cylinder = w.style == WarpStyle::Cylinder;
|
||||
// Free Transform's reference point check box and grid keep their slots, greyed and inert, as
|
||||
// in the reference (#12503): on, at the centre. The disabled `Ui` greys the grid once; its own
|
||||
// greying (for Toggle Reference Point off) would dim it again.
|
||||
ui.add_enabled_ui(false, |ui| {
|
||||
reference_point_toggle(ui, &mut true);
|
||||
anchor_grid_widget(ui, Some(4), true);
|
||||
});
|
||||
crate::widgets::vline(ui, 22.0);
|
||||
// Split, Grid, then the warp style with its bend fields.
|
||||
ui.add_enabled_ui(!on_type && !cylinder, |ui| warp_mesh_fields(app, ui, w));
|
||||
crate::widgets::vline(ui, 22.0);
|
||||
@@ -501,13 +509,30 @@ fn warp_fields(app: &mut PhotocraftApp, ui: &mut egui::Ui, w: &Warp) {
|
||||
for (k, (name, v)) in fields.iter().enumerate() {
|
||||
lbl(ui, name);
|
||||
let mut f = *v as f32;
|
||||
if crate::widgets::value_field(ui, &mut f, -100.0..=100.0, "%", 58.0).accessible_name(*name).changed()
|
||||
let shown = ((f64::from(f) * 10.0).round() / 10.0) as f32;
|
||||
let r = crate::widgets::value_field_fixed(ui, &mut f, -100.0..=100.0, "%", 62.0, 1).accessible_name(*name);
|
||||
// The fields take one decimal: a typed 12.345 is stored as the 12.3 they show once the
|
||||
// field is left (rounding each keystroke would rewrite the text being typed). Only an
|
||||
// edit rounds: tabbing through keeps a value from a file (33.333) as it is, though the
|
||||
// field applies its shown text (33.3) as it loses the focus. Arithmetic (`10+2`) only
|
||||
// applies then, so a value other than the shown one is an edit too.
|
||||
let edited_id = r.id.with("warp-edited");
|
||||
let edited = ui.data(|d| d.get_temp::<bool>(edited_id)).unwrap_or(false);
|
||||
let left = !r.has_focus();
|
||||
if left {
|
||||
ui.data_mut(|d| d.remove_temp::<bool>(edited_id));
|
||||
} else if r.changed() {
|
||||
ui.data_mut(|d| d.insert_temp(edited_id, true));
|
||||
}
|
||||
let edited = edited || (r.changed() && f != shown);
|
||||
if ((r.changed() && !r.lost_focus()) || (r.lost_focus() && edited))
|
||||
&& let Some(Some(cur)) = app.ui.transform.as_mut().map(|t| t.warp.as_mut())
|
||||
{
|
||||
let f = if left { (f64::from(f) * 10.0).round() / 10.0 } else { f64::from(f) };
|
||||
match k {
|
||||
0 => cur.bend = f64::from(f),
|
||||
1 => cur.h_distort = f64::from(f),
|
||||
_ => cur.v_distort = f64::from(f),
|
||||
0 => cur.bend = f,
|
||||
1 => cur.h_distort = f,
|
||||
_ => cur.v_distort = f,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -645,26 +670,22 @@ fn split_icon(ui: &mut egui::Ui, kind: &str, tip: &str, on: bool) -> egui::Respo
|
||||
/// `mode_switch`: the Free Transform / Warp switch (not for Content-Aware Scale, which only scales).
|
||||
fn transform_actions(app: &mut PhotocraftApp, ui: &mut egui::Ui, warping: bool, mode_switch: bool) {
|
||||
ui.add_space(8.0);
|
||||
let commit_tip = if warping {
|
||||
crate::i18n::fmt(tl!("Commit warp ({key})"), &[("key", &crate::shortcuts::pretty("Enter"))])
|
||||
} else {
|
||||
crate::i18n::fmt(tl!("Commit transform ({key})"), &[("key", &crate::shortcuts::pretty("Enter"))])
|
||||
};
|
||||
// Warp and Free Transform share these tooltips, as in the reference (#12503).
|
||||
let commit_tip = crate::i18n::fmt(tl!("Commit transform ({key})"), &[("key", &crate::shortcuts::pretty("Enter"))]);
|
||||
let commit_btn = crate::icons::button(ui, "check", 26.0, false, &commit_tip);
|
||||
let label = "Commit transform";
|
||||
commit_btn.widget_info(|| egui::WidgetInfo::labeled(egui::Role::Button, true, tl!(label)));
|
||||
if commit_btn.clicked() {
|
||||
commit(app);
|
||||
}
|
||||
let cancel_tip = if warping { tl!("Cancel warp (Esc)") } else { tl!("Cancel transform (Esc)") };
|
||||
let cancel_btn = crate::icons::button(ui, "ban", 26.0, false, cancel_tip);
|
||||
let cancel_btn = crate::icons::button(ui, "ban", 26.0, false, tl!("Cancel transform (Esc)"));
|
||||
let label = "Cancel transform";
|
||||
cancel_btn.widget_info(|| egui::WidgetInfo::labeled(egui::Role::Button, true, tl!(label)));
|
||||
if cancel_btn.clicked() {
|
||||
cancel(app);
|
||||
}
|
||||
if warping {
|
||||
let reset = crate::icons::button(ui, "undo-2", 26.0, false, tl!("Reset"));
|
||||
let reset = crate::icons::button(ui, "undo-2", 26.0, false, tl!("Reset the warp"));
|
||||
reset.widget_info(|| egui::WidgetInfo::labeled(egui::Role::Button, true, "Reset warp"));
|
||||
if reset.clicked() {
|
||||
reset_warp(app);
|
||||
@@ -707,3 +728,7 @@ pub(super) fn rotate_about_pivot(app: &mut PhotocraftApp, da: f64) {
|
||||
[c[0] + x * cs - y * sn, c[1] + x * sn + y * cs]
|
||||
});
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "warp_options_bar_tests.rs"]
|
||||
mod warp_options_bar_tests;
|
||||
@@ -1,6 +1,6 @@
|
||||
use super::*;
|
||||
|
||||
fn session() -> TransformSession {
|
||||
pub(super) fn session() -> TransformSession {
|
||||
TransformSession {
|
||||
session: 1,
|
||||
layer: 1,
|
||||
@@ -221,7 +221,7 @@ fn warp_bar_buttons_follow_the_fields_on_a_wide_bar() {
|
||||
h.run_steps(4);
|
||||
assert!(h.state().ui.transform.as_ref().unwrap().warp.is_some());
|
||||
let commit = h.get_by_label("Commit transform").rect();
|
||||
assert!(commit.right() < width / 2.0, "commit sits next to the fields, not at the far right: {commit:?}");
|
||||
assert!(commit.right() < width * 0.6, "commit sits next to the fields, not at the far right: {commit:?}");
|
||||
let reset = h.get_by_label("Reset warp").rect();
|
||||
assert!(reset.right() < commit.left() + 1.0, "reset is left of commit");
|
||||
h.get_by_label("Reset warp").click();
|
||||
@@ -325,7 +325,7 @@ fn type_into_bar_field(n: usize, text: &str) -> TransformSession {
|
||||
|
||||
/// The transform bar over the test box, after `setup` (e.g. picking the W/H unit). Tall enough
|
||||
/// for the fields' unit menu to open below the bar unscrolled.
|
||||
fn bar_harness(setup: impl FnOnce(&mut PhotocraftApp)) -> egui_kittest::Harness<'static, PhotocraftApp> {
|
||||
pub(super) fn bar_harness(setup: impl FnOnce(&mut PhotocraftApp)) -> egui_kittest::Harness<'static, PhotocraftApp> {
|
||||
use egui_kittest::Harness;
|
||||
let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default());
|
||||
app.ui.transform = Some(session());
|
||||
@@ -345,7 +345,7 @@ fn bar_harness(setup: impl FnOnce(&mut PhotocraftApp)) -> egui_kittest::Harness<
|
||||
}
|
||||
|
||||
/// [`type_into_bar_field`] after `setup`.
|
||||
fn type_into_bar_field_with(setup: impl FnOnce(&mut PhotocraftApp), n: usize, text: &str) -> TransformSession {
|
||||
pub(super) fn type_into_bar_field_with(setup: impl FnOnce(&mut PhotocraftApp), n: usize, text: &str) -> TransformSession {
|
||||
use egui_kittest::kittest::Queryable;
|
||||
let mut h = bar_harness(setup);
|
||||
h.get_all_by_role(egui::accesskit::Role::SpinButton).nth(n).unwrap().click();
|
||||
|
||||
@@ -0,0 +1,185 @@
|
||||
//! #12503: the Warp options bar keeps Bend, H and V to one decimal, shares Free Transform's
|
||||
//! Commit and Cancel tooltips (Reset reads "Reset the warp"), and starts with Free Transform's
|
||||
//! reference point check box and grid, greyed and inert; the tool preset picker is greyed too.
|
||||
|
||||
use super::super::tests::{bar_harness, session, type_into_bar_field_with};
|
||||
use super::*;
|
||||
use egui_kittest::kittest::{NodeT, Queryable};
|
||||
|
||||
type Harness = egui_kittest::Harness<'static, PhotocraftApp>;
|
||||
|
||||
/// An Arc warp over the test box, so Bend, H and V are live.
|
||||
fn arc(app: &mut PhotocraftApp) {
|
||||
let t = app.ui.transform.as_mut().unwrap();
|
||||
t.warp = Some(Warp { style: WarpStyle::Arc, bend: 50.0, ..Warp::none(t.rect) });
|
||||
}
|
||||
|
||||
fn warp(t: &TransformSession) -> [f64; 3] {
|
||||
let w = t.warp.as_ref().unwrap();
|
||||
[w.bend, w.h_distort, w.v_distort]
|
||||
}
|
||||
|
||||
/// Hovers `label`'s control long enough for its tooltip, and says whether `tip` is shown.
|
||||
fn shows_tip(h: &mut Harness, label: &str, tip: &str) -> bool {
|
||||
h.get_by_label(label).hover();
|
||||
h.run_steps(60);
|
||||
h.query_all_by_label(tip).any(|n| n.accesskit_node().role() == egui::accesskit::Role::Label)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bend_h_and_v_store_the_one_decimal_they_show() {
|
||||
for n in 0..3 {
|
||||
let mut want = [50.0, 0.0, 0.0];
|
||||
want[n] = 12.3;
|
||||
assert_eq!(warp(&type_into_bar_field_with(arc, n, "12.345")), want, "field {n}");
|
||||
}
|
||||
// Past the range, the value is clamped as before.
|
||||
assert_eq!(warp(&type_into_bar_field_with(arc, 1, "-150")), [50.0, -100.0, 0.0]);
|
||||
let h = bar_harness(|app| {
|
||||
arc(app);
|
||||
app.ui.transform.as_mut().unwrap().warp.as_mut().unwrap().h_distort = 12.3;
|
||||
});
|
||||
assert_eq!(shown(&h), ["50.0", "12.3", "0.0"]);
|
||||
// Entering Warp from Free Transform: no bend yet.
|
||||
let mut h = bar_harness(|_| {});
|
||||
// Free Transform's X, Y, W and H keep dropping trailing zeros.
|
||||
assert_eq!(shown(&h)[..4], ["50", "25", "100", "100"]);
|
||||
h.get_by_label("Switch between free transform and warp modes").click();
|
||||
h.run_steps(4);
|
||||
assert_eq!(shown(&h), ["0.0", "0.0", "0.0"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tabbing_through_keeps_a_value_it_did_not_edit() {
|
||||
let mut h = bar_harness(|app| {
|
||||
arc(app);
|
||||
app.ui.transform.as_mut().unwrap().warp.as_mut().unwrap().bend = 33.333;
|
||||
});
|
||||
h.get_all_by_role(egui::accesskit::Role::SpinButton).next().unwrap().click();
|
||||
h.run();
|
||||
h.key_press(egui::Key::Tab);
|
||||
h.run_steps(3);
|
||||
assert_eq!(warp(h.state().ui.transform.as_ref().unwrap()), [33.333, 0.0, 0.0]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_arithmetic_entry_is_stored_as_the_field_is_left() {
|
||||
assert_eq!(warp(&type_into_bar_field_with(arc, 1, "10+2")), [50.0, 12.0, 0.0]);
|
||||
// Appended to the shown 10.0, no keystroke changes the value before the field is left.
|
||||
for leave in [egui::Key::Enter, egui::Key::Tab] {
|
||||
let mut h = bar_harness(|app| {
|
||||
arc(app);
|
||||
app.ui.transform.as_mut().unwrap().warp.as_mut().unwrap().h_distort = 10.0;
|
||||
});
|
||||
h.get_all_by_role(egui::accesskit::Role::SpinButton).nth(1).unwrap().click();
|
||||
h.run();
|
||||
h.key_press(egui::Key::End);
|
||||
h.run();
|
||||
for c in "+2.25".chars() {
|
||||
h.event(egui::Event::Text(c.to_string()));
|
||||
h.run();
|
||||
}
|
||||
h.key_press(leave);
|
||||
h.run_steps(3);
|
||||
assert_eq!(warp(h.state().ui.transform.as_ref().unwrap()), [50.0, 12.3, 0.0], "{leave:?}");
|
||||
}
|
||||
}
|
||||
|
||||
/// The text of every number field in the bar, in order.
|
||||
fn shown(h: &Harness) -> Vec<String> {
|
||||
h.get_all_by_role(egui::accesskit::Role::SpinButton).map(|n| n.accesskit_node().value().unwrap_or_default().to_string()).collect()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn warp_actions_have_the_free_transform_tooltips() {
|
||||
let commit = crate::i18n::fmt("Commit transform ({key})", &[("key", &crate::shortcuts::pretty("Enter"))]);
|
||||
let mut h = bar_harness(arc);
|
||||
assert!(shows_tip(&mut h, "Commit transform", &commit));
|
||||
assert!(shows_tip(&mut h, "Cancel transform", "Cancel transform (Esc)"));
|
||||
assert!(shows_tip(&mut h, "Reset warp", "Reset the warp"));
|
||||
// Free Transform keeps its own, and has no Reset.
|
||||
let mut h = bar_harness(|_| {});
|
||||
assert!(shows_tip(&mut h, "Commit transform", &commit));
|
||||
assert!(shows_tip(&mut h, "Cancel transform", "Cancel transform (Esc)"));
|
||||
assert!(h.query_by_label("Reset warp").is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn warp_bar_starts_with_the_greyed_reference_point_controls() {
|
||||
let mut h = bar_harness(arc);
|
||||
let toggle = h.get_by_label("Toggle reference point");
|
||||
let node = toggle.accesskit_node();
|
||||
assert!(node.is_disabled() && node.toggled() == Some(egui::accesskit::Toggled::True), "greyed and on");
|
||||
let rect = toggle.rect();
|
||||
assert!(rect.right() < h.get_by_label("Split Warp Crosswise").rect().left(), "before Split");
|
||||
// In the slot Free Transform has it in.
|
||||
assert_eq!(rect.left(), bar_harness(|_| {}).get_by_label("Toggle reference point").rect().left());
|
||||
assert!(shows_tip(&mut h, "Toggle reference point", "Toggle reference point"));
|
||||
|
||||
// The grid follows the check box; its top-left dot would move the reference point.
|
||||
let gap = h.ctx.global_style().spacing.item_spacing.x;
|
||||
let grid_top_left = egui::pos2(rect.right() + gap + 16.0 / 6.0, rect.center().y - 16.0 / 3.0);
|
||||
h.event(egui::Event::PointerMoved(grid_top_left));
|
||||
h.run_steps(60);
|
||||
assert!(h.query_all_by_label("Reference point location").any(|n| n.accesskit_node().role() == egui::accesskit::Role::Label), "grid tooltip");
|
||||
|
||||
let state = |h: &Harness| (h.state().ui.tool_options.transform_reference_point, h.state().ui.transform.as_ref().unwrap().pivot);
|
||||
let before = state(&h);
|
||||
h.get_by_label("Toggle reference point").click();
|
||||
h.run_steps(2);
|
||||
click(&mut h, grid_top_left);
|
||||
assert_eq!(state(&h), before, "greyed controls do nothing");
|
||||
|
||||
// The same click in Free Transform, with the reference point shown, moves it to the corner.
|
||||
let mut h = bar_harness(|app| app.ui.tool_options.transform_reference_point = true);
|
||||
click(&mut h, grid_top_left);
|
||||
assert_eq!(state(&h), (true, [0.0, 0.0]));
|
||||
}
|
||||
|
||||
fn click(h: &mut Harness, pos: egui::Pos2) {
|
||||
click_with(h, pos, egui::PointerButton::Primary);
|
||||
}
|
||||
|
||||
fn click_with(h: &mut Harness, pos: egui::Pos2, button: egui::PointerButton) {
|
||||
h.event(egui::Event::PointerMoved(pos));
|
||||
h.run();
|
||||
for pressed in [true, false] {
|
||||
h.event(egui::Event::PointerButton { pos, button, pressed, modifiers: Default::default() });
|
||||
h.run();
|
||||
}
|
||||
h.run_steps(2);
|
||||
}
|
||||
|
||||
/// The whole options bar (tool preset picker included) over the test box, warping or not.
|
||||
fn full_bar(warping: bool) -> Harness {
|
||||
let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default());
|
||||
app.ui.transform = Some(session());
|
||||
if warping {
|
||||
arc(&mut app);
|
||||
}
|
||||
let mut h = egui_kittest::Harness::builder().with_size(vec2(1400.0, 300.0)).build_ui_state(
|
||||
|ui, app: &mut PhotocraftApp| {
|
||||
if ui.ctx().fonts(|f| f.families().contains(&egui::FontFamily::Name("medium".into()))) {
|
||||
crate::panels::options_bar(app, ui);
|
||||
}
|
||||
},
|
||||
app,
|
||||
);
|
||||
PhotocraftApp::setup_context(&h.ctx, crate::theme::ThemeKind::Studio);
|
||||
h.run_steps(6);
|
||||
h
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_tool_preset_picker_is_greyed_only_while_warping() {
|
||||
for warping in [false, true] {
|
||||
let mut h = full_bar(warping);
|
||||
let tool = h.state().ui.tool.label();
|
||||
let picker = h.get_by_label(tool);
|
||||
assert_eq!(picker.accesskit_node().is_disabled(), warping, "warping: {warping}");
|
||||
// Its right-click menu (Reset Tool) opens only when it is live.
|
||||
let at = picker.rect().center();
|
||||
click_with(&mut h, at, egui::PointerButton::Secondary);
|
||||
assert_eq!(h.query_by_label("Reset Tool").is_none(), warping, "warping: {warping}");
|
||||
}
|
||||
}
|
||||
@@ -231,6 +231,9 @@ mod delete_anchor_options_bar_tests;
|
||||
#[cfg(test)]
|
||||
mod pen_enter_deselects_tests;
|
||||
|
||||
#[cfg(test)]
|
||||
mod pen_mode_menu_tests;
|
||||
|
||||
pub(crate) use pen::freeform_locked_shape;
|
||||
|
||||
/// Where a Pen draft goes, captured at its first anchor.
|
||||
|
||||
@@ -67,8 +67,13 @@ pub fn options_bar(app: &mut PhotocraftApp, ui: &mut egui::Ui, tool: Tool) -> bo
|
||||
return true;
|
||||
}
|
||||
if matches!(tool, Tool::Pen | Tool::FreeformPen | Tool::CurvaturePen) {
|
||||
let opts = [("path".to_string(), tl!("Path")), ("shape".to_string(), tl!("Shape"))];
|
||||
crate::widgets::dropdown(ui, "pen-mode", tl!("Mode"), &mut o.vector_mode, &opts, 80.0);
|
||||
// Photoshop's Pen lists Shape, Path and a greyed Pixels (#12906); the other pens keep theirs.
|
||||
let opts = if tool == Tool::Pen {
|
||||
vec![("shape".to_string(), tl!("Shape")), ("path".to_string(), tl!("Path")), ("pixels".to_string(), tl!("Pixels"))]
|
||||
} else {
|
||||
vec![("path".to_string(), tl!("Path")), ("shape".to_string(), tl!("Shape"))]
|
||||
};
|
||||
crate::widgets::dropdown_enabled(ui, "pen-mode", tl!("Mode"), &mut o.vector_mode, &opts, 80.0, |m| m != "pixels");
|
||||
crate::widgets::vline(ui, 22.0);
|
||||
if o.vector_mode == "shape" {
|
||||
crate::widgets::value_field(ui, &mut o.stroke_width, 0.0..=288.0, "px", 58.0).accessible_name(tl!("Stroke:"));
|
||||
|
||||
@@ -0,0 +1,110 @@
|
||||
//! #12906: the Pen's Mode dropdown lists Shape, Path and Pixels, in that order, as in Photoshop.
|
||||
//! Pixels is greyed and can't be picked, by the pointer or the keys; the default stays Path, and
|
||||
//! Reset Tool sets Path again. The Freeform and Curvature Pens keep their Path, Shape list.
|
||||
|
||||
use egui::accesskit::Role;
|
||||
use egui_kittest::Harness;
|
||||
use egui_kittest::kittest::{NodeT, Queryable};
|
||||
use serde_json::json;
|
||||
|
||||
use super::add_anchor_options_bar_tests::harness;
|
||||
use crate::PhotocraftApp;
|
||||
use crate::state::{Tool, ToolOptions};
|
||||
|
||||
/// The options bar's Mode dropdown (the topmost one named Mode).
|
||||
fn combo<'a>(h: &'a Harness<'static, PhotocraftApp>) -> egui_kittest::Node<'a> {
|
||||
let combos = h.query_all_by_role(Role::ComboBox).filter(|n| n.accesskit_node().label().as_deref() == Some("Mode"));
|
||||
combos.min_by(|a, b| a.rect().top().total_cmp(&b.rect().top())).expect("the Mode dropdown")
|
||||
}
|
||||
|
||||
/// Opens the options bar's Mode dropdown.
|
||||
fn open(h: &mut Harness<'static, PhotocraftApp>) {
|
||||
combo(h).click();
|
||||
h.run_steps(3);
|
||||
assert!(crate::widgets::dropdown_list_open(&h.ctx), "the list is open");
|
||||
}
|
||||
|
||||
/// The open list's rows top to bottom (the mode buttons below the dropdown), each with whether
|
||||
/// it is greyed.
|
||||
fn rows(h: &Harness<'static, PhotocraftApp>) -> Vec<(String, bool)> {
|
||||
let combo = combo(h).rect();
|
||||
let mut rows: Vec<_> = h
|
||||
.query_all_by_role(Role::Button)
|
||||
.filter(|n| n.rect().top() >= combo.bottom() && n.accesskit_node().label().is_some_and(|l| ["Shape", "Path", "Pixels"].contains(&l.as_str())))
|
||||
.map(|n| (n.rect().top(), n.accesskit_node().label().unwrap_or_default(), n.accesskit_node().is_disabled()))
|
||||
.collect();
|
||||
rows.sort_by(|a, b| a.0.total_cmp(&b.0));
|
||||
rows.into_iter().map(|(_, label, greyed)| (label, greyed)).collect()
|
||||
}
|
||||
|
||||
/// Clicks the open list's row `label`.
|
||||
fn pick(h: &mut Harness<'static, PhotocraftApp>, label: &str) {
|
||||
let combo = combo(h).rect();
|
||||
let row = h.query_all_by_label(label).find(|n| n.rect().top() >= combo.bottom()).expect("the row");
|
||||
row.click();
|
||||
h.run_steps(3);
|
||||
}
|
||||
|
||||
fn mode(h: &Harness<'static, PhotocraftApp>) -> String {
|
||||
h.state().ui.tool_options.vector_mode.clone()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_pens_list_is_shape_path_and_a_greyed_pixels() {
|
||||
let mut h = harness(Tool::Pen);
|
||||
open(&mut h);
|
||||
let expected = [("Shape".to_string(), false), ("Path".to_string(), false), ("Pixels".to_string(), true)];
|
||||
assert_eq!(rows(&h), expected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_default_mode_is_path_and_reset_tool_sets_it_again() {
|
||||
assert_eq!(ToolOptions::default().vector_mode, "path");
|
||||
let mut h = harness(Tool::Pen);
|
||||
assert_eq!(mode(&h), "path");
|
||||
assert_eq!(combo(&h).value().as_deref(), Some("Path"), "the button shows Path");
|
||||
|
||||
open(&mut h);
|
||||
pick(&mut h, "Shape");
|
||||
assert_eq!(mode(&h), "shape", "Shape can be picked");
|
||||
let ctx = h.ctx.clone();
|
||||
crate::menus::invoke(h.state_mut(), &ctx, "tool.reset", json!({})).unwrap();
|
||||
assert_eq!(mode(&h), "path", "Reset Tool from Shape mode");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn clicking_pixels_leaves_the_mode() {
|
||||
let mut h = harness(Tool::Pen);
|
||||
open(&mut h);
|
||||
pick(&mut h, "Pixels");
|
||||
assert_eq!(mode(&h), "path");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_keys_never_land_on_pixels() {
|
||||
let mut h = harness(Tool::Pen);
|
||||
open(&mut h);
|
||||
// ↓ from Path, the last enabled row, would be Pixels.
|
||||
h.key_press(egui::Key::ArrowDown);
|
||||
h.run_steps(2);
|
||||
assert_eq!(mode(&h), "path", "↓");
|
||||
// The next row starting with P after Path is Pixels.
|
||||
h.key_press(egui::Key::P);
|
||||
h.event(egui::Event::Text("p".into()));
|
||||
h.run_steps(2);
|
||||
assert_eq!(mode(&h), "path", "type-ahead P");
|
||||
// The keys still step between the enabled rows.
|
||||
h.key_press(egui::Key::ArrowUp);
|
||||
h.run_steps(2);
|
||||
assert_eq!(mode(&h), "shape", "↑");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_freeform_and_curvature_pens_keep_path_and_shape() {
|
||||
for tool in [Tool::FreeformPen, Tool::CurvaturePen] {
|
||||
let mut h = harness(tool);
|
||||
open(&mut h);
|
||||
let expected = [("Path".to_string(), false), ("Shape".to_string(), false)];
|
||||
assert_eq!(rows(&h), expected, "{tool:?}");
|
||||
}
|
||||
}
|
||||
@@ -46,7 +46,7 @@ pub use color::{
|
||||
#[cfg(test)]
|
||||
use color::{checker_tile_id, checker_uv};
|
||||
pub use dropdown::{
|
||||
combo_list, dropdown, dropdown_hovered, dropdown_literal, dropdown_wheel_grouped, dropdown_wheel_grouped_enabled, dropdown_wheel_hovered,
|
||||
combo_list, dropdown, dropdown_enabled, dropdown_hovered, dropdown_literal, dropdown_wheel_grouped, dropdown_wheel_grouped_enabled, dropdown_wheel_hovered,
|
||||
dropdown_with_tooltips, menu_scroll, swatch_popup,
|
||||
};
|
||||
pub(crate) use fields::compact_wrapping_value_field;
|
||||
@@ -74,8 +74,8 @@ pub use text_field::{
|
||||
INPUT_EVENT_LIMIT, TEXT_FIELD_H, TEXT_FIELD_LIMIT, cap_text_events, focus_first_field, text_field, text_field_ex, text_field_with_trailing,
|
||||
};
|
||||
pub use units::{
|
||||
FieldUnits, fmt_num, fmt_num_prec, fmt_num2, parse_num, set_field_resolution, unit_decimals, unit_of_key, value_field_extent, value_field_len,
|
||||
value_field_prec, value_field_prec_blank, value_field_units,
|
||||
FieldUnits, fmt_num, fmt_num_prec, fmt_num2, parse_num, set_field_resolution, unit_decimals, unit_of_key, value_field_extent, value_field_fixed,
|
||||
value_field_len, value_field_prec, value_field_prec_blank, value_field_units,
|
||||
};
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
@@ -15,6 +15,28 @@ pub fn dropdown_literal<T: PartialEq + Clone>(ui: &mut Ui, id: &str, name: &str,
|
||||
!chosen.is_empty()
|
||||
}
|
||||
|
||||
/// [`dropdown`] whose open list greys the options `enabled` refuses: drawn disabled and never
|
||||
/// picked, by the pointer or the keys (#12906, the Pen's Pixels mode).
|
||||
pub fn dropdown_enabled<T: PartialEq + Clone>(
|
||||
ui: &mut Ui,
|
||||
id: &str,
|
||||
name: &str,
|
||||
current: &mut T,
|
||||
options: &[(T, &str)],
|
||||
width: f32,
|
||||
enabled: impl Fn(&T) -> bool,
|
||||
) -> bool {
|
||||
let before = current.clone();
|
||||
let (chosen, _) = dropdown_with(ui, id, name, current, options, width, false, true, &|_| false, &enabled);
|
||||
// The arrow keys and type-ahead step onto greyed rows too; landing there keeps the value.
|
||||
if !enabled(current) {
|
||||
*current = before;
|
||||
ui.ctx().request_repaint();
|
||||
return false;
|
||||
}
|
||||
!chosen.is_empty()
|
||||
}
|
||||
|
||||
/// [`dropdown`], also returning the option under the pointer in its open list (live previews).
|
||||
pub fn dropdown_hovered<T: PartialEq + Clone>(ui: &mut Ui, id: &str, name: &str, current: &mut T, options: &[(T, &str)], width: f32) -> (bool, Option<T>) {
|
||||
let (chosen, hovered) = dropdown_with(ui, id, name, current, options, width, false, true, &|_| false, &|_| true);
|
||||
|
||||
@@ -2,7 +2,7 @@ use super::panel::{chevron_icon, surface};
|
||||
use super::scrub::{label_scrub_response, take_label_scrub};
|
||||
use super::slider::slider;
|
||||
use super::text_field::first_field_id;
|
||||
use super::units::{FieldUnits, field_resolution_id, fmt_num, fmt_num_prec, fmt_num2, parse_num_in, plain, unit_of_suffix};
|
||||
use super::units::{FieldUnits, field_resolution_id, fmt_num, fmt_num_fixed, fmt_num_prec, fmt_num2, parse_num_in, plain, unit_of_suffix};
|
||||
use super::{Align2, Color32, Rect, Response, Sense, Stroke, StrokeKind, Tokens, Ui, Vec2, pos2, theme, vec2};
|
||||
|
||||
/// Monospace numeric field with a dimmed unit suffix, Photoshop style. Drag to scrub. Typed
|
||||
@@ -120,6 +120,8 @@ pub(super) struct FieldOpts {
|
||||
/// Show an unset value as an empty field rather than `0` (the Crop tool's free ratio sides,
|
||||
/// #10888). Editing, scrubbing and parsing are unchanged.
|
||||
pub(super) blank_when_zero: bool,
|
||||
/// Keep the trailing zeros of `decimals` (`50.0`), where every other field drops them.
|
||||
pub(super) keep_zeros: bool,
|
||||
}
|
||||
|
||||
/// Arrow-key and drag step for a value field: [`FieldOpts::step_from_decimals`] uses `decimals`;
|
||||
@@ -462,7 +464,7 @@ fn number_edit(
|
||||
units: crate::numeric_expression::Units,
|
||||
opts: FieldOpts,
|
||||
) -> Response {
|
||||
let FieldOpts { decimals, wrap_drag, hold_typed, blank_when_zero, .. } = opts;
|
||||
let FieldOpts { decimals, wrap_drag, hold_typed, blank_when_zero, keep_zeros, .. } = opts;
|
||||
let (id, ctx) = (ui.next_auto_id(), ui.ctx().clone());
|
||||
// Focused before the DragValue is drawn, so it gains focus this frame and selects its text.
|
||||
if ui.data_mut(|d| d.remove_temp::<bool>(first_field_id())).unwrap_or(false) {
|
||||
@@ -482,6 +484,7 @@ fn number_edit(
|
||||
return String::new();
|
||||
}
|
||||
let text = match decimals {
|
||||
Some(d) if keep_zeros => fmt_num_fixed(v, d),
|
||||
Some(d) => fmt_num_prec(v, d),
|
||||
None if fine => fmt_num2(v),
|
||||
None => fmt_num(v),
|
||||
|
||||
@@ -28,6 +28,12 @@ pub fn value_field_prec(ui: &mut Ui, value: &mut f32, range: std::ops::RangeIncl
|
||||
value_field_in(ui, value, range, suffix, width, 0.0, FieldOpts { decimals: Some(decimals), ..Default::default() }, None).0
|
||||
}
|
||||
|
||||
/// A [`value_field_prec`] that keeps its trailing zeros (`50.0`, `0.0`): Warp's Bend, H and V,
|
||||
/// which the reference shows to one decimal (#12503).
|
||||
pub fn value_field_fixed(ui: &mut Ui, value: &mut f32, range: std::ops::RangeInclusive<f32>, suffix: &str, width: f32, decimals: u32) -> Response {
|
||||
value_field_in(ui, value, range, suffix, width, 0.0, FieldOpts { decimals: Some(decimals), keep_zeros: true, ..Default::default() }, None).0
|
||||
}
|
||||
|
||||
/// A [`value_field_prec`] that shows an unset `0` as an empty field (Crop's free ratio sides,
|
||||
/// #10888). Everything else, including scrubbing and typed input, is identical.
|
||||
pub fn value_field_prec_blank(ui: &mut Ui, value: &mut f32, range: std::ops::RangeInclusive<f32>, suffix: &str, width: f32, decimals: u32) -> Response {
|
||||
@@ -121,6 +127,14 @@ pub fn fmt_num_prec(v: f64, decimals: u32) -> String {
|
||||
photocraft_engine::prefs::fmt_decimals(v, decimals as usize)
|
||||
}
|
||||
|
||||
/// [`fmt_num_prec`] keeping its trailing zeros: `50.0` at one place.
|
||||
pub(super) fn fmt_num_fixed(v: f64, decimals: u32) -> String {
|
||||
let s = fmt_num_prec(v, decimals);
|
||||
let shown = s.split_once('.').map_or(0, |(_, frac)| frac.len());
|
||||
let pad = (decimals as usize).saturating_sub(shown);
|
||||
if pad == 0 { s } else { format!("{s}{}{}", if shown == 0 { "." } else { "" }, "0".repeat(pad)) }
|
||||
}
|
||||
|
||||
/// Two-decimal variant of [`fmt_num`] for small ranges: `1.05`, `0.78`, `2`.
|
||||
pub fn fmt_num2(v: f64) -> String {
|
||||
fmt_num_prec(v, 2)
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
| `photocraft-type.jpg` | PhotoCraft UI screenshot (offscreen snapshot) with *Among the Sierra Nevada, California*, Albert Bierstadt, 1868 | Artwork: public domain, [Wikimedia Commons](https://commons.wikimedia.org/wiki/File:Albert_Bierstadt_-_Among_the_Sierra_Nevada,_California_-_Google_Art_Project.jpg). UI: this project. |
|
||||
| `photocraft-export-light.jpg` | PhotoCraft UI screenshot (offscreen snapshot) with *The Kiss*, Gustav Klimt, 1907–1908 | Artwork: public domain, [Wikimedia Commons](https://commons.wikimedia.org/wiki/File:Gustav_Klimt_016.jpg). UI: this project. |
|
||||
|
||||
Screenshots must use famous public-domain artwork (or content made in the app), never personal photos.
|
||||
Screenshots must use famous public-domain artwork (or content made in the app), never personal photos. Only images the README or a doc displays live here (a doc's own before/after comparison included); screenshots that only show a PR's change go in its PR description.
|
||||
|
||||
# Other bundled data
|
||||
|
||||
|
||||
|
Before Width: | Height: | Size: 163 KiB |
|
Before Width: | Height: | Size: 165 KiB |
|
Before Width: | Height: | Size: 164 KiB |
|
Before Width: | Height: | Size: 231 KiB |
|
Before Width: | Height: | Size: 231 KiB |
|
Before Width: | Height: | Size: 393 KiB |
|
Before Width: | Height: | Size: 278 KiB |
|
Before Width: | Height: | Size: 145 KiB |
|
Before Width: | Height: | Size: 90 KiB |