0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-02-13 18:48:37 -05:00

🐛 Change absolute position to elements

This commit is contained in:
alonso.torres 2020-06-04 13:14:12 +02:00
parent 75f8b04fa8
commit e17ab24e66
2 changed files with 12 additions and 40 deletions

View file

@ -60,15 +60,10 @@
(fn [event attr]
(let [cval (-> (dom/get-target event)
(dom/get-value)
(d/parse-integer))
pval (get shape attr)
delta (if (= attr :x)
(gpt/point (math/neg (- pval cval)) 0)
(gpt/point 0 (math/neg (- pval cval))))]
(d/parse-integer 0))]
;; TODO: Change so not apply the modifiers until blur
(st/emit! (udw/set-modifiers #{(:id shape)} {:displacement delta})
(udw/apply-modifiers #{(:id shape)}))))
(when cval
(st/emit! (udw/update-position (:id shape) {attr cval})))))
on-width-change #(on-size-change % :width)
on-height-change #(on-size-change % :height)

View file

@ -23,28 +23,6 @@
;; -- User/drawing coords
(defn user-coords-vector
[shape]
(let [oldselrec (-> shape gsh/shape->path (gsh/center-transform (:transform shape)) gsh/shape->rect-shape)
{sel-x :x sel-y :y :as selrec} #_(:selrect shape) oldselrec
{rec-x :x rec-y :y} (-> shape gsh/shape->rect-shape)
dx (- rec-x sel-x)
dy (- rec-y sel-y)]
(-> (gpt/point dx dy)
(gpt/round 2))))
(defn user->draw
[{:keys [x y width height] :as shape}]
(let [dv (user-coords-vector shape)]
(-> shape
(gsh/move dv))))
(defn draw->user
[{:keys [x y width height] :as shape}]
(let [dv (user-coords-vector shape)]
(-> shape
(gsh/move (gpt/negate dv)))))
(mf/defc measures-menu
[{:keys [shape options] :as props}]
(let [options (or options #{:size :position :rotation :radius})
@ -52,8 +30,7 @@
frame (deref (refs/object-by-id (:frame-id shape)))
old-shape shape
shape (->> shape
(gsh/transform-shape frame)
(draw->user))
(gsh/transform-shape frame))
on-size-change
(fn [event attr]
@ -70,12 +47,12 @@
(fn [event attr]
(let [value (-> (dom/get-target event)
(dom/get-value)
(d/parse-integer 0))
new-shape (-> shape
(assoc attr value)
(gsh/translate-from-frame frame)
(user->draw))]
(st/emit! (udw/update-position (:id shape) (select-keys new-shape [attr])))))
(d/parse-integer 0))]
(when value
(let [from (-> shape :selrect attr)
to (+ value (attr frame))
target (+ (attr shape) (- to from))]
(st/emit! (udw/update-position (:id shape) {attr target}))))))
on-rotation-change
(fn [event]
@ -137,13 +114,13 @@
:type "number"
:no-validate true
:on-change on-pos-x-change
:value (-> shape :x (math/precision 2))}]]
:value (-> shape :selrect :x (math/precision 2))}]]
[:div.input-element.Yaxis
[:input.input-text {:placeholder "y"
:type "number"
:no-validate true
:on-change on-pos-y-change
:value (-> shape :y (math/precision 2))}]]])
:value (-> shape :selrect :y (math/precision 2))}]]])
(when (options :rotation)
[:div.row-flex