From 06cebbc527ea89e356de1e55c40a5eec20b4d03c Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Mon, 18 May 2020 15:32:34 +0200 Subject: [PATCH] :bug: Fixes problem with rotation input --- .../uxbox/main/data/workspace/transforms.cljs | 43 ++++++++++--------- .../workspace/sidebar/options/measures.cljs | 34 +++++++-------- 2 files changed, 38 insertions(+), 39 deletions(-) diff --git a/frontend/src/uxbox/main/data/workspace/transforms.cljs b/frontend/src/uxbox/main/data/workspace/transforms.cljs index beddce0c2..52069905b 100644 --- a/frontend/src/uxbox/main/data/workspace/transforms.cljs +++ b/frontend/src/uxbox/main/data/workspace/transforms.cljs @@ -357,29 +357,32 @@ ;; Set-rotation is custom because applies different modifiers to each shape adjusting their position (defn set-rotation - [delta-rotation shapes center] - (ptk/reify ::set-rotation - dwc/IUpdateGroup - (get-ids [_] (map :id shapes)) + ([delta-rotation shapes] + (set-rotation delta-rotation shapes (-> shapes gsh/selection-rect gsh/center))) - ptk/UpdateEvent - (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)))) + ([delta-rotation shapes center] + (ptk/reify ::set-rotation + dwc/IUpdateGroup + (get-ids [_] (map :id shapes)) - (rotate-around-center [state angle center shapes] - (reduce #(rotate-shape %1 angle %2 center) state shapes))] + ptk/UpdateEvent + (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]) - 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))))))) + (rotate-around-center [state angle center shapes] + (reduce #(rotate-shape %1 angle %2 center) state shapes))] + + (let [objects (get-in state [:workspace-data page-id :objects]) + 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 [ids] 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 b86b8b9d5..159d0b35c 100644 --- a/frontend/src/uxbox/main/ui/workspace/sidebar/options/measures.cljs +++ b/frontend/src/uxbox/main/ui/workspace/sidebar/options/measures.cljs @@ -34,24 +34,27 @@ dx (- rec-x sel-x) dy (- rec-y sel-y)] - (gpt/point dx dy))) + (-> (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)))) + (-> 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))))) + (-> shape + (gsh/move (gpt/negate dv))))) (mf/defc measures-menu [{:keys [shape options] :as props}] (let [options (or options #{:size :position :rotation :radius}) locale (i18n/use-locale) frame (deref (refs/object-by-id (:frame-id shape))) - + old-shape shape shape (->> shape (gsh/transform-shape frame) (draw->user)) @@ -83,7 +86,7 @@ (let [value (-> (dom/get-target event) (dom/get-value) (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)})))) on-radius-change @@ -138,21 +141,13 @@ :type "number" :no-validate true :on-change on-pos-x-change - :value (:x shape) - ;;:value (str (-> (- (x shape) (:x parent)) ; Show to user position relative to frame - ;; (d/coalesce 0) - ;; (math/round))) - }]] + :value (:x shape)}]] [:div.input-element.Yaxis [:input.input-text {:placeholder "y" :type "number" :no-validate true :on-change on-pos-y-change - :value (:y shape) - ;;:value (str (-> (- (y shape) (:y parent)) - ;; (d/coalesce 0) - ;; (math/round))) - }]]]) + :value (:y shape)}]]]) (when (options :rotation) [:div.row-flex @@ -163,7 +158,7 @@ :type "number" :no-validate true :min "0" - :max "360" + :max "359" :on-change on-rotation-change :value (str (-> (:rotation shape) (d/coalesce 0) @@ -171,12 +166,13 @@ [:input.slidebar {:type "range" :min "0" - :max "360" - :step "1" + :max "359" + :step "10" :no-validate true :on-change on-rotation-change :value (str (-> (:rotation shape) - (d/coalesce 0)))}]]) + (d/coalesce 0) + (math/round)))}]]) (when (options :radius) [:div.row-flex