Merge branch 'bb-epic-crop-mx5bund6' of github.com:storytold/photocraft into bb-epic-crop-mx5bund6--17661-crop-preview-rows

This commit is contained in:
David Mann committed 2026-12-02 03:24:38 +01:00
commit b9920ee384
5 files changed
+91 -4

No files matched your search

+2
View File
@@ -123,6 +123,8 @@ pub fn handle(app: &mut PhotocraftApp, ctx: &egui::Context, req: &ControlRequest
outcome
}
#[cfg(test)]
mod crop_overlay_orientation_tests;
#[cfg(test)]
mod pointer_color_picker_sample_tests;
#[cfg(test)]
@@ -0,0 +1,83 @@
//! #17672 (EPIC-CROP #10866): the Golden Spiral has eight orientations, as in the reference
//! application. `ui.set cropOverlayOrientation` takes 0 to 7, Shift+O on a pending crop steps
//! through all eight and wraps, saved settings keep them, and the Triangle keeps its two.
use craft::behavior::geometry::crop::CropGuide;
use egui::Modifiers;
use serde_json::json;
use crate::PhotocraftApp;
use crate::canvas::testing::{control, key};
use crate::canvas::{ToolEvent, tool_event};
use crate::state::Tool;
/// A 32 × 32 document with the Crop tool picked (Classic Mode, so the view stays put).
fn crop_app() -> Box<PhotocraftApp> {
let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default());
app.run("file.new", json!({"width": 32, "height": 32})).unwrap();
app.sync_views();
app.ui.tool = Tool::Crop;
app.ui.tool_options.crop.shield.classic_mode = true;
app.ui.extras.snap = false;
app
}
/// Draws a crop frame from (4, 4) to (28, 28): a pending crop, which Shift+O needs.
fn draw_crop(app: &mut PhotocraftApp) {
tool_event(app, ToolEvent::Down { x: 4.0, y: 4.0, pressure: 1.0 }, Modifiers::NONE);
tool_event(app, ToolEvent::Move { x: 16.0, y: 16.0, pressure: 1.0 }, Modifiers::NONE);
tool_event(app, ToolEvent::Move { x: 28.0, y: 28.0, pressure: 1.0 }, Modifiers::NONE);
tool_event(app, ToolEvent::Up { x: 28.0, y: 28.0 }, Modifiers::NONE);
assert!(crate::crop_ui::pending(app), "the drag draws a pending frame");
}
#[test]
fn ui_set_takes_each_golden_spiral_orientation() {
let mut app = crop_app();
for o in 0..8u64 {
let r = control(&mut app, "ui.set", json!({"cropOverlay": "goldenSpiral", "cropOverlayOrientation": o}));
assert_eq!(r["ok"], true, "orientation {o}: {r}");
let seen = control(&mut app, "ui.inspect", json!({}));
assert_eq!(seen["result"]["toolOptions"]["crop"]["guideOrientation"].as_u64(), Some(o));
}
// Past the last orientation is refused and changes nothing.
let r = control(&mut app, "ui.set", json!({"cropOverlayOrientation": 8}));
assert_eq!(r["ok"], false, "{r}");
assert_eq!(app.ui.tool_options.crop.guide_orientation, 7);
}
#[test]
fn shift_o_steps_the_spiral_through_eight_orientations_and_the_triangle_through_two() {
let mut app = crop_app();
draw_crop(&mut app);
app.ui.tool_options.crop.guide = CropGuide::GoldenSpiral;
app.ui.tool_options.crop.guide_orientation = 0;
let mut seen = Vec::new();
for _ in 0..8 {
key(&mut app, egui::Key::O, Modifiers::SHIFT);
seen.push(app.ui.tool_options.crop.guide_orientation);
}
assert_eq!(seen, [1, 2, 3, 4, 5, 6, 7, 0], "Shift+O steps 0 to 7 and wraps");
app.ui.tool_options.crop.guide = CropGuide::Triangle;
let mut seen = Vec::new();
for _ in 0..2 {
key(&mut app, egui::Key::O, Modifiers::SHIFT);
seen.push(app.ui.tool_options.crop.guide_orientation);
}
assert_eq!(seen, [1, 0], "the Triangle keeps its two orientations");
}
#[test]
fn saved_settings_keep_a_spiral_orientation_past_three() {
let restored = |guide: &str, orientation: u8| {
let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default());
app.session.prefs.edit(|p| p.tool_options = json!({"crop": {"guide": guide, "guideOrientation": orientation}}));
crate::tool_memory::restore(&mut app);
(app.ui.tool_options.crop.guide, app.ui.tool_options.crop.guide_orientation)
};
assert_eq!(restored("goldenSpiral", 6), (CropGuide::GoldenSpiral, 6));
assert_eq!(restored("goldenSpiral", 7), (CropGuide::GoldenSpiral, 7));
// An orientation the guide doesn't have starts over.
assert_eq!(restored("triangle", 6), (CropGuide::Triangle, 0));
}
+4 -2
View File
@@ -716,9 +716,11 @@ impl CropSet {
let show = parse_like(&crop.guide_show, v, || "cropOverlayShow must be one of auto, always, never".to_string())?;
writes.push(Box::new(move |app| app.ui.tool_options.crop.guide_show = show));
}
// Up to the Golden Spiral's eight (#17672); a guide with fewer starts over when it shows.
let orientations = CropGuide::ALL.iter().map(|g| g.orientations()).max().unwrap_or(1);
match uint_field(p, "cropOverlayOrientation")? {
Some(o) if o < 4 => writes.push(Box::new(move |app| app.ui.tool_options.crop.guide_orientation = o as u8)),
Some(_) => return Err("cropOverlayOrientation must be 0, 1, 2 or 3".into()),
Some(o) if o < u64::from(orientations) => writes.push(Box::new(move |app| app.ui.tool_options.crop.guide_orientation = o as u8)),
Some(_) => return Err(format!("cropOverlayOrientation must be 0 to {}", orientations - 1)),
None => {}
}
// The Crop tool's Fill (#3823): "background" (Background (default), or Transparent
+1 -1
View File
@@ -735,7 +735,7 @@ fn ui_set_drives_the_crop_overlay_options() {
json!({"cropOverlay": "spiral"}),
json!({"cropOverlay": 1}),
json!({"cropOverlayShow": "sometimes"}),
json!({"cropOverlayOrientation": 4}),
json!({"cropOverlayOrientation": 8}),
json!({"cropOverlayOrientation": -1}),
json!({"cropOverlayOrientation": "1"}),
json!({"cropOverlay": "grid", "cropOverlayShow": "nope"}),
+1 -1
View File
@@ -118,7 +118,7 @@ The transport is the framework's control server (`craft::automation::server` in
- Clone Source X/Y are signed document-pixel offsets, using the existing `source - destination` convention. The panel derives the current preview/stroke pairing without anchoring it on hover. `cloneSource.list` exposes `anchor` (persistent Aligned pairing), `lastAnchor` (most recently used successful pairing), and `offset` (source minus that last reference). Unaligned strokes update the readout while restarting at the sample point each time; failed or canceled strokes do not commit a pairing. To edit the offset shown for a preview, use `cloneSource.set {"offset":[dx,dy],"anchor":[destinationX,destinationY]}`; without an explicit anchor an edit uses the last reported reference, then the existing aligned reference or sample point. Source picking clears both anchors; resetTransform retains them. Null optional coordinates are omitted consistently in mapping and source-document selection. Invalid coordinates, slot indexes, and oversized transformed sampling windows return errors without painting.
- 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, zoom}` returns the colour such a sample picks, as four floats 0..1 (not 0..255). `zoom` is optional: the view zoom in screen pixels per document pixel (1 = 100 %, a positive number). Without it, an N by N Average reads the N × N square centred on the pixel. With it, the sample matches the Eyedropper at that zoom (#11751): above 100 % it is still the centred square, and at 100 % and below an N by N Average covers (N+1) × (N+1) *screen* pixels, so at 100 % 3 by 3 reads 4 × 4 document pixels and at 50 % 8 × 8. The side in document pixels is (N+1) ÷ `zoom` rounded to the nearest whole pixel, at least N+1 and at most 4096 (at 75 % a 3 by 3 Average reads 5 × 5). The box starts ⌈side ÷ 2⌉ − 1 pixels left of and above the sampled pixel, so an odd side is centred on it and an even side has one pixel more after it than before (at 100 % 3 by 3 reads x−1 … x+2). Like every sample, the box is clipped to the canvas, and a point off the canvas reads transparent. Point Sample reads one pixel at every zoom. To get what the Eyedropper picks, pass its `eyedropperSampleSize` as `size`, its `eyedropperSample` as `sampleLayer` and the document's zoom as `zoom`: left out, `size` is Point Sample (1) and `sampleLayer` is `all`.
- `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 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..7; Triangle has two orientations and Golden Spiral eight, 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`, the Fill dropdown's first entry, which reads Background (default), or Transparent (default) with Delete Cropped Pixels off, or `contentAware`), the Crop tool's Fill dropdown (#3823, #10872): 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.