mirror of
https://github.com/penpot/penpot.git
synced 2025-03-16 01:31:22 -05:00
🐛 Fixes problem with rotation input
This commit is contained in:
parent
82baaae593
commit
06cebbc527
2 changed files with 38 additions and 39 deletions
|
@ -357,29 +357,32 @@
|
||||||
|
|
||||||
;; Set-rotation is custom because applies different modifiers to each shape adjusting their position
|
;; Set-rotation is custom because applies different modifiers to each shape adjusting their position
|
||||||
(defn set-rotation
|
(defn set-rotation
|
||||||
[delta-rotation shapes center]
|
([delta-rotation shapes]
|
||||||
(ptk/reify ::set-rotation
|
(set-rotation delta-rotation shapes (-> shapes gsh/selection-rect gsh/center)))
|
||||||
dwc/IUpdateGroup
|
|
||||||
(get-ids [_] (map :id shapes))
|
|
||||||
|
|
||||||
ptk/UpdateEvent
|
([delta-rotation shapes center]
|
||||||
(update [_ state]
|
(ptk/reify ::set-rotation
|
||||||
(let [page-id (:current-page-id state)]
|
dwc/IUpdateGroup
|
||||||
(letfn [(rotate-shape [state angle shape center]
|
(get-ids [_] (map :id shapes))
|
||||||
(let [objects (get-in state [:workspace-data page-id :objects])
|
|
||||||
path [:workspace-data page-id :objects (:id shape) :modifiers]
|
|
||||||
modifiers (rotation-modifiers center shape angle)]
|
|
||||||
(-> state
|
|
||||||
(update-in path merge modifiers))))
|
|
||||||
|
|
||||||
(rotate-around-center [state angle center shapes]
|
ptk/UpdateEvent
|
||||||
(reduce #(rotate-shape %1 angle %2 center) state shapes))]
|
(update [_ state]
|
||||||
|
(let [page-id (:current-page-id state)]
|
||||||
|
(letfn [(rotate-shape [state angle shape center]
|
||||||
|
(let [objects (get-in state [:workspace-data page-id :objects])
|
||||||
|
path [:workspace-data page-id :objects (:id shape) :modifiers]
|
||||||
|
modifiers (rotation-modifiers center shape angle)]
|
||||||
|
(-> state
|
||||||
|
(update-in path merge modifiers))))
|
||||||
|
|
||||||
(let [objects (get-in state [:workspace-data page-id :objects])
|
(rotate-around-center [state angle center shapes]
|
||||||
id->obj #(get objects %)
|
(reduce #(rotate-shape %1 angle %2 center) state shapes))]
|
||||||
get-children (fn [shape] (map id->obj (cp/get-children (:id shape) objects)))
|
|
||||||
shapes (concat shapes (mapcat get-children shapes))]
|
(let [objects (get-in state [:workspace-data page-id :objects])
|
||||||
(rotate-around-center state delta-rotation center shapes)))))))
|
id->obj #(get objects %)
|
||||||
|
get-children (fn [shape] (map id->obj (cp/get-children (:id shape) objects)))
|
||||||
|
shapes (concat shapes (mapcat get-children shapes))]
|
||||||
|
(rotate-around-center state delta-rotation center shapes))))))))
|
||||||
|
|
||||||
(defn apply-modifiers
|
(defn apply-modifiers
|
||||||
[ids]
|
[ids]
|
||||||
|
|
|
@ -34,24 +34,27 @@
|
||||||
|
|
||||||
dx (- rec-x sel-x)
|
dx (- rec-x sel-x)
|
||||||
dy (- rec-y sel-y)]
|
dy (- rec-y sel-y)]
|
||||||
(gpt/point dx dy)))
|
(-> (gpt/point dx dy)
|
||||||
|
(gpt/round 2))))
|
||||||
|
|
||||||
(defn user->draw
|
(defn user->draw
|
||||||
[{:keys [x y width height] :as shape}]
|
[{:keys [x y width height] :as shape}]
|
||||||
(let [dv (user-coords-vector shape)]
|
(let [dv (user-coords-vector shape)]
|
||||||
(-> shape (gsh/move dv))))
|
(-> shape
|
||||||
|
(gsh/move dv))))
|
||||||
|
|
||||||
(defn draw->user
|
(defn draw->user
|
||||||
[{:keys [x y width height] :as shape}]
|
[{:keys [x y width height] :as shape}]
|
||||||
(let [dv (user-coords-vector shape)]
|
(let [dv (user-coords-vector shape)]
|
||||||
(-> shape (gsh/move (gpt/negate dv)))))
|
(-> shape
|
||||||
|
(gsh/move (gpt/negate dv)))))
|
||||||
|
|
||||||
(mf/defc measures-menu
|
(mf/defc measures-menu
|
||||||
[{:keys [shape options] :as props}]
|
[{:keys [shape options] :as props}]
|
||||||
(let [options (or options #{:size :position :rotation :radius})
|
(let [options (or options #{:size :position :rotation :radius})
|
||||||
locale (i18n/use-locale)
|
locale (i18n/use-locale)
|
||||||
frame (deref (refs/object-by-id (:frame-id shape)))
|
frame (deref (refs/object-by-id (:frame-id shape)))
|
||||||
|
old-shape shape
|
||||||
shape (->> shape
|
shape (->> shape
|
||||||
(gsh/transform-shape frame)
|
(gsh/transform-shape frame)
|
||||||
(draw->user))
|
(draw->user))
|
||||||
|
@ -83,7 +86,7 @@
|
||||||
(let [value (-> (dom/get-target event)
|
(let [value (-> (dom/get-target event)
|
||||||
(dom/get-value)
|
(dom/get-value)
|
||||||
(d/parse-integer 0))]
|
(d/parse-integer 0))]
|
||||||
(st/emit! (udw/set-rotation (- value (:rotation shape)) [shape])
|
(st/emit! (udw/set-rotation (- value (:rotation shape)) [old-shape])
|
||||||
(udw/apply-modifiers #{(:id shape)}))))
|
(udw/apply-modifiers #{(:id shape)}))))
|
||||||
|
|
||||||
on-radius-change
|
on-radius-change
|
||||||
|
@ -138,21 +141,13 @@
|
||||||
:type "number"
|
:type "number"
|
||||||
:no-validate true
|
:no-validate true
|
||||||
:on-change on-pos-x-change
|
:on-change on-pos-x-change
|
||||||
:value (:x shape)
|
:value (:x shape)}]]
|
||||||
;;:value (str (-> (- (x shape) (:x parent)) ; Show to user position relative to frame
|
|
||||||
;; (d/coalesce 0)
|
|
||||||
;; (math/round)))
|
|
||||||
}]]
|
|
||||||
[:div.input-element.Yaxis
|
[:div.input-element.Yaxis
|
||||||
[:input.input-text {:placeholder "y"
|
[:input.input-text {:placeholder "y"
|
||||||
:type "number"
|
:type "number"
|
||||||
:no-validate true
|
:no-validate true
|
||||||
:on-change on-pos-y-change
|
:on-change on-pos-y-change
|
||||||
:value (:y shape)
|
:value (:y shape)}]]])
|
||||||
;;:value (str (-> (- (y shape) (:y parent))
|
|
||||||
;; (d/coalesce 0)
|
|
||||||
;; (math/round)))
|
|
||||||
}]]])
|
|
||||||
|
|
||||||
(when (options :rotation)
|
(when (options :rotation)
|
||||||
[:div.row-flex
|
[:div.row-flex
|
||||||
|
@ -163,7 +158,7 @@
|
||||||
:type "number"
|
:type "number"
|
||||||
:no-validate true
|
:no-validate true
|
||||||
:min "0"
|
:min "0"
|
||||||
:max "360"
|
:max "359"
|
||||||
:on-change on-rotation-change
|
:on-change on-rotation-change
|
||||||
:value (str (-> (:rotation shape)
|
:value (str (-> (:rotation shape)
|
||||||
(d/coalesce 0)
|
(d/coalesce 0)
|
||||||
|
@ -171,12 +166,13 @@
|
||||||
[:input.slidebar
|
[:input.slidebar
|
||||||
{:type "range"
|
{:type "range"
|
||||||
:min "0"
|
:min "0"
|
||||||
:max "360"
|
:max "359"
|
||||||
:step "1"
|
:step "10"
|
||||||
:no-validate true
|
:no-validate true
|
||||||
:on-change on-rotation-change
|
:on-change on-rotation-change
|
||||||
:value (str (-> (:rotation shape)
|
:value (str (-> (:rotation shape)
|
||||||
(d/coalesce 0)))}]])
|
(d/coalesce 0)
|
||||||
|
(math/round)))}]])
|
||||||
|
|
||||||
(when (options :radius)
|
(when (options :radius)
|
||||||
[:div.row-flex
|
[:div.row-flex
|
||||||
|
|
Loading…
Add table
Reference in a new issue