From f9c0482949233f2fbf4e3b65a8bd98c5796659b0 Mon Sep 17 00:00:00 2001 From: Eva Date: Wed, 2 Mar 2022 14:20:57 +0100 Subject: [PATCH] :sparkles: Show actual coordinates while modifying and creating a shape --- .../main/ui/workspace/sidebar/options.cljs | 53 +++++++++++-------- .../sidebar/options/menus/measures.cljs | 13 +++-- .../sidebar/options/shapes/bool.cljs | 3 +- .../sidebar/options/shapes/circle.cljs | 3 +- .../sidebar/options/shapes/frame.cljs | 3 +- .../sidebar/options/shapes/group.cljs | 2 +- .../sidebar/options/shapes/image.cljs | 3 +- .../sidebar/options/shapes/multiple.cljs | 2 +- .../sidebar/options/shapes/path.cljs | 3 +- .../sidebar/options/shapes/rect.cljs | 3 +- .../sidebar/options/shapes/svg_raw.cljs | 3 +- .../sidebar/options/shapes/text.cljs | 3 +- 12 files changed, 59 insertions(+), 35 deletions(-) diff --git a/frontend/src/app/main/ui/workspace/sidebar/options.cljs b/frontend/src/app/main/ui/workspace/sidebar/options.cljs index 6a96678d7..62161131f 100644 --- a/frontend/src/app/main/ui/workspace/sidebar/options.cljs +++ b/frontend/src/app/main/ui/workspace/sidebar/options.cljs @@ -6,6 +6,8 @@ (ns app.main.ui.workspace.sidebar.options (:require + [app.common.data :as d] + [app.common.geom.shapes :as gsh] [app.main.data.workspace :as udw] [app.main.refs :as refs] [app.main.store :as st] @@ -55,28 +57,37 @@ (mf/defc options-content {::mf/wrap [mf/memo]} [{:keys [selected section shapes shapes-with-children page-id file-id]}] - [:div.tool-window - [:div.tool-window-content - [:& tab-container {:on-change-tab #(st/emit! (udw/set-options-mode %)) - :selected section} - [:& tab-element {:id :design - :title (tr "workspace.options.design")} - [:div.element-options - [:& align-options] - [:& bool-options] - (case (count selected) - 0 [:& page/options] - 1 [:& shape-options {:shape (first shapes) - :page-id page-id - :file-id file-id - :shapes-with-children shapes-with-children}] - [:& multiple/options {:shapes-with-children shapes-with-children - :shapes shapes}])]] + (let [drawing (mf/deref refs/workspace-drawing) + base-objects (-> (mf/deref refs/workspace-page-objects)) + modifiers (mf/deref refs/workspace-modifiers) + objects-modified (mf/with-memo [base-objects modifiers] + (gsh/merge-modifiers base-objects modifiers)) + selected-shapes (into [] (keep (d/getf objects-modified)) selected)] + [:div.tool-window + [:div.tool-window-content + [:& tab-container {:on-change-tab #(st/emit! (udw/set-options-mode %)) + :selected section} + [:& tab-element {:id :design + :title (tr "workspace.options.design")} + [:div.element-options + [:& align-options] + [:& bool-options] + (cond + (d/not-empty? drawing) [:& shape-options {:shape (:object drawing) + :page-id page-id + :file-id file-id}] + (= 0 (count selected)) [:& page/options] + (= 1 (count selected)) [:& shape-options {:shape (first selected-shapes) + :page-id page-id + :file-id file-id + :shapes-with-children shapes-with-children}] + :else [:& multiple/options {:shapes-with-children shapes-with-children + :shapes selected-shapes}])]] - [:& tab-element {:id :prototype - :title (tr "workspace.options.prototype")} - [:div.element-options - [:& interactions-menu {:shape (first shapes)}]]]]]]) + [:& tab-element {:id :prototype + :title (tr "workspace.options.prototype")} + [:div.element-options + [:& interactions-menu {:shape (first shapes)}]]]]]])) ;; TODO: this need optimizations, selected-objects and ;; selected-objects-with-children are derefed always but they only diff --git a/frontend/src/app/main/ui/workspace/sidebar/options/menus/measures.cljs b/frontend/src/app/main/ui/workspace/sidebar/options/menus/measures.cljs index 414507beb..a7f40f5fb 100644 --- a/frontend/src/app/main/ui/workspace/sidebar/options/menus/measures.cljs +++ b/frontend/src/app/main/ui/workspace/sidebar/options/menus/measures.cljs @@ -54,14 +54,17 @@ ;; -- User/drawing coords (mf/defc measures-menu - [{:keys [ids ids-with-children values type all-types] :as props}] + [{:keys [ids ids-with-children values type all-types shape] :as props}] + (let [options (if (= type :multiple) (reduce #(union %1 %2) (map #(get type->options %) all-types)) (get type->options type)) ids-with-children (or ids-with-children ids) - old-shapes (deref (refs/objects-by-id ids)) + old-shapes (if (= type :multiple) + (deref (refs/objects-by-id ids)) + [shape]) frames (map #(deref (refs/object-by-id (:frame-id %))) old-shapes) shapes (as-> old-shapes $ @@ -78,6 +81,10 @@ (not= (:width values) :multiple) (assoc :width width) (not= (:height values) :multiple) (assoc :height height))) + values (let [{:keys [rotation]} (-> shapes first)] + (cond-> values + (not= (:rotation values) :multiple) (assoc :rotation rotation))) + proportion-lock (:proportion-lock values) show-presets-dropdown? (mf/use-state false) @@ -134,7 +141,6 @@ (fn [value] (st/emit! (udw/increase-rotation ids value)))) - on-switch-to-radius-1 (mf/use-callback (mf/deps ids) @@ -154,7 +160,6 @@ (mf/use-callback (mf/deps ids) (fn [value] - (prn "entro en on radius 1") (st/emit! (dch/update-shapes ids-with-children #(ctr/set-radius-1 % value))))) on-radius-multi-change diff --git a/frontend/src/app/main/ui/workspace/sidebar/options/shapes/bool.cljs b/frontend/src/app/main/ui/workspace/sidebar/options/shapes/bool.cljs index dc5a8fa8c..23367cdda 100644 --- a/frontend/src/app/main/ui/workspace/sidebar/options/shapes/bool.cljs +++ b/frontend/src/app/main/ui/workspace/sidebar/options/shapes/bool.cljs @@ -26,7 +26,8 @@ [:* [:& measures-menu {:ids ids :type type - :values measure-values}] + :values measure-values + :shape shape}] [:& constraints-menu {:ids ids :values constraint-values}] [:& layer-menu {:ids ids diff --git a/frontend/src/app/main/ui/workspace/sidebar/options/shapes/circle.cljs b/frontend/src/app/main/ui/workspace/sidebar/options/shapes/circle.cljs index 7fad14c2b..5dbeada46 100644 --- a/frontend/src/app/main/ui/workspace/sidebar/options/shapes/circle.cljs +++ b/frontend/src/app/main/ui/workspace/sidebar/options/shapes/circle.cljs @@ -27,7 +27,8 @@ [:* [:& measures-menu {:ids ids :type type - :values measure-values}] + :values measure-values + :shape shape}] [:& constraints-menu {:ids ids :values constraint-values}] [:& layer-menu {:ids ids diff --git a/frontend/src/app/main/ui/workspace/sidebar/options/shapes/frame.cljs b/frontend/src/app/main/ui/workspace/sidebar/options/shapes/frame.cljs index 5cae0756a..18ef3950d 100644 --- a/frontend/src/app/main/ui/workspace/sidebar/options/shapes/frame.cljs +++ b/frontend/src/app/main/ui/workspace/sidebar/options/shapes/frame.cljs @@ -25,7 +25,8 @@ [:* [:& measures-menu {:ids [(:id shape)] :values measure-values - :type type}] + :type type + :shape shape}] [:& layer-menu {:ids ids :type type :values layer-values}] diff --git a/frontend/src/app/main/ui/workspace/sidebar/options/shapes/group.cljs b/frontend/src/app/main/ui/workspace/sidebar/options/shapes/group.cljs index c7778b0b6..1683aa087 100644 --- a/frontend/src/app/main/ui/workspace/sidebar/options/shapes/group.cljs +++ b/frontend/src/app/main/ui/workspace/sidebar/options/shapes/group.cljs @@ -41,7 +41,7 @@ [comp-ids comp-values] [[(:id shape)] (select-keys shape component-attrs)]] [:div.options - [:& measures-menu {:type type :ids measure-ids :values measure-values}] + [:& measures-menu {:type type :ids measure-ids :values measure-values :shape shape}] [:& component-menu {:ids comp-ids :values comp-values}] [:& constraints-menu {:ids constraint-ids :values constraint-values}] [:& layer-menu {:type type :ids layer-ids :values layer-values}] diff --git a/frontend/src/app/main/ui/workspace/sidebar/options/shapes/image.cljs b/frontend/src/app/main/ui/workspace/sidebar/options/shapes/image.cljs index eb91a0fa6..077ecda69 100644 --- a/frontend/src/app/main/ui/workspace/sidebar/options/shapes/image.cljs +++ b/frontend/src/app/main/ui/workspace/sidebar/options/shapes/image.cljs @@ -27,7 +27,8 @@ [:* [:& measures-menu {:ids ids :type type - :values measure-values}] + :values measure-values + :shape shape}] [:& constraints-menu {:ids ids :values constraint-values}] diff --git a/frontend/src/app/main/ui/workspace/sidebar/options/shapes/multiple.cljs b/frontend/src/app/main/ui/workspace/sidebar/options/shapes/multiple.cljs index d28786b6f..69fa38320 100644 --- a/frontend/src/app/main/ui/workspace/sidebar/options/shapes/multiple.cljs +++ b/frontend/src/app/main/ui/workspace/sidebar/options/shapes/multiple.cljs @@ -241,7 +241,7 @@ [:div.options (when-not (empty? measure-ids) - [:& measures-menu {:type type :all-types all-types :ids measure-ids :values measure-values}]) + [:& measures-menu {:type type :all-types all-types :ids measure-ids :values measure-values :shape shapes}]) (when-not (empty? constraint-ids) [:& constraints-menu {:ids constraint-ids :values constraint-values}]) diff --git a/frontend/src/app/main/ui/workspace/sidebar/options/shapes/path.cljs b/frontend/src/app/main/ui/workspace/sidebar/options/shapes/path.cljs index cd911b1b1..be8bb8e1e 100644 --- a/frontend/src/app/main/ui/workspace/sidebar/options/shapes/path.cljs +++ b/frontend/src/app/main/ui/workspace/sidebar/options/shapes/path.cljs @@ -27,7 +27,8 @@ [:* [:& measures-menu {:ids ids :type type - :values measure-values}] + :values measure-values + :shape shape}] [:& constraints-menu {:ids ids :values constraint-values}] [:& layer-menu {:ids ids diff --git a/frontend/src/app/main/ui/workspace/sidebar/options/shapes/rect.cljs b/frontend/src/app/main/ui/workspace/sidebar/options/shapes/rect.cljs index ad537732a..825e8e3eb 100644 --- a/frontend/src/app/main/ui/workspace/sidebar/options/shapes/rect.cljs +++ b/frontend/src/app/main/ui/workspace/sidebar/options/shapes/rect.cljs @@ -29,7 +29,8 @@ [:* [:& measures-menu {:ids ids :type type - :values measure-values}] + :values measure-values + :shape shape}] [:& constraints-menu {:ids ids :values constraint-values}] diff --git a/frontend/src/app/main/ui/workspace/sidebar/options/shapes/svg_raw.cljs b/frontend/src/app/main/ui/workspace/sidebar/options/shapes/svg_raw.cljs index ded7837f1..fa209083e 100644 --- a/frontend/src/app/main/ui/workspace/sidebar/options/shapes/svg_raw.cljs +++ b/frontend/src/app/main/ui/workspace/sidebar/options/shapes/svg_raw.cljs @@ -103,7 +103,8 @@ [:* [:& measures-menu {:ids ids :type type - :values measure-values}] + :values measure-values + :shape shape}] [:& constraints-menu {:ids ids :values constraint-values}] diff --git a/frontend/src/app/main/ui/workspace/sidebar/options/shapes/text.cljs b/frontend/src/app/main/ui/workspace/sidebar/options/shapes/text.cljs index 8e7803c1c..93324181a 100644 --- a/frontend/src/app/main/ui/workspace/sidebar/options/shapes/text.cljs +++ b/frontend/src/app/main/ui/workspace/sidebar/options/shapes/text.cljs @@ -62,7 +62,8 @@ [:& measures-menu {:ids ids :type type - :values (select-keys shape measure-attrs)}] + :values (select-keys shape measure-attrs) + :shape shape}] [:& constraints-menu {:ids ids