File tree 8 files changed +41
-25
lines changed
.clj-kondo/metosin/malli-types-cljs
8 files changed +41
-25
lines changed Original file line number Diff line number Diff line change 306
306
:key-code :number ,
307
307
:key :string ,
308
308
:modifiers :set }}],
309
- :ret :any }}}},
309
+ :ret :any }}},
310
+ pointer-delta {:arities {1 {:args [:any ], :ret :any }}}},
310
311
renderer.utils.math {clamp {:arities {3 {:args [:number :number :number ],
311
312
:ret :number }}},
312
313
angle-dx {:arities {2 {:args [:number :number ],
330
331
:ret :any }}},
331
332
focus-bounds {:arities {2 {:args [:any :keyword ],
332
333
:ret :any },
333
- 3 {:args [:any :any :any ],
334
+ 3 {:args [:any
335
+ :keyword
336
+ :seqable ],
334
337
:ret :any }}},
335
338
zoom-in-place {:arities {3 {:args [:any
336
339
:number
Original file line number Diff line number Diff line change 1
1
(ns renderer.app.handlers
2
2
(:require
3
+ [clojure.core.matrix :as mat]
3
4
[malli.experimental :as mx]
4
5
[renderer.app.db :refer [State]]
5
6
[renderer.app.effects :as-alias fx]
34
35
(assoc :tool tool)
35
36
(tool.hierarchy/activate )))
36
37
38
+ (mx/defn pointer-delta
39
+ [db]
40
+ (mat/sub (:adjusted-pointer-pos db) (:adjusted-pointer-offset db)))
41
+
37
42
(mx/defn pointer-handler
38
43
[db, e :- PointerEvent, now :- number?]
39
44
(let [{:keys [pointer-offset tool dom-rect drag primary-tool drag-threshold]} db
Original file line number Diff line number Diff line change 212
212
[(finalize " Scale selection" )]
213
213
(fn [db [_ ratio]]
214
214
(let [pivot-point (-> db h/bounds bounds/center)]
215
- (h/scale db ratio pivot-point true ))))
215
+ (h/scale db ratio pivot-point true true ))))
216
216
217
217
(rf/reg-event-db
218
218
::move-up
Original file line number Diff line number Diff line change 445
445
(update-el db id hierarchy/place pos)))
446
446
447
447
(defn scale
448
- [db ratio pivot-point recur?]
449
- (reduce
450
- (fn [db el]
451
- (let [pivot-point (->> (element db el) :bounds (take 2 ) (mat/sub pivot-point))]
452
- (update-el db el hierarchy/scale ratio pivot-point)))
453
- db
454
- (cond-> (selected-ids db)
455
- recur? (concat (descendant-ids db)))))
448
+ [db ratio pivot-point in-place recursive]
449
+ (let [ids-to-scale (cond-> (selected-ids db) recursive (set/union (descendant-ids db)))]
450
+ (reduce
451
+ (fn [db id]
452
+ (let [pivot-point (->> (element db id) :bounds (take 2 ) (mat/sub pivot-point))
453
+ db (update-el db id hierarchy/scale ratio pivot-point)]
454
+ (if in-place
455
+ (let [pointer-delta (mat/sub (:adjusted-pointer-pos db) (:adjusted-pointer-offset db))
456
+ child-ids (set (children-ids db id))
457
+ child-ids (set/intersection child-ids ids-to-scale)]
458
+ (reduce (partial-right translate pointer-delta) db child-ids))
459
+ db)))
460
+ db
461
+ ids-to-scale)))
456
462
457
463
(defn align
458
464
([db direction]
Original file line number Diff line number Diff line change 73
73
(mat/add [x1 y1]))]
74
74
(assoc-in db [:documents (:active-document db) :pan ] pan)))
75
75
76
+ (def FocusType [:enum :original :fit :fill ])
77
+
76
78
(mx/defn focus-bounds
77
- ([db, focus-type :- [ :enum :original :fit :fill ] ]
79
+ ([db, focus-type :- FocusType ]
78
80
(cond-> db
79
81
(:active-document db)
80
82
(focus-bounds focus-type (or (element.h/bounds db)
81
83
(element/united-bounds (element.h/root-children db))))))
82
- ([{ :keys [active-document dom-rect] :as db} focus-type bounds ]
84
+ ([db, focus-type :- FocusType, bounds :- Bounds ]
83
85
(let [[width height] (utils.bounds/->dimensions bounds)
84
- width-ratio (/ (:width dom-rect) width)
85
- height-ratio (/ (:height dom-rect) height)
86
+ width-ratio (/ (-> db : dom-rect :width ) width)
87
+ height-ratio (/ (-> db : dom-rect :height ) height)
86
88
min-zoom (min width-ratio height-ratio)]
87
89
(-> db
88
- (assoc-in [:documents active-document :zoom ]
90
+ (assoc-in [:documents ( : active-document db) :zoom ]
89
91
(case focus-type
90
92
:original (min (* min-zoom 0.9 ) 1 )
91
93
:fit min-zoom
Original file line number Diff line number Diff line change 4
4
[kdtree :as kdtree]
5
5
[malli.experimental :as mx]
6
6
[re-frame.core :as rf]
7
+ [renderer.app.handlers :as app.h]
7
8
[renderer.element.handlers :as element.h]
8
9
[renderer.snap.db :refer [SnapOption]]
9
10
[renderer.snap.subs :as-alias snap.s]
28
29
29
30
(contains? #{:edit :scale } (:state db))
30
31
[(mat/add [(-> db :clicked-element :x ) (-> db :clicked-element :y )]
31
- (mat/sub (:adjusted-pointer-pos db)
32
- (:adjusted-pointer-offset db)))]
32
+ (app.h/pointer-delta db))]
33
33
34
34
:else
35
35
[(:adjusted-pointer-pos db)]))))
Original file line number Diff line number Diff line change 64
64
(defmethod hierarchy /drag :edit
65
65
[db e]
66
66
(let [clicked-element (:clicked-element db)
67
- pointer-delta (mat/sub (:adjusted-pointer-pos db) (:adjusted-pointer-offset db))
68
67
db (history.h/swap db)
69
68
el-id (:element clicked-element)
70
- delta (cond-> pointer-delta (pointer/ctrl? e) pointer/lock-direction)]
69
+ delta (cond-> ( app.h/ pointer-delta db) (pointer/ctrl? e) pointer/lock-direction)]
71
70
(cond-> db
72
71
el-id
73
72
(-> (element.h/update-el el-id element.hierarchy/edit delta (:id clicked-element))
Original file line number Diff line number Diff line change 210
210
ratio (mapv #(max % 0.01 ) ratio)]
211
211
(-> db
212
212
(assoc :pivot-point pivot-point)
213
- (element.h/scale ratio pivot-point recursive))))
213
+ (element.h/scale ratio pivot-point in-place recursive))))
214
214
215
215
(mx/defn select-element
216
216
[db, multiple :- boolean?]
222
222
223
223
(defmethod hierarchy /drag :select
224
224
[db e]
225
- (let [delta (mat/sub (:adjusted-pointer-pos db) (:adjusted-pointer-offset db))
226
- state (:state db)
225
+ (let [state (:state db)
227
226
ctrl? (pointer/ctrl? e)
228
- delta (cond-> delta (and ctrl? (not= state :scale )) pointer/lock-direction)
229
227
alt-key? (pointer/alt? e)
230
228
ratio-locked? (or (pointer/ctrl? e) (element.h/ratio-locked? db))
231
- db (element.h/clear-ignored db)]
229
+ db (element.h/clear-ignored db)
230
+ delta (cond-> (app.h/pointer-delta db)
231
+ (and ctrl? (not= state :scale ))
232
+ pointer/lock-direction)]
232
233
(case state
233
234
:select
234
235
(-> db
You can’t perform that action at this time.
0 commit comments