From f0478ffa01655cf12bac960ba730a5b50f83050c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Moya?= Date: Tue, 14 Apr 2020 15:15:30 +0200 Subject: [PATCH] :sparkles: Use relative coords in options panel --- frontend/src/uxbox/main/geom.cljs | 1 + .../workspace/sidebar/options/measures.cljs | 22 +++++++++++++++---- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/frontend/src/uxbox/main/geom.cljs b/frontend/src/uxbox/main/geom.cljs index bda881a26..3246ffb8e 100644 --- a/frontend/src/uxbox/main/geom.cljs +++ b/frontend/src/uxbox/main/geom.cljs @@ -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)) diff --git a/frontend/src/uxbox/main/ui/workspace/sidebar/options/measures.cljs b/frontend/src/uxbox/main/ui/workspace/sidebar/options/measures.cljs index 51f1c67d0..2e084c144 100644 --- a/frontend/src/uxbox/main/ui/workspace/sidebar/options/measures.cljs +++ b/frontend/src/uxbox/main/ui/workspace/sidebar/options/measures.cljs @@ -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)))}]]])