Say which photograph the sliders are pointed at
Selecting a mask layer silently re-points about thirty controls at that layer's chain. Same panel, same order, same sliders, different meaning — and the only thing that said so was a sentence in the panel above, which a photographer reaching for the exposure slider has no reason to read. An exposure change lands on the whole frame when it was meant for a face, or the reverse; both are silent, and both are discovered later. `ui-navigation.md` §1.1 calls it the dangerous one and it is: the others in that document cost time, this one costs work. The remedy is the classic one for a modal fault — make the mode visible — and the application already had the pattern. Crop arms a canvas interaction, draws an overlay, gives the column one job and is left by the control that entered it. Local masking is the same animal built as a peer panel, and that is what created the ambiguity. So `crop-mode` stops being a bare boolean and becomes one value of a three-state mode, which is the point: two modes could both be on before, and now that is not a state the interface can be in rather than one it is tested against. **One strip, not two.** The mode control was going to sit beside the group strip that filters the adjustments, which is two controls above one column answering the same question — what am I working on. They are one control now, `Crop · Local │ All · Light · Colour`, which is the shape Lightroom Mobile's bottom strip has for the same reason. The two halves are different kinds of state and are drawn differently: a mode is a chip that fills with the accent when it is on, a group is a word with a rule under it. That difference is what lets both be read at once, which they routinely are — picking Light while a mask is selected filters *that layer's* chain and does not leave the mode. Dropping the scope on a group press would be the same fault coming back from the other end, and would make Light mean two things depending on where it was pressed. The strip stays pinned above the develop column rather than moving to the top of the canvas as the document proposed. The half that filters the column belongs to the column, and the photograph is the subject. The canvas keeps one button, which now names the mode it leaves rather than saying "Done" — that was unambiguous with one mode and would not be with two — because the column can be closed on a narrow window and no mode may be inescapable. Entering a mode is a side effect, so Rust owns it rather than the strip writing the property: crop drops the zoom, local turns the overlay on, and leaving clears the selection. That last one is the fix. The "Overlay" and "Select" toggles are gone because they armed things that are simply what the mode *is* — a mode that has to be switched on separately is one you can enter and have do nothing. Escape and the Android back gesture join `back_step` as one `LeaveMode` rather than a second exit concept, and the mode is left before the zoom is: it was entered later, and it is the bigger step back. The heading is where the scope goes. Not a caption beside the panel, the heading *of* the panel that changed — `ADJUST` becomes the layer's name, the same string the selected row in the stack shows. That is the difference between describing a hazard and removing it. **Handles on the photograph.** A linear or radial mask could be created and then not moved, so a radial sat at the centre of the frame at its default size for ever. Three faults stood in the way of drawing one. The first is that a gradient did not render at all until the model had run. The rasteriser was built on the way out of `segment` and the array's size was read *off* the segmentation, so a gradient added to an unsegmented photograph produced nothing — silently, in the same way exports and thumbnails once did: the shader still emits the layer's block and the empty placeholder multiplies it by zero. The proxy size is a property of the photograph. Both are derived from it now, and deliberately at the same size rather than by coincidence, because a subject's distance field is sampled against that array. The second is hit-testing. A handle is drawn in output coordinates and stored in source ones, and between them lie the crop, the zoom, the pan, the straightening and the turns. `Framing::source_at` is `wgsl_prologue` evaluated on the CPU, kept in that file beside it so that keeping the two in step is one file's problem — a handle mapped through anything less drifts off the mask the moment the view moves, which is exactly what masks are rasterised in source space to avoid. The third is that a drag is a displacement, not a destination. Each handle answers to the movement of the pointer since the press, applied to where the mask was when the press landed. Snapping the handle to the pointer instead jerks it by up to half a touch target on the first press, and the target is finger-sized because a tablet has no hover to reveal a control and no modifier to qualify it. A ramp gets three handles — centre, width, angle. An ellipse gets three too: centre and one per semi-axis, the major one carrying the direction as well as the length, because where an axis is put says both. It had a fourth, and it is gone: standing off the shape by a fixed distance, the rotation arm began outside the photograph at the size a new radial is created at, so the first thing anyone saw was a control they could not reach without first shrinking the mask. Two faults here were found by looking at the screen rather than at the source, both of the kind that cannot be found any other way. A `1px` rule with a size and no position is *centred* by Slint, so the seam between the photograph and the column was a hairline down the middle of the panel, through the histogram and every slider under it — twice, once in `app.slint` and once in `AdjustPanel`. And handing Slint a fresh model for the handles on every pointer event made the repeater rebuild its items, taking the `TouchArea` holding the gesture with them: the handle jumped once and then went dead under a finger that was still down. `develop.rs` carries the same warning about the parameter rows, where it broke slider drags; the model is rewritten in place now. The tests worth having are the ones about ambiguity and about the map. That the same row reads the frame's value, then the layer's, then the frame's again is §1.1 in one assertion. That dragging a handle onto another gradient's matching handle *produces* that gradient closes the loop between the two directions of the framing map, through a view that is cropped, zoomed, panned, straightened and quarter-turned at once — a one-legged map is invisible when the framing is neutral, because then both legs are the identity. Not done here: the histogram still reports the whole frame while the sliders edit a layer. That disagreement is real and is N3's, which this unblocks. The strip has room for a Brush entry beside Crop and Local when the painted masks land in the core, and it needs nothing here but the canvas interaction. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -41,8 +41,10 @@
|
||||
use std::f32::consts::PI;
|
||||
use std::fmt::Write as _;
|
||||
|
||||
use crate::descriptor::{Attribute, LocalizedKey, OpDescriptor, OpId, ParamDescriptor, ParamId, Presentation, Scale, Unit,
|
||||
WidgetDemand, WidgetKind,};
|
||||
use crate::descriptor::{
|
||||
Attribute, LocalizedKey, OpDescriptor, OpId, ParamDescriptor, ParamId, Presentation, Scale,
|
||||
Unit, WidgetDemand, WidgetKind,
|
||||
};
|
||||
use crate::operation::Affects;
|
||||
|
||||
pub const ID: OpId = OpId("framing");
|
||||
@@ -597,6 +599,105 @@ impl Framing {
|
||||
.normalised()
|
||||
}
|
||||
|
||||
/// TRACES: FR-DEV-3
|
||||
/// Where an output point comes from in the source, both in normalised
|
||||
/// `0..1` coordinates.
|
||||
///
|
||||
/// **This is [`Self::wgsl_prologue`] evaluated on the CPU**, for the one
|
||||
/// caller that cannot run the shader: an interface hit-testing a control
|
||||
/// drawn *on the photograph*. A gradient's handles are stored in source
|
||||
/// coordinates and dragged in output ones, and the two are separated by
|
||||
/// the crop, the zoom, the pan, the straightening and the turns — so a
|
||||
/// handle that mapped through anything less would drift off the mask the
|
||||
/// moment the view moved, which is exactly the fault masks are rasterised
|
||||
/// in source space to avoid.
|
||||
///
|
||||
/// The two must agree step for step. They are kept together in this file,
|
||||
/// and `the_cpu_map_matches_the_prologue_step_for_step` below pins the
|
||||
/// correspondence so a change to one that is not made to the other fails
|
||||
/// rather than showing up as a mask that is subtly wrong only when
|
||||
/// straightened.
|
||||
pub fn source_at(&self, out: (f32, f32), src_w: u32, src_h: u32) -> (f32, f32) {
|
||||
let (ax, fx) = self.aspects(src_w, src_h);
|
||||
let rect = self.visible_rect();
|
||||
|
||||
// Into the crop rect, then into the framed image's own centred space.
|
||||
let uv = (rect.x + out.0 * rect.width, rect.y + out.1 * rect.height);
|
||||
let mut p = ((uv.0 - 0.5) * fx, uv.1 - 0.5);
|
||||
|
||||
if self.angle != 0.0 {
|
||||
let rad = self.angle * PI / 180.0;
|
||||
let (s, c) = (rad.sin(), rad.cos());
|
||||
p = (p.0 * c - p.1 * s, p.0 * s + p.1 * c);
|
||||
}
|
||||
|
||||
let (turns, flip_h, flip_v) = self.effective();
|
||||
p = match turns {
|
||||
1 => (p.1 * ax, -p.0 / fx),
|
||||
2 => (-p.0, -p.1),
|
||||
3 => (-p.1 * ax, p.0 / fx),
|
||||
_ => p,
|
||||
};
|
||||
if flip_h {
|
||||
p.0 = -p.0;
|
||||
}
|
||||
if flip_v {
|
||||
p.1 = -p.1;
|
||||
}
|
||||
|
||||
(p.0 / ax + 0.5, p.1 + 0.5)
|
||||
}
|
||||
|
||||
/// Where a source point lands on the output — [`Self::source_at`] run
|
||||
/// backwards.
|
||||
///
|
||||
/// Outside `0..1` when the point is cropped away or panned off screen,
|
||||
/// which is the honest answer: the caller draws a handle there and clips
|
||||
/// it, rather than being handed a clamped position that claims the mask is
|
||||
/// somewhere it is not.
|
||||
pub fn output_at(&self, src: (f32, f32), src_w: u32, src_h: u32) -> (f32, f32) {
|
||||
let (ax, fx) = self.aspects(src_w, src_h);
|
||||
let mut p = ((src.0 - 0.5) * ax, src.1 - 0.5);
|
||||
|
||||
let (turns, flip_h, flip_v) = self.effective();
|
||||
if flip_v {
|
||||
p.1 = -p.1;
|
||||
}
|
||||
if flip_h {
|
||||
p.0 = -p.0;
|
||||
}
|
||||
p = match turns {
|
||||
1 => (-p.1 * fx, p.0 / ax),
|
||||
2 => (-p.0, -p.1),
|
||||
3 => (p.1 * fx, -p.0 / ax),
|
||||
_ => p,
|
||||
};
|
||||
|
||||
if self.angle != 0.0 {
|
||||
let rad = -self.angle * PI / 180.0;
|
||||
let (s, c) = (rad.sin(), rad.cos());
|
||||
p = (p.0 * c - p.1 * s, p.0 * s + p.1 * c);
|
||||
}
|
||||
|
||||
let uv = (p.0 / fx + 0.5, p.1 + 0.5);
|
||||
let rect = self.visible_rect();
|
||||
(
|
||||
(uv.0 - rect.x) / rect.width.max(1e-6),
|
||||
(uv.1 - rect.y) / rect.height.max(1e-6),
|
||||
)
|
||||
}
|
||||
|
||||
/// The x components of `aspect` and `frame_aspect`, whose y is always 1.
|
||||
///
|
||||
/// The pair the prologue puts in scope, and the distinction that makes a
|
||||
/// quarter turn exact: `aspect` measures the source, `frame_aspect`
|
||||
/// measures the frame the user is looking at, and a turn is where the two
|
||||
/// meet.
|
||||
fn aspects(&self, src_w: u32, src_h: u32) -> (f32, f32) {
|
||||
let ax = src_w.max(1) as f32 / src_h.max(1) as f32;
|
||||
(ax, if self.swaps_axes() { 1.0 / ax } else { ax })
|
||||
}
|
||||
|
||||
/// Uniform values the generated prologue reads.
|
||||
///
|
||||
/// A fixed-size block in a fixed slot, like the camera matrix: the
|
||||
@@ -1591,4 +1692,141 @@ mod tests {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ---- the CPU coordinate map (source_at / output_at) -------------------
|
||||
//
|
||||
// These matter because the map has no other check on it. The shader's
|
||||
// version is verified by the picture looking right; this one is read by
|
||||
// hit-testing, where being wrong means a handle that grabs nothing and
|
||||
// nothing on screen says why.
|
||||
|
||||
/// A 3:2 frame. Square would hide every aspect fault in here.
|
||||
const SRC: (u32, u32) = (600, 400);
|
||||
|
||||
fn close(a: (f32, f32), b: (f32, f32), what: &str) {
|
||||
assert!(
|
||||
(a.0 - b.0).abs() < 1e-4 && (a.1 - b.1).abs() < 1e-4,
|
||||
"{what}: {a:?} != {b:?}"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_unedited_frame_maps_an_output_point_to_itself() {
|
||||
// The neutral prologue is `uv_src = uv`, and a map that quietly
|
||||
// introduced an aspect factor here would put every mask a little off
|
||||
// on every unedited photograph — the case that is never looked at
|
||||
// twice.
|
||||
let f = Framing::new();
|
||||
for out in [(0.0, 0.0), (0.5, 0.5), (0.25, 0.8), (1.0, 1.0)] {
|
||||
close(f.source_at(out, SRC.0, SRC.1), out, "neutral");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_map_round_trips_through_every_transform_at_once() {
|
||||
// Handles are drawn with `output_at` and dragged with `source_at`, so
|
||||
// a discrepancy between them is a handle that jumps away from the
|
||||
// pointer on the first press. Every stage is on, because the faults
|
||||
// that survive are the ones only a composition exposes — an aspect
|
||||
// applied on one leg and not the other cancels under a bare rotation.
|
||||
for turns in 0..4 {
|
||||
let mut f = Framing::new();
|
||||
f.set_crop(CropRect {
|
||||
x: 0.1,
|
||||
y: 0.2,
|
||||
width: 0.6,
|
||||
height: 0.5,
|
||||
});
|
||||
f.set_view(CropRect {
|
||||
x: 0.3,
|
||||
y: 0.25,
|
||||
width: 0.4,
|
||||
height: 0.4,
|
||||
});
|
||||
f.set_param(ANGLE, -7.5);
|
||||
f.rotate_quarters(turns);
|
||||
f.set_param(FLIP_H, 1.0);
|
||||
f.set_param(FLIP_V, 1.0);
|
||||
|
||||
for out in [(0.0, 0.0), (0.5, 0.5), (0.2, 0.9), (0.95, 0.05)] {
|
||||
let src = f.source_at(out, SRC.0, SRC.1);
|
||||
close(f.output_at(src, SRC.0, SRC.1), out, "round trip");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_stored_orientation_is_part_of_the_map() {
|
||||
// The baseline reaches the prologue through `effective`, so it has to
|
||||
// reach this the same way. A portrait frame the camera stored sideways
|
||||
// is the common case, and a map that ignored the tag would place every
|
||||
// handle on a photograph that is not the one on screen.
|
||||
let mut f = Framing::new();
|
||||
f.set_baseline(dr_types::Orientation {
|
||||
quarter_turns: 1,
|
||||
flip_h: false,
|
||||
flip_v: false,
|
||||
});
|
||||
|
||||
// The output's top-left comes from the source's bottom-left under a
|
||||
// clockwise quarter turn.
|
||||
close(f.source_at((0.0, 0.0), SRC.0, SRC.1), (0.0, 1.0), "turned");
|
||||
close(
|
||||
f.output_at((0.0, 1.0), SRC.0, SRC.1),
|
||||
(0.0, 0.0),
|
||||
"turned back",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn zooming_in_narrows_what_an_output_point_reaches() {
|
||||
// The property the handles depend on: the same place on screen is a
|
||||
// *different* source point once the view moves, so a handle drawn from
|
||||
// stored geometry has to be re-placed on every frame of a pan. If this
|
||||
// were independent of the view the handles would sit still while the
|
||||
// photograph slid under them.
|
||||
let mut f = Framing::new();
|
||||
let wide = f.source_at((0.25, 0.25), SRC.0, SRC.1);
|
||||
|
||||
f.set_view(CropRect {
|
||||
x: 0.25,
|
||||
y: 0.25,
|
||||
width: 0.5,
|
||||
height: 0.5,
|
||||
});
|
||||
let close_in = f.source_at((0.25, 0.25), SRC.0, SRC.1);
|
||||
|
||||
assert!(close_in.0 > wide.0 && close_in.1 > wide.1, "{close_in:?}");
|
||||
close(close_in, (0.375, 0.375), "zoomed");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_cpu_map_matches_the_prologue_step_for_step() {
|
||||
// The two are the same function written twice, and nothing but this
|
||||
// stops them drifting apart. It checks the *shape* — that the
|
||||
// permutation the prologue emits for each turn is the one implemented
|
||||
// above — because the alternative is running WGSL in a unit test.
|
||||
let mut f = Framing::new();
|
||||
f.rotate_quarters(1);
|
||||
assert!(
|
||||
f.wgsl_prologue()
|
||||
.contains("p = vec2<f32>(p.y * aspect.x, -p.x / frame_aspect.x);"),
|
||||
"the one-turn permutation moved; `source_at` must move with it"
|
||||
);
|
||||
|
||||
let mut f = Framing::new();
|
||||
f.rotate_quarters(3);
|
||||
assert!(
|
||||
f.wgsl_prologue()
|
||||
.contains("p = vec2<f32>(-p.y * aspect.x, p.x / frame_aspect.x);"),
|
||||
"the three-turn permutation moved; `source_at` must move with it"
|
||||
);
|
||||
|
||||
// And the sampler's last step, which lives in `operation.rs` and is
|
||||
// the half of the map this file does not emit.
|
||||
assert!(
|
||||
crate::operation::sample_source(false).contains("p / aspect + vec2<f32>(0.5)"),
|
||||
"the sampler's return to texture coordinates moved"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -562,7 +562,7 @@ fn encode_output(c: vec3<f32>) -> vec3<f32> {{
|
||||
/// Split out because it is the join between the coordinate stage and the
|
||||
/// colour stage, and because the choice it makes — an exact integer load, or
|
||||
/// a filtered sample — is the one thing the free-angle case changes.
|
||||
fn sample_source(interpolate: bool) -> &'static str {
|
||||
pub(crate) fn sample_source(interpolate: bool) -> &'static str {
|
||||
if interpolate {
|
||||
" // Back to texture coordinates.
|
||||
let uv_src = p / aspect + vec2<f32>(0.5);
|
||||
|
||||
Reference in New Issue
Block a user