0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-02-10 09:08:31 -05:00

Merge pull request #177 from uxbox/246/show-relative-pos-in-options

 Use relative coords in options panel
This commit is contained in:
Andrey Antukh 2020-04-15 09:26:52 +02:00 committed by GitHub
commit 55c85c0d5c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 4 deletions

View file

@ -82,6 +82,7 @@
:frame (absolute-move-rect shape position)
:image (absolute-move-rect shape position)
:rect (absolute-move-rect shape position)
:text (absolute-move-rect shape position)
:group (absolute-move-rect shape position)
:circle (absolute-move-circle shape position)
shape))

View file

@ -12,6 +12,7 @@
[rumext.alpha :as mf]
[uxbox.builtins.icons :as i]
[uxbox.main.store :as st]
[uxbox.main.refs :as refs]
[uxbox.common.data :as d]
[uxbox.util.dom :as dom]
[uxbox.main.data.workspace :as udw]
@ -23,6 +24,17 @@
(let [options (or options #{:size :position :rotation :radius})
locale (i18n/use-locale)
data (deref refs/workspace-data)
parent (get-in data [:objects (:frame-id shape)])
x (cond
(:x shape) :x
(:cx shape) :cx)
y (cond
(:y shape) :y
(:cy shape) :cy)
on-size-change
(fn [event attr]
(let [value (-> (dom/get-target event)
@ -45,8 +57,10 @@
(fn [event attr]
(let [value (-> (dom/get-target event)
(dom/get-value)
(d/parse-integer 0))]
(st/emit! (udw/update-position (:id shape) {attr value}))))
(d/parse-integer 0))
; Convert back to absolute position before update
abs-value (+ value (attr parent))]
(st/emit! (udw/update-position (:id shape) {attr abs-value}))))
on-rotation-change
(fn [event]
@ -133,7 +147,7 @@
:type "number"
:no-validate true
:on-change on-pos-x-change
:value (str (-> (:x shape)
:value (str (-> (- (x shape) (:x parent)) ; Show to user position relative to frame
(d/coalesce 0)
(math/round)))}]]
[:div.input-element.pixels
@ -141,7 +155,7 @@
:type "number"
:no-validate true
:on-change on-pos-y-change
:value (str (-> (:y shape)
:value (str (-> (- (y shape) (:y parent))
(d/coalesce 0)
(math/round)))}]]])