mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
Crop: the overlay shows Always by default, and Fill resets when another open document becomes active
This commit is contained in:
1 parent
d0bff086d6
commit
a0ec548cd7
6 files changed
+158
-5
No files matched your search
@@ -295,6 +295,16 @@ impl PhotocraftApp {
|
||||
// snapshot and advance its revision; a replaced snapshot without a newer revision is a
|
||||
// reopened document, even with the same ID.
|
||||
let document = self.session.active().map(|st| (st.doc.id, st.revision, std::sync::Arc::downgrade(&st.doc)));
|
||||
// Crop's Fill goes back to its default entry when another document that was already open
|
||||
// becomes active (a tab switch, or closing the active one), as in the reference
|
||||
// application. A new or opened document isn't in `view_docs` yet, so it keeps the setting,
|
||||
// as do tool switches, commits and cancels, which leave the active document alone (#10894).
|
||||
if let (Some((id, ..)), Some((old_id, ..))) = (&document, &self.path_document)
|
||||
&& id != old_id
|
||||
&& self.view_docs.contains(id)
|
||||
{
|
||||
self.ui.tool_options.crop_content_aware = false;
|
||||
}
|
||||
let same_document = match (&self.path_document, &document) {
|
||||
(Some((old_id, old_revision, old_source)), Some((id, revision, source))) => old_id == id && (revision > old_revision || old_source.ptr_eq(source)),
|
||||
(None, None) => true,
|
||||
|
||||
@@ -184,7 +184,8 @@ pub struct ToolOptions {
|
||||
#[serde(default = "yes")]
|
||||
pub perspective_crop_grid: bool,
|
||||
/// Crop overlay (#1919): the guide in the crop box, when it shows and its orientation
|
||||
/// (Photoshop's defaults: Rule of Thirds, Auto Show Overlay). See `crop_overlay`.
|
||||
/// (the reference application's defaults: Rule of Thirds, Always Show Overlay, #10894). See
|
||||
/// `crop_overlay`.
|
||||
#[serde(default)]
|
||||
pub crop_overlay: crate::crop_overlay::CropOverlay,
|
||||
#[serde(default)]
|
||||
|
||||
@@ -81,8 +81,10 @@ impl CropOverlay {
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub enum OverlayShow {
|
||||
/// Only while the crop box is being dragged (drawn, moved, resized or turned).
|
||||
#[default]
|
||||
Auto,
|
||||
/// The whole time a crop is pending, as the reference application starts out (its Reset Tool
|
||||
/// brings back Always Show Overlay, #10894).
|
||||
#[default]
|
||||
Always,
|
||||
Never,
|
||||
}
|
||||
@@ -438,7 +440,7 @@ mod tests {
|
||||
#[test]
|
||||
fn cycling_overlays_and_orientations() {
|
||||
let mut o = ToolOptions::default();
|
||||
assert_eq!((o.crop_overlay, o.crop_overlay_show, o.crop_overlay_orientation), (CropOverlay::Thirds, OverlayShow::Auto, 0));
|
||||
assert_eq!((o.crop_overlay, o.crop_overlay_show, o.crop_overlay_orientation), (CropOverlay::Thirds, OverlayShow::Always, 0));
|
||||
let mut seen = vec![o.crop_overlay];
|
||||
for _ in 0..6 {
|
||||
cycle(&mut o);
|
||||
@@ -539,6 +541,8 @@ mod tests {
|
||||
#[test]
|
||||
fn the_overlay_shows_by_mode_and_gesture() {
|
||||
let mut app = crop_app();
|
||||
// Auto is no longer the default (#10894): set it for the Auto half of this test.
|
||||
app.ui.tool_options.crop_overlay_show = OverlayShow::Auto;
|
||||
assert!(current_guides(&app, 300.0, 200.0).is_empty(), "Auto: no guides without a drag");
|
||||
app.crop.drag = Some(crate::crop_ui::CropDrag::Move { start: [0.0, 0.0], rect: [0.0, 0.0, 10.0, 10.0] });
|
||||
assert_eq!(current_guides(&app, 300.0, 200.0).len(), 4, "Auto: the thirds while dragging");
|
||||
@@ -555,7 +559,7 @@ mod tests {
|
||||
#[test]
|
||||
fn old_state_files_get_photoshops_defaults() {
|
||||
let o: ToolOptions = serde_json::from_str(r#"{"crop_ratio": "1:1"}"#).unwrap();
|
||||
assert_eq!((o.crop_overlay, o.crop_overlay_show, o.crop_overlay_orientation), (CropOverlay::Thirds, OverlayShow::Auto, 0));
|
||||
assert_eq!((o.crop_overlay, o.crop_overlay_show, o.crop_overlay_orientation), (CropOverlay::Thirds, OverlayShow::Always, 0));
|
||||
let o: ToolOptions = serde_json::from_str(r#"{"crop_overlay": "goldenSpiral", "crop_overlay_show": "always", "crop_overlay_orientation": 3}"#).unwrap();
|
||||
assert_eq!((o.crop_overlay, o.crop_overlay_show, o.crop_overlay_orientation), (CropOverlay::GoldenSpiral, OverlayShow::Always, 3));
|
||||
}
|
||||
|
||||
@@ -0,0 +1,137 @@
|
||||
//! #10894: two Crop defaults as in the reference application. The overlay shows Always by
|
||||
//! default, and Reset Tool brings back Always and Rule of Thirds. Fill goes back to its default
|
||||
//! entry when another document that was already open becomes active, and keeps Content-Aware
|
||||
//! Fill otherwise.
|
||||
|
||||
use photocraft_ui_egui::control::{ControlRequest, handle};
|
||||
use photocraft_ui_egui::crop_overlay::{CropOverlay, OverlayShow};
|
||||
use photocraft_ui_egui::{PhotocraftApp, Tool};
|
||||
use serde_json::{Value, json};
|
||||
|
||||
fn app() -> PhotocraftApp {
|
||||
let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), Default::default());
|
||||
app.run("file.new", json!({"width": 64, "height": 48})).unwrap();
|
||||
app.sync_views();
|
||||
app
|
||||
}
|
||||
|
||||
/// A control request as the control channel sends it, then the frame's sync.
|
||||
fn control(app: &mut PhotocraftApp, method: &str, params: Value) -> Value {
|
||||
let ctx = egui::Context::default();
|
||||
let (req, rx) = ControlRequest::new(method, params);
|
||||
handle(app, &ctx, &req);
|
||||
app.sync_views();
|
||||
rx.try_recv().unwrap_or(Value::Null)
|
||||
}
|
||||
|
||||
/// Pick a document by its Window menu row, as the tab bar does.
|
||||
fn activate(app: &mut PhotocraftApp, index: usize) {
|
||||
control(app, "ui.menu.invoke", json!({"id": format!("window.document.{index}")}));
|
||||
assert_eq!(app.session.active_index(), Some(index), "document {index} is active");
|
||||
}
|
||||
|
||||
fn content_aware(app: &PhotocraftApp) -> bool {
|
||||
app.ui.tool_options.crop_content_aware
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_overlay_shows_always_by_default_and_reset_tool_brings_it_back() {
|
||||
let mut app = app();
|
||||
let o = &app.ui.tool_options;
|
||||
assert_eq!((o.crop_overlay, o.crop_overlay_show), (CropOverlay::Thirds, OverlayShow::Always), "a fresh Crop tool");
|
||||
|
||||
app.ui.tool = Tool::Crop;
|
||||
app.ui.tool_options.crop_overlay = CropOverlay::Diagonal;
|
||||
app.ui.tool_options.crop_overlay_show = OverlayShow::Auto;
|
||||
control(&mut app, "ui.menu.invoke", json!({"id": "tool.reset"}));
|
||||
let o = &app.ui.tool_options;
|
||||
assert_eq!((o.crop_overlay, o.crop_overlay_show), (CropOverlay::Thirds, OverlayShow::Always), "Reset Tool");
|
||||
|
||||
app.ui.tool_options.crop_overlay_show = OverlayShow::Never;
|
||||
control(&mut app, "ui.menu.invoke", json!({"id": "tool.reset"}));
|
||||
assert_eq!(app.ui.tool_options.crop_overlay_show, OverlayShow::Always, "Reset Tool from Never too");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_show_mode_already_saved_keeps_its_value() {
|
||||
for (saved, want) in [("auto", OverlayShow::Auto), ("never", OverlayShow::Never), ("always", OverlayShow::Always)] {
|
||||
let o: photocraft_ui_egui::state::ToolOptions = serde_json::from_value(json!({"crop_overlay_show": saved})).unwrap();
|
||||
assert_eq!(o.crop_overlay_show, want, "a saved `{saved}` loads as it was saved");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn fill_is_kept_by_tool_switches_and_new_documents() {
|
||||
let mut app = app();
|
||||
app.ui.tool_options.crop_content_aware = true;
|
||||
|
||||
app.ui.tool = Tool::Brush;
|
||||
app.sync_views();
|
||||
app.ui.tool = Tool::Crop;
|
||||
app.sync_views();
|
||||
assert!(content_aware(&app), "switch to another tool and back: kept");
|
||||
|
||||
app.run("file.new", json!({"width": 32, "height": 32})).unwrap();
|
||||
app.sync_views();
|
||||
assert_eq!(app.session.active_index(), Some(1), "the new document is active");
|
||||
assert!(content_aware(&app), "create a new document: kept");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn fill_is_kept_when_a_crop_is_committed_or_cancelled() {
|
||||
let mut app = app();
|
||||
app.ui.tool = Tool::Crop;
|
||||
app.ui.tool_options.crop_content_aware = true;
|
||||
|
||||
photocraft_ui_egui::crop_ui::ensure_frame(&mut app);
|
||||
app.ui.crop_rect = Some([8.0, 8.0, 40.0, 32.0]);
|
||||
photocraft_ui_egui::canvas::commit_crop(&mut app);
|
||||
app.sync_views();
|
||||
let size = app.session.active().unwrap().doc.size;
|
||||
assert_eq!((size.width, size.height), (32, 24), "the crop was committed");
|
||||
assert!(content_aware(&app), "commit a crop: kept");
|
||||
|
||||
photocraft_ui_egui::crop_ui::ensure_frame(&mut app);
|
||||
app.ui.crop_rect = Some([4.0, 4.0, 20.0, 16.0]);
|
||||
photocraft_ui_egui::crop_ui::cancel(&mut app);
|
||||
app.sync_views();
|
||||
assert_eq!(app.session.active().unwrap().doc.size.width, 32, "the cancelled crop changed nothing");
|
||||
assert!(content_aware(&app), "cancel a crop: kept");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn fill_goes_back_to_the_default_entry_when_another_open_document_becomes_active() {
|
||||
let mut app = app();
|
||||
app.run("file.new", json!({"width": 32, "height": 32})).unwrap();
|
||||
app.sync_views();
|
||||
|
||||
// A tab switch to a document that was already open.
|
||||
app.ui.tool_options.crop_content_aware = true;
|
||||
activate(&mut app, 0);
|
||||
assert!(!content_aware(&app), "make another already-open document active: back to the default");
|
||||
|
||||
// Switching back to the first one doesn't bring it back.
|
||||
activate(&mut app, 1);
|
||||
assert!(!content_aware(&app), "switch back to the first document: stays at the default");
|
||||
|
||||
// Closing the active document makes another open one active.
|
||||
app.ui.tool_options.crop_content_aware = true;
|
||||
control(&mut app, "ui.menu.invoke", json!({"id": "file.close"}));
|
||||
assert_eq!(app.session.documents().len(), 1, "one document closed");
|
||||
assert!(!content_aware(&app), "close the active document so another becomes active: back to the default");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn fill_is_kept_while_the_same_document_stays_active() {
|
||||
let mut app = app();
|
||||
app.ui.tool_options.crop_content_aware = true;
|
||||
// Repeated syncs of the same document, as every frame does, leave it alone.
|
||||
for _ in 0..3 {
|
||||
app.sync_views();
|
||||
}
|
||||
assert!(content_aware(&app));
|
||||
// An edit replaces the snapshot without changing the document.
|
||||
app.run("layer.new.layer", json!({})).unwrap();
|
||||
app.sync_views();
|
||||
assert!(content_aware(&app), "an edit in the active document keeps it");
|
||||
}
|
||||
@@ -13,6 +13,7 @@ mod clipboard_svg;
|
||||
mod color_managed_canvas;
|
||||
mod crop_beyond_canvas;
|
||||
mod crop_default_mode;
|
||||
mod crop_defaults;
|
||||
mod crop_popup_keys;
|
||||
mod custom_print_paper;
|
||||
mod display_shadows;
|
||||
|
||||
@@ -59,7 +59,7 @@ The transport is `apps/photocraft/src/control_server.rs`, and the handlers are i
|
||||
- Each painting tool keeps its own brush, as in Photoshop: `tools.setBrush` and `ui.set {brushSize}` change the active tool's brush, and switching tools swaps in that tool's own (size, hardness, mode, opacity, flow, dynamics, smoothing). A tool used for the first time starts from the brush in hand. The colours, the erase flag and the stroke seed stay shared. So `ui.set {tool: "eraser", brushSize: 12}` sets the Eraser's size, and `ui.set {tool: "brush"}` afterwards brings the Brush's own size back.
|
||||
- Brush Pose's `pose.overrideTiltX` and `pose.overrideTiltY` are independent booleans. For example, `engine.execute {"command":"tools.setBrush","params":{"pose":{"enabled":true,"tiltX":45,"overrideTiltX":true,"overrideTiltY":false}}}` fixes X at 45° while Y follows the stylus. Pose tilts are degrees (±90); the Brush Settings panel displays percentages (±100). Old stored `overrideTilt` values migrate to both axes. In command patches, `overrideTilt` sets both axes unless an explicit axis field in the same patch overrides it. `brush.get` includes both axis flags and the legacy combined readback (`overrideTilt` is true only when both flags are true). Axis-only journals omit that derived combined key so replay retains the other axis. Present flag values must be booleans; null and other types return an error.
|
||||
- `ui.set` also accepts the Eyedropper options bar (#1649): `eyedropperSampleSize` (`"point"` or 1, 3, 5, 11, 31, 51, 101: the side of the averaged square, shared by the Eyedropper, a painting tool's Alt-click eyedropper, the Curves/Color Picker eyedroppers and the Info panel), `eyedropperSample` (`current`, `currentAndBelow`, `all`, `allNoAdjustments`, `currentAndBelowNoAdjustments`) and `eyedropperRing` (boolean, Show Sampling Ring). `ui.inspect` reports them under `toolOptions` (`eyedropper_size`, `eyedropper_sample`, `eyedropper_ring`). The engine command `document.sampleColor {x, y, size, sampleLayer}` returns the colour such a sample picks, as four floats 0..1 (not 0..255).
|
||||
- `ui.set` also accepts the Crop tool's overlay menu (#1919): `cropOverlay` (`thirds`, `grid`, `diagonal`, `triangle`, `goldenRatio`, `goldenSpiral`), `cropOverlayShow` (`auto`: only while the crop box is dragged, Photoshop's default; `always`; `never`) and `cropOverlayOrientation` (0..3; Triangle has two orientations and Golden Spiral four, the others ignore it). `ui.inspect` reports them under `toolOptions` (`crop_overlay`, `crop_overlay_show`, `crop_overlay_orientation`). In the app, O cycles the overlay and ⇧O its orientation while the Crop tool shows a box.
|
||||
- `ui.set` also accepts the Crop tool's overlay menu (#1919): `cropOverlay` (`thirds`, `grid`, `diagonal`, `triangle`, `goldenRatio`, `goldenSpiral`), `cropOverlayShow` (`always`: the whole time a crop is pending, the default, as in the reference application; `auto`: only while the crop box is dragged; `never`) and `cropOverlayOrientation` (0..3; Triangle has two orientations and Golden Spiral four, the others ignore it). `ui.inspect` reports them under `toolOptions` (`crop_overlay`, `crop_overlay_show`, `crop_overlay_orientation`). In the app, O cycles the overlay and ⇧O its orientation while the Crop tool shows a box.
|
||||
- `ui.set` also accepts the Pen tools' options bar (#1397): `penMode` (`path` or `shape`) and `penPathOp`, the Path Operations menu (`newLayer`, `combine`, `subtract`, `intersect`, `exclude`): how the next Pen, Freeform Pen or Curvature Pen path joins the selected shape layer (Shape mode; `newLayer` makes a new one) or the targeted vector mask, selected path or Work Path (Path mode, where `newLayer` combines). `ui.inspect` reports them under `toolOptions` (`vector_mode`, `pen_path_op`). Merge Shape Components is the engine command `path.mergeShapeComponents` (work, saved or `layer` path) or `layer.combineShapes.mergeShapeComponents` (shape layers).
|
||||
- `ui.set` also accepts `cropFill` (`background`, Photoshop's Background (Default), or `contentAware`), the Crop tool's Fill dropdown (#3823): with `contentAware`, committing a turned or extending frame passes `contentAware: true` to `image.crop`, which fills the area the image doesn't cover from its surroundings. `ui.inspect` reports it as `toolOptions.crop_content_aware`.
|
||||
Both gradient modes use the current preset, including its opacity stops. Select `Foreground to Transparent` through `gradient.presets.select`, or pass custom `stops` and `transparency: [[0,100],[1,0]]` (location 0..1, opacity 0..100). Use `applyToLayer: false` to edit only the tool preset. Classic gradient drags dispatch `paint.gradient` without overriding them.
|
||||
|
||||
Reference in new issue
Block a user