0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-02-18 21:06:11 -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] (fn [event attr]
(let [cval (-> (dom/get-target event) (let [cval (-> (dom/get-target event)
(dom/get-value) (dom/get-value)
(d/parse-integer)) (d/parse-integer 0))]
pval (get shape attr)
delta (if (= attr :x)
(gpt/point (math/neg (- pval cval)) 0)
(gpt/point 0 (math/neg (- pval cval))))]
;; TODO: Change so not apply the modifiers until blur ;; TODO: Change so not apply the modifiers until blur
(st/emit! (udw/set-modifiers #{(:id shape)} {:displacement delta}) (when cval
(udw/apply-modifiers #{(:id shape)})))) (st/emit! (udw/update-position (:id shape) {attr cval})))))
on-width-change #(on-size-change % :width) on-width-change #(on-size-change % :width)
on-height-change #(on-size-change % :height) on-height-change #(on-size-change % :height)

View file

@ -23,28 +23,6 @@
;; -- User/drawing coords ;; -- 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 (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})
@ -52,8 +30,7 @@
frame (deref (refs/object-by-id (:frame-id shape))) frame (deref (refs/object-by-id (:frame-id shape)))
old-shape shape old-shape shape
shape (->> shape shape (->> shape
(gsh/transform-shape frame) (gsh/transform-shape frame))
(draw->user))
on-size-change on-size-change
(fn [event attr] (fn [event attr]
@ -70,12 +47,12 @@
(fn [event attr] (fn [event attr]
(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))]
new-shape (-> shape (when value
(assoc attr value) (let [from (-> shape :selrect attr)
(gsh/translate-from-frame frame) to (+ value (attr frame))
(user->draw))] target (+ (attr shape) (- to from))]
(st/emit! (udw/update-position (:id shape) (select-keys new-shape [attr]))))) (st/emit! (udw/update-position (:id shape) {attr target}))))))
on-rotation-change on-rotation-change
(fn [event] (fn [event]
@ -137,13 +114,13 @@
:type "number" :type "number"
:no-validate true :no-validate true
:on-change on-pos-x-change :on-change on-pos-x-change
:value (-> shape :x (math/precision 2))}]] :value (-> shape :selrect :x (math/precision 2))}]]
[: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 (-> shape :y (math/precision 2))}]]]) :value (-> shape :selrect :y (math/precision 2))}]]])
(when (options :rotation) (when (options :rotation)
[:div.row-flex [:div.row-flex