Give a peg handles on the stage
A peg was reachable and not usable. It is a `:group`, so it draws nothing, and both of the stage's ways in key off a DRAWN op: `pick/choose` hit-tests the ops, so a click never found it, and `handles` hangs its box, corners and turn knob off `pick/bounds-of`, so it got only the pivot cross — which is `pointer-events: none`. So the pivot `gesture/refusal` tells you to make could be made, and then only typed at in the inspector, and reselected only from a timeline row. Every assertion about the maths passed throughout, which is the point: nothing under `domain/` can see this. So the handles fall back to a fixed-size rosette about the peg's own origin — cross to move, knob to turn, four corners to scale. Fixed size, in stage pixels, because there is no drawing for it to be proportional to. The cross gets a transparent `.peg-grab` disc rather than taking the handler itself, since `.pivot` must stay `pointer-events: none` everywhere else: it is a mark on the picture and must not eat a click meant for the shape under it. `test/browser/peg.mjs` asserts the handles as DOM and drags through them with real pointer events, because that is the half a unit test cannot reach: a peg appears with no drift at all, is selected, renders one knob, four corners and no box, and dragging its cross moves its child by exactly the drag. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HkinzDz1VtahZVsujAGRBD
This commit is contained in:
parent
925c12fc77
commit
00b8ed34ee
3 changed files with 231 additions and 8 deletions
|
|
@ -266,10 +266,19 @@
|
|||
made. On a node that draws nothing — a peg — there is no box and the cross
|
||||
marks its own origin, which is what it turns about.
|
||||
|
||||
AN INDICATOR AND NOT A HANDLE. There is nothing to drag it to: no pivot is
|
||||
stored, so moving it could only mean something for the next drag and would be
|
||||
gone by the one after. A pivot that has to persist is a peg, which is a node,
|
||||
and is moved and keyed as any other node is."
|
||||
THE CROSS IS NOT A HANDLE FOR THE PIVOT. There is nothing to drag it to: no
|
||||
pivot is stored, so moving it could only mean something for the next drag and
|
||||
would be gone by the one after. A pivot that has to persist is a peg.
|
||||
|
||||
A PEG GETS A ROSETTE INSTEAD OF A BOX, and it has to get something: it draws
|
||||
nothing, so it has no bounds to hang handles on — and the stage's other way in,
|
||||
dragging what is under the pointer, is `pick/choose` on the DRAWN ops, which
|
||||
never returns a node that draws nothing. Without this a peg could be made and
|
||||
then only be typed at in the inspector, which is not a pivot anybody would use.
|
||||
So the handles fall back to a fixed-size cluster about its own origin: the cross
|
||||
moves it, a knob turns it, four corners scale it. FIXED SIZE, in stage pixels,
|
||||
because there is no drawing to be proportional to — the same reason the ghost's
|
||||
cross is always drawn at a fixed size."
|
||||
[ctx]
|
||||
(let [{:keys [world bounds]} @(rf/subscribe [::sub/selected-placement])
|
||||
[_ _ _ path] @(rf/subscribe [::sub/selection])
|
||||
|
|
@ -287,7 +296,7 @@
|
|||
(begin! ctx kind path (xy svg event (:w ctx) (:h ctx))))))]
|
||||
(when world
|
||||
[:g.handles
|
||||
(when-let [[x0 y0 x1 y1] bounds]
|
||||
(if-let [[x0 y0 x1 y1] bounds]
|
||||
(let [corners (partition 2 (through world [x0 y0 x1 y0 x1 y1 x0 y1]))
|
||||
[cx cy tx ty] (through world [(/ (+ x0 x1) 2) (/ (+ y0 y1) 2) (/ (+ x0 x1) 2) y0])
|
||||
len (max 1e-6 (js/Math.hypot (- tx cx) (- ty cy)))
|
||||
|
|
@ -300,9 +309,25 @@
|
|||
(for [[i [x y]] (map-indexed vector corners)]
|
||||
^{:key i}
|
||||
[:rect.corner {:x (- x 1.8) :y (- y 1.8) :width 3.6 :height 3.6
|
||||
:on-pointer-down (grab :scale)}]))]))
|
||||
[:path.pivot {:d (str "M " (- px 3) " " py " H " (+ px 3)
|
||||
" M " px " " (- py 3) " V " (+ py 3))}]])))
|
||||
:on-pointer-down (grab :scale)}]))])
|
||||
;; A peg. Same three gestures, hung on nothing.
|
||||
(let [r 7]
|
||||
[:<>
|
||||
[:line.knob-arm {:x1 px :y1 (- py r) :x2 px :y2 (- py r 8)}]
|
||||
[:circle.knob {:cx px :cy (- py r 8) :r 2.2 :on-pointer-down (grab :turn)}]
|
||||
(doall
|
||||
(for [[i [x y]] (map-indexed vector [[(- px r) (- py r)] [(+ px r) (- py r)]
|
||||
[(+ px r) (+ py r)] [(- px r) (+ py r)]])]
|
||||
^{:key i}
|
||||
[:rect.corner {:x (- x 1.8) :y (- y 1.8) :width 3.6 :height 3.6
|
||||
:on-pointer-down (grab :scale)}]))
|
||||
;; What moves a peg. A transparent disc rather than the cross itself,
|
||||
;; because `.pivot` is `pointer-events: none` — it is a mark on the
|
||||
;; picture in every other case and must not eat a click meant for the
|
||||
;; shape under it.
|
||||
[:circle.peg-grab {:cx px :cy py :r r :on-pointer-down (grab :move)}]]))
|
||||
[:path.pivot {:d (str "M " (- px 4) " " py " H " (+ px 4)
|
||||
" M " px " " (- py 4) " V " (+ py 4))}]])))
|
||||
|
||||
(defn- group-handles [ctx placements]
|
||||
(let [boxes (keep stage-bounds placements)]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue