From a2e26210d1550296101a9f34d039ecd4c07d8258 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Mon, 7 Nov 2022 12:25:22 +0100 Subject: [PATCH] :sparkles: Renamed modifiers functions --- .../app/common/geom/shapes/constraints.cljc | 13 +- .../geom/shapes/flex_layout/modifiers.cljc | 16 +- .../src/app/common/geom/shapes/modifiers.cljc | 8 +- .../common/geom/shapes/pixel_precision.cljc | 4 +- .../app/common/geom/shapes/transforms.cljc | 2 +- common/src/app/common/types/modifiers.cljc | 270 +++++++++--------- .../test/common_tests/geom_shapes_test.cljc | 14 +- .../app/main/data/workspace/drawing/box.cljs | 6 +- .../main/data/workspace/drawing/common.cljs | 2 +- .../app/main/data/workspace/modifiers.cljs | 8 +- .../app/main/data/workspace/shape_layout.cljs | 2 +- .../src/app/main/data/workspace/texts.cljs | 8 +- .../app/main/data/workspace/transforms.cljs | 32 +-- frontend/src/app/main/render.cljs | 8 +- .../src/app/main/ui/viewer/interactions.cljs | 2 +- .../shapes/frame/dynamic_modifiers.cljs | 4 +- .../shapes/text/viewport_texts_html.cljs | 2 +- 17 files changed, 201 insertions(+), 200 deletions(-) diff --git a/common/src/app/common/geom/shapes/constraints.cljc b/common/src/app/common/geom/shapes/constraints.cljc index 2be4becad..c90cd179b 100644 --- a/common/src/app/common/geom/shapes/constraints.cljc +++ b/common/src/app/common/geom/shapes/constraints.cljc @@ -152,7 +152,7 @@ end-angl (gpt/angle-with-other end-before end-after) target-end (if (mth/close? end-angl 180) (- (gpt/length end-before)) (gpt/length end-before)) disp-vector-end (gpt/subtract end-after (gpt/scale (gpt/unit end-after) target-end))] - (ctm/move disp-vector-end))) + (ctm/move-modifiers disp-vector-end))) (defmethod constraint-modifier :fixed [_ axis child-points-before parent-points-before child-points-after parent-points-after transformed-parent] @@ -174,9 +174,8 @@ resize-angl (gpt/angle-with-other before-vec after-vec) resize-sign (if (mth/close? resize-angl 180) -1 1) - scale (* resize-sign (/ (gpt/length after-vec) (gpt/length before-vec))) - ] - (ctm/resize (get-scale axis scale) c0 (:transform transformed-parent) (:transform-inverse transformed-parent)))) + scale (* resize-sign (/ (gpt/length after-vec) (gpt/length before-vec)))] + (ctm/resize-modifiers (get-scale axis scale) c0 (:transform transformed-parent) (:transform-inverse transformed-parent)))) (defmethod constraint-modifier :center [_ axis child-points-before parent-points-before child-points-after parent-points-after] @@ -185,7 +184,7 @@ center-angl (gpt/angle-with-other center-before center-after) target-center (if (mth/close? center-angl 180) (- (gpt/length center-before)) (gpt/length center-before)) disp-vector-center (gpt/subtract center-after (gpt/scale (gpt/unit center-after) target-center))] - (ctm/move disp-vector-center))) + (ctm/move-modifiers disp-vector-center))) (defmethod constraint-modifier :default [_ _ _ _ _] []) @@ -242,10 +241,10 @@ (cond-> modifiers (not= :scale constraints-h) - (ctm/set-resize (gpt/point scale-x 1) resize-origin transform transform-inverse) + (ctm/resize (gpt/point scale-x 1) resize-origin transform transform-inverse) (not= :scale constraints-v) - (ctm/set-resize (gpt/point 1 scale-y) resize-origin transform transform-inverse)))) + (ctm/resize (gpt/point 1 scale-y) resize-origin transform transform-inverse)))) (defn calc-child-modifiers [parent child modifiers ignore-constraints transformed-parent] diff --git a/common/src/app/common/geom/shapes/flex_layout/modifiers.cljc b/common/src/app/common/geom/shapes/flex_layout/modifiers.cljc index fc0b60683..2a9a04e09 100644 --- a/common/src/app/common/geom/shapes/flex_layout/modifiers.cljc +++ b/common/src/app/common/geom/shapes/flex_layout/modifiers.cljc @@ -23,11 +23,11 @@ scale-x (/ (:width child-bb-before) (:width child-bb-after)) scale-y (/ (:height child-bb-before) (:height child-bb-after)) - resize-origin (-> transformed-parent :points first) ;; TODO LAYOUT: IS always the origin?n + resize-origin (-> transformed-parent :points first) ;; TODO LAYOUT: IS always the origin resize-vector (gpt/point scale-x scale-y)] (-> modifiers (ctm/select-child-modifiers) - (ctm/set-resize resize-vector resize-origin transform transform-inverse)))) + (ctm/resize resize-vector resize-origin transform transform-inverse)))) (defn calc-fill-width-data "Calculates the size and modifiers for the width of an auto-fill child" @@ -41,7 +41,7 @@ (let [target-width (max (get-in children-data [(:id child) :child-width]) 0.01) fill-scale (/ target-width child-width)] {:width target-width - :modifiers (ctm/resize (gpt/point fill-scale 1) child-origin transform transform-inverse)}) + :modifiers (ctm/resize-modifiers (gpt/point fill-scale 1) child-origin transform transform-inverse)}) (ctl/col? parent) (let [target-width (max (- line-width (ctl/child-width-margin child)) 0.01) @@ -49,7 +49,7 @@ target-width (min max-width target-width) fill-scale (/ target-width child-width)] {:width target-width - :modifiers (ctm/resize (gpt/point fill-scale 1) child-origin transform transform-inverse)}))) + :modifiers (ctm/resize-modifiers (gpt/point fill-scale 1) child-origin transform transform-inverse)}))) (defn calc-fill-height-data "Calculates the size and modifiers for the height of an auto-fill child" @@ -63,7 +63,7 @@ (let [target-height (max (get-in children-data [(:id child) :child-height]) 0.01) fill-scale (/ target-height child-height)] {:height target-height - :modifiers (ctm/resize (gpt/point 1 fill-scale) child-origin transform transform-inverse)}) + :modifiers (ctm/resize-modifiers (gpt/point 1 fill-scale) child-origin transform transform-inverse)}) (ctl/row? parent) (let [target-height (max (- line-height (ctl/child-height-margin child)) 0.01) @@ -71,7 +71,7 @@ target-height (min max-height target-height) fill-scale (/ target-height child-height)] {:height target-height - :modifiers (ctm/resize (gpt/point 1 fill-scale) child-origin transform transform-inverse)}))) + :modifiers (ctm/resize-modifiers (gpt/point 1 fill-scale) child-origin transform transform-inverse)}))) (defn layout-child-modifiers "Calculates the modifiers for the layout" @@ -93,9 +93,9 @@ move-vec (gpt/to-vec child-origin corner-p) modifiers - (-> (ctm/empty-modifiers) + (-> (ctm/empty) (cond-> fill-width (ctm/add-modifiers (:modifiers fill-width))) (cond-> fill-height (ctm/add-modifiers (:modifiers fill-height))) - (ctm/set-move move-vec))] + (ctm/move move-vec))] [modifiers layout-line])) diff --git a/common/src/app/common/geom/shapes/modifiers.cljc b/common/src/app/common/geom/shapes/modifiers.cljc index 3b6a3c61b..2f365a6a2 100644 --- a/common/src/app/common/geom/shapes/modifiers.cljc +++ b/common/src/app/common/geom/shapes/modifiers.cljc @@ -98,7 +98,7 @@ (let [child-modifiers (gct/calc-child-modifiers parent child modifiers ignore-constraints transformed-parent) child-modifiers (cond-> child-modifiers snap-pixel? (gpp/set-pixel-precision child))] (cond-> modif-tree - (not (ctm/empty-modifiers? child-modifiers)) + (not (ctm/empty? child-modifiers)) (update-in [(:id child) :modifiers] ctm/add-modifiers child-modifiers))))] (reduce set-child modif-tree children))) @@ -111,7 +111,7 @@ (ctm/select-child-geometry-modifiers) (gcl/normalize-child-modifiers parent child transformed-parent))] (cond-> modif-tree - (not (ctm/empty-modifiers? child-modifiers)) + (not (ctm/empty? child-modifiers)) (update-in [(:id child) :modifiers] ctm/add-modifiers child-modifiers))))] (let [children (map (d/getf objects) (:shapes transformed-parent))] (reduce process-child modif-tree children)))) @@ -178,14 +178,14 @@ (let [origin (-> parent :points first) scale-width (/ auto-width (-> parent :selrect :width) )] (-> modifiers - (ctm/set-resize-parent (gpt/point scale-width 1) origin (:transform parent) (:transform-inverse parent))))) + (ctm/resize-parent (gpt/point scale-width 1) origin (:transform parent) (:transform-inverse parent))))) (set-parent-auto-height [modifiers parent auto-height] (let [origin (-> parent :points first) scale-height (/ auto-height (-> parent :selrect :height) )] (-> modifiers - (ctm/set-resize-parent (gpt/point 1 scale-height) origin (:transform parent) (:transform-inverse parent)))))] + (ctm/resize-parent (gpt/point 1 scale-height) origin (:transform parent) (:transform-inverse parent)))))] (let [modifiers (get-in modif-tree [(:id parent) :modifiers]) children (->> parent diff --git a/common/src/app/common/geom/shapes/pixel_precision.cljc b/common/src/app/common/geom/shapes/pixel_precision.cljc index 03aa4359a..297abf99a 100644 --- a/common/src/app/common/geom/shapes/pixel_precision.cljc +++ b/common/src/app/common/geom/shapes/pixel_precision.cljc @@ -32,7 +32,7 @@ ratio-height (/ target-height curr-height) scalev (gpt/point ratio-width ratio-height)] (-> modifiers - (ctm/set-resize scalev origin transform transform-inverse)))) + (ctm/resize scalev origin transform transform-inverse)))) (defn position-pixel-precision [modifiers shape] @@ -42,7 +42,7 @@ target-corner (gpt/round corner) deltav (gpt/to-vec corner target-corner)] (-> modifiers - (ctm/set-move deltav)))) + (ctm/move deltav)))) (defn set-pixel-precision "Adjust modifiers so they adjust to the pixel grid" diff --git a/common/src/app/common/geom/shapes/transforms.cljc b/common/src/app/common/geom/shapes/transforms.cljc index bdaa87807..3dcf61c89 100644 --- a/common/src/app/common/geom/shapes/transforms.cljc +++ b/common/src/app/common/geom/shapes/transforms.cljc @@ -403,7 +403,7 @@ ([shape modifiers] (cond-> shape - (and (some? modifiers) (not (ctm/empty-modifiers? modifiers))) + (and (some? modifiers) (not (ctm/empty? modifiers))) (apply-modifiers modifiers)))) (defn transform-bounds diff --git a/common/src/app/common/types/modifiers.cljc b/common/src/app/common/types/modifiers.cljc index 48710b40c..e6c7943d1 100644 --- a/common/src/app/common/types/modifiers.cljc +++ b/common/src/app/common/types/modifiers.cljc @@ -5,6 +5,7 @@ ;; Copyright (c) UXBOX Labs SL (ns app.common.types.modifiers + (:refer-clojure :exclude [empty empty?]) (:require [app.common.data :as d] [app.common.geom.matrix :as gmt] @@ -13,7 +14,9 @@ [app.common.math :as mth] [app.common.pages.helpers :as cph] [app.common.spec :as us] - [app.common.text :as txt])) + [app.common.text :as txt] + #?(:cljs [cljs.core :as c] + :clj [clojure.core :as c]))) ;; --- Modifiers @@ -39,7 +42,7 @@ ;; Public builder API -(defn empty-modifiers [] +(defn empty [] {}) (defn move-vec? [vector] @@ -50,16 +53,16 @@ (or (not (mth/almost-zero? (- (:x vector) 1))) (not (mth/almost-zero? (- (:y vector) 1))))) -(defn set-move-parent +(defn move-parent ([modifiers x y] - (set-move-parent modifiers (gpt/point x y))) + (move-parent modifiers (gpt/point x y))) ([modifiers vector] (cond-> modifiers (move-vec? vector) (update :geometry-parent conjv {:type :move :vector vector})))) -(defn set-resize-parent +(defn resize-parent ([modifiers vector origin] (cond-> modifiers (resize-vec? vector) @@ -75,16 +78,16 @@ :origin origin :transform transform :transform-inverse transform-inverse})))) -(defn set-move +(defn move ([modifiers x y] - (set-move modifiers (gpt/point x y))) + (move modifiers (gpt/point x y))) ([modifiers vector] (cond-> modifiers (move-vec? vector) (update :geometry-child conjv {:type :move :vector vector})))) -(defn set-resize +(defn resize ([modifiers vector origin] (cond-> modifiers (resize-vec? vector) @@ -101,7 +104,7 @@ :transform transform :transform-inverse transform-inverse})))) -(defn set-rotation +(defn rotation [modifiers center angle] (cond-> modifiers (not (mth/close? angle 0)) @@ -111,14 +114,14 @@ :center center :rotation angle})))) -(defn set-remove-children +(defn remove-children [modifiers shapes] (cond-> modifiers (d/not-empty? shapes) (update :structure-parent conjv {:type :remove-children :value shapes}))) -(defn set-add-children +(defn add-children [modifiers shapes index] (cond-> modifiers (d/not-empty? shapes) @@ -126,17 +129,17 @@ :value shapes :index index}))) -(defn set-reflow +(defn reflow [modifiers] (-> modifiers (update :structure-parent conjv {:type :reflow}))) -(defn set-scale-content +(defn scale-content [modifiers value] (-> modifiers (update :structure-child conjv {:type :scale-content :value value}))) -(defn set-change-property +(defn change-property [modifiers property value] (-> modifiers (update :structure-child conjv {:type :change-property @@ -162,94 +165,66 @@ ;; These are convenience methods to create single operation modifiers without the builder -(defn move +(defn move-modifiers ([x y] - (set-move (empty-modifiers) (gpt/point x y))) + (move (empty) (gpt/point x y))) ([vector] - (set-move (empty-modifiers) vector))) + (move (empty) vector))) -(defn move-parent +(defn move-parent-modifiers ([x y] - (set-move-parent (empty-modifiers) (gpt/point x y))) + (move-parent (empty) (gpt/point x y))) ([vector] - (set-move-parent (empty-modifiers) vector))) + (move-parent (empty) vector))) -(defn resize +(defn resize-modifiers ([vector origin] - (set-resize (empty-modifiers) vector origin)) + (resize (empty) vector origin)) ([vector origin transform transform-inverse] - (set-resize (empty-modifiers) vector origin transform transform-inverse))) + (resize (empty) vector origin transform transform-inverse))) -(defn resize-parent +(defn resize-parent-modifiers ([vector origin] - (set-resize-parent (empty-modifiers) vector origin)) + (resize-parent (empty) vector origin)) ([vector origin transform transform-inverse] - (set-resize-parent (empty-modifiers) vector origin transform transform-inverse))) + (resize-parent (empty) vector origin transform transform-inverse))) -(defn rotation +(defn rotation-modifiers [shape center angle] (let [shape-center (gco/center-shape shape) rotation (-> (gmt/matrix) (gmt/rotate angle center) (gmt/rotate (- angle) shape-center))] - (-> (empty-modifiers) - (set-rotation shape-center angle) - (set-move (gpt/transform (gpt/point 0 0) rotation))))) + (-> (empty) + (rotation shape-center angle) + (move (gpt/transform (gpt/point 0 0) rotation))))) -(defn remove-children +(defn remove-children-modifiers [shapes] - (-> (empty-modifiers) - (set-remove-children shapes))) + (-> (empty) + (remove-children shapes))) -(defn add-children +(defn add-children-modifiers [shapes index] - (-> (empty-modifiers) - (set-add-children shapes index))) + (-> (empty) + (add-children shapes index))) -(defn reflow +(defn reflow-modifiers [] - (-> (empty-modifiers) - (set-reflow))) + (-> (empty) + (reflow))) -(defn scale-content +(defn scale-content-modifiers [value] - (-> (empty-modifiers) - (set-scale-content value))) + (-> (empty) + (scale-content value))) -(defn child-modifiers? - [{:keys [geometry-child structure-child]}] - (or (d/not-empty? geometry-child) - (d/not-empty? structure-child))) - -(defn select-child-modifiers - [modifiers] - (select-keys modifiers [:geometry-child :structure-child])) - -(defn select-child-geometry-modifiers - [modifiers] - (select-keys modifiers [:geometry-child])) - -(defn select-parent-modifiers - [modifiers] - (select-keys modifiers [:geometry-parent :structure-parent])) - -(defn select-structure - [modifiers] - (select-keys modifiers [:structure-parent])) - -(defn empty-modifiers? - [modifiers] - (and (empty? (:geometry-child modifiers)) - (empty? (:geometry-parent modifiers)) - (empty? (:structure-parent modifiers)) - (empty? (:structure-child modifiers)))) - -(defn change-dimensions +(defn change-dimensions-modifiers [shape attr value] (us/assert map? shape) (us/assert #{:width :height} attr) @@ -281,7 +256,7 @@ scalev (gpt/divide (gpt/point width height) (gpt/point sr-width sr-height))] - (resize scalev origin shape-transform shape-transform-inv))) + (resize-modifiers scalev origin shape-transform shape-transform-inv))) (defn change-orientation-modifiers [shape orientation] @@ -304,28 +279,56 @@ scalev (gpt/divide (gpt/point new-width new-height) (gpt/point sr-width sr-height))] - (resize scalev origin shape-transform shape-transform-inv))) + (resize-modifiers scalev origin shape-transform shape-transform-inv))) -(defn merge-modifiers - [objects modifiers] +;; Predicates - (let [set-modifier - (fn [objects [id modifiers]] - (-> objects - (d/update-when id merge modifiers)))] - (->> modifiers - (reduce set-modifier objects)))) +(defn empty? + [modifiers] + (and (c/empty? (:geometry-child modifiers)) + (c/empty? (:geometry-parent modifiers)) + (c/empty? (:structure-parent modifiers)) + (c/empty? (:structure-child modifiers)))) + +(defn child-modifiers? + [{:keys [geometry-child structure-child]}] + (or (d/not-empty? geometry-child) + (d/not-empty? structure-child))) (defn only-move? + "Returns true if there are only move operations" [modifier] (or (and (= 1 (-> modifier :geometry-child count)) (= :move (-> modifier :geometry-child first :type))) (and (= 1 (-> modifier :geometry-parent count)) (= :move (-> modifier :geometry-parent first :type))))) -(defn get-frame-add-children - [modif-tree] +(defn has-geometry? + [{:keys [geometry-parent geometry-child]}] + (or (d/not-empty? geometry-parent) + (d/not-empty? geometry-child))) +;; Extract subsets of modifiers + +(defn select-child-modifiers + [modifiers] + (select-keys modifiers [:geometry-child :structure-child])) + +(defn select-child-geometry-modifiers + [modifiers] + (select-keys modifiers [:geometry-child])) + +(defn select-parent-modifiers + [modifiers] + (select-keys modifiers [:geometry-parent :structure-parent])) + +(defn select-structure + [modifiers] + (select-keys modifiers [:structure-parent])) + +(defn added-children-frames + "Returns the frames that have an 'add-children' operation" + [modif-tree] (let [structure-changes (into {} (comp (filter (fn [[_ val]] (-> val :modifiers :structure-parent some?))) @@ -340,7 +343,10 @@ (->> value (map (fn [id] {:frame frame-id :shape id})))))))) structure-changes))) +;; Main transformation functions + (defn modifiers->transform + "Given a set of modifiers returns its transformation matrix" [modifiers] (letfn [(apply-modifier [matrix {:keys [type vector rotation center origin transform transform-inverse] :as modifier}] (case type @@ -360,7 +366,6 @@ matrix) :rotation - ;; TODO LAYOUT: Maybe an issue when no center data (gmt/multiply (-> (gmt/matrix) (gmt/translate center) @@ -373,63 +378,60 @@ (->> modifiers (reduce apply-modifier (gmt/matrix)))))) -(defn scale-text-content - [content value] - - (->> content - (txt/transform-nodes - txt/is-text-node? - (fn [attrs] - (let [font-size (-> (get attrs :font-size 14) - (d/parse-double) - (* value) - (str)) ] - (d/txt-merge attrs {:font-size font-size})))))) - -(defn apply-scale-content - [shape value] - - (cond-> shape - (cph/text-shape? shape) - (update :content scale-text-content value))) - (defn apply-structure-modifiers + "Apply structure changes to a shape" [shape modifiers] - (let [remove-children - (fn [shapes children-to-remove] - (let [remove? (set children-to-remove)] - (d/removev remove? shapes))) + (letfn [(scale-text-content + [content value] - apply-modifier - (fn [shape {:keys [type property value index rotation]}] - (cond-> shape - (= type :rotation) - (update :rotation #(mod (+ % rotation) 360)) + (->> content + (txt/transform-nodes + txt/is-text-node? + (fn [attrs] + (let [font-size (-> (get attrs :font-size 14) + (d/parse-double) + (* value) + (str)) ] + (d/txt-merge attrs {:font-size font-size})))))) - (and (= type :add-children) (some? index)) - (update :shapes - (fn [shapes] - (if (vector? shapes) - (cph/insert-at-index shapes index value) - (d/concat-vec shapes value)))) + (apply-scale-content + [shape value] - (and (= type :add-children) (nil? index)) - (update :shapes d/concat-vec value) + (cond-> shape + (cph/text-shape? shape) + (update :content scale-text-content value)))] + (let [remove-children + (fn [shapes children-to-remove] + (let [remove? (set children-to-remove)] + (d/removev remove? shapes))) - (= type :remove-children) - (update :shapes remove-children value) + apply-modifier + (fn [shape {:keys [type property value index rotation]}] + (cond-> shape + (= type :rotation) + (update :rotation #(mod (+ % rotation) 360)) - (= type :scale-content) - (apply-scale-content value) + (and (= type :add-children) (some? index)) + (update :shapes + (fn [shapes] + (if (vector? shapes) + (cph/insert-at-index shapes index value) + (d/concat-vec shapes value)))) - (= type :change-property) - (assoc property value)))] + (and (= type :add-children) (nil? index)) + (update :shapes d/concat-vec value) + + (= type :remove-children) + (update :shapes remove-children value) + + (= type :scale-content) + (apply-scale-content value) + + (= type :change-property) + (assoc property value)))] + + (as-> shape $ + (reduce apply-modifier $ (:structure-parent modifiers)) + (reduce apply-modifier $ (:structure-child modifiers)))))) - (as-> shape $ - (reduce apply-modifier $ (:structure-parent modifiers)) - (reduce apply-modifier $ (:structure-child modifiers))))) -(defn has-geometry? - [{:keys [geometry-parent geometry-child]}] - (or (d/not-empty? geometry-parent) - (d/not-empty? geometry-child))) diff --git a/common/test/common_tests/geom_shapes_test.cljc b/common/test/common_tests/geom_shapes_test.cljc index eae43ef1b..e974774f8 100644 --- a/common/test/common_tests/geom_shapes_test.cljc +++ b/common/test/common_tests/geom_shapes_test.cljc @@ -60,7 +60,7 @@ (t/testing "Transform shape with translation modifiers" (t/are [type] - (let [modifiers (ctm/move (gpt/point 10 -10))] + (let [modifiers (ctm/move-modifiers (gpt/point 10 -10))] (let [shape-before (create-test-shape type {:modifiers modifiers}) shape-after (gsh/transform-shape shape-before)] (t/is (not= shape-before shape-after)) @@ -92,7 +92,7 @@ (t/testing "Transform shape with resize modifiers" (t/are [type] - (let [modifiers (ctm/resize (gpt/point 2 2) (gpt/point 0 0)) + (let [modifiers (ctm/resize-modifiers (gpt/point 2 2) (gpt/point 0 0)) shape-before (create-test-shape type {:modifiers modifiers}) shape-after (gsh/transform-shape shape-before)] (t/is (not= shape-before shape-after)) @@ -112,7 +112,7 @@ (t/testing "Transform with empty resize" (t/are [type] - (let [modifiers (ctm/resize (gpt/point 1 1) (gpt/point 0 0)) + (let [modifiers (ctm/resize-modifiers (gpt/point 1 1) (gpt/point 0 0)) shape-before (create-test-shape type {:modifiers modifiers}) shape-after (gsh/transform-shape shape-before)] (t/are [prop] @@ -123,7 +123,7 @@ (t/testing "Transform with resize=0" (t/are [type] - (let [modifiers (ctm/resize (gpt/point 0 0) (gpt/point 0 0)) + (let [modifiers (ctm/resize-modifiers (gpt/point 0 0) (gpt/point 0 0)) shape-before (create-test-shape type {:modifiers modifiers}) shape-after (gsh/transform-shape shape-before)] (t/is (> (get-in shape-before [:selrect :width]) @@ -138,7 +138,7 @@ (t/testing "Transform shape with rotation modifiers" (t/are [type] (let [shape-before (create-test-shape type) - modifiers (ctm/rotation shape-before (gsh/center-shape shape-before) 30 ) + modifiers (ctm/rotation-modifiers shape-before (gsh/center-shape shape-before) 30 ) shape-before (assoc shape-before :modifiers modifiers) shape-after (gsh/transform-shape shape-before)] @@ -160,7 +160,7 @@ (t/testing "Transform shape with rotation = 0 should leave equal selrect" (t/are [type] (let [shape-before (create-test-shape type) - modifiers (ctm/rotation shape-before (gsh/center-shape shape-before) 0) + modifiers (ctm/rotation-modifiers shape-before (gsh/center-shape shape-before) 0) shape-after (gsh/transform-shape (assoc shape-before :modifiers modifiers))] (t/are [prop] (t/is (close? (get-in shape-before [:selrect prop]) @@ -170,7 +170,7 @@ (t/testing "Transform shape with invalid selrect fails gracefully" (t/are [type selrect] - (let [modifiers (ctm/move 0 0) + (let [modifiers (ctm/move-modifiers 0 0) shape-before (-> (create-test-shape type {:modifiers modifiers}) (assoc :selrect selrect)) shape-after (gsh/transform-shape shape-before)] diff --git a/frontend/src/app/main/data/workspace/drawing/box.cljs b/frontend/src/app/main/data/workspace/drawing/box.cljs index ad91a1226..c586af8c4 100644 --- a/frontend/src/app/main/data/workspace/drawing/box.cljs +++ b/frontend/src/app/main/data/workspace/drawing/box.cljs @@ -47,9 +47,9 @@ (-> shape (assoc :click-draw? false) - (gsh/transform-shape (-> (ctm/empty-modifiers) - (ctm/set-resize scalev (gpt/point x y)) - (ctm/set-move movev)))))) + (gsh/transform-shape (-> (ctm/empty) + (ctm/resize scalev (gpt/point x y)) + (ctm/move movev)))))) (defn update-drawing [state initial point lock?] (update-in state [:workspace-drawing :object] resize-shape initial point lock?)) diff --git a/frontend/src/app/main/data/workspace/drawing/common.cljs b/frontend/src/app/main/data/workspace/drawing/common.cljs index 2016c3c7d..ad0da2563 100644 --- a/frontend/src/app/main/data/workspace/drawing/common.cljs +++ b/frontend/src/app/main/data/workspace/drawing/common.cljs @@ -51,7 +51,7 @@ (and click-draw? (not text?)) (-> (assoc :width min-side :height min-side) - (gsh/transform-shape (ctm/move (- (/ min-side 2)) (- (/ min-side 2))))) + (gsh/transform-shape (ctm/move-modifiers (- (/ min-side 2)) (- (/ min-side 2))))) (and click-draw? text?) (assoc :height 17 :width 4 :grow-type :auto-width) diff --git a/frontend/src/app/main/data/workspace/modifiers.cljs b/frontend/src/app/main/data/workspace/modifiers.cljs index 9263d9745..b6f6d2464 100644 --- a/frontend/src/app/main/data/workspace/modifiers.cljs +++ b/frontend/src/app/main/data/workspace/modifiers.cljs @@ -159,11 +159,11 @@ (filterv #(contains? child-set %)))] (cond-> modif-tree (not= original-frame target-frame) - (-> (update-in [original-frame :modifiers] ctm/set-remove-children shapes) - (update-in [target-frame :modifiers] ctm/set-add-children shapes drop-index)) + (-> (update-in [original-frame :modifiers] ctm/remove-children shapes) + (update-in [target-frame :modifiers] ctm/add-children shapes drop-index)) (and layout? (= original-frame target-frame)) - (update-in [target-frame :modifiers] ctm/set-add-children shapes drop-index))))] + (update-in [target-frame :modifiers] ctm/add-children shapes drop-index))))] (reduce update-frame-modifiers modif-tree origin-frame-ids))) @@ -214,7 +214,7 @@ get-modifier (fn [shape] - (ctm/rotation shape center angle)) + (ctm/rotation-modifiers shape center angle)) modif-tree (-> (build-modif-tree ids objects get-modifier) diff --git a/frontend/src/app/main/data/workspace/shape_layout.cljs b/frontend/src/app/main/data/workspace/shape_layout.cljs index c1a94684a..799cf0497 100644 --- a/frontend/src/app/main/data/workspace/shape_layout.cljs +++ b/frontend/src/app/main/data/workspace/shape_layout.cljs @@ -52,7 +52,7 @@ (let [objects (wsh/lookup-page-objects state) ids (->> ids (filter (partial ctl/layout? objects)))] (if (d/not-empty? ids) - (let [modif-tree (dwm/create-modif-tree ids (ctm/reflow))] + (let [modif-tree (dwm/create-modif-tree ids (ctm/reflow-modifiers))] (rx/of (dwm/set-modifiers modif-tree) (dwm/apply-modifiers))) (rx/empty)))))) diff --git a/frontend/src/app/main/data/workspace/texts.cljs b/frontend/src/app/main/data/workspace/texts.cljs index 06592a153..0527184a0 100644 --- a/frontend/src/app/main/data/workspace/texts.cljs +++ b/frontend/src/app/main/data/workspace/texts.cljs @@ -322,11 +322,11 @@ {shape-width :width shape-height :height} selrect] (cond-> shape (and (not-changed? shape-width new-width) (= grow-type :auto-width)) - (gsh/transform-shape (ctm/change-dimensions shape :width new-width)) + (gsh/transform-shape (ctm/change-dimensions-modifiers shape :width new-width)) (and (not-changed? shape-height new-height) (or (= grow-type :auto-height) (= grow-type :auto-width))) - (gsh/transform-shape (ctm/change-dimensions shape :height new-height)))))] + (gsh/transform-shape (ctm/change-dimensions-modifiers shape :height new-height)))))] (rx/of (dch/update-shapes [id] update-fn {:reg-objects? true :save-undo? false})))))) @@ -346,10 +346,10 @@ (let [new-shape (cond-> shape (some? width) - (gsh/transform-shape (ctm/change-dimensions shape :width width)) + (gsh/transform-shape (ctm/change-dimensions-modifiers shape :width width)) (some? height) - (gsh/transform-shape (ctm/change-dimensions shape :height height)) + (gsh/transform-shape (ctm/change-dimensions-modifiers shape :height height)) (some? position-data) (assoc :position-data position-data)) diff --git a/frontend/src/app/main/data/workspace/transforms.cljs b/frontend/src/app/main/data/workspace/transforms.cljs index 7ef6eb3cd..543757c1f 100644 --- a/frontend/src/app/main/data/workspace/transforms.cljs +++ b/frontend/src/app/main/data/workspace/transforms.cljs @@ -185,19 +185,19 @@ (and layout-child? fill-height?))) modifiers - (-> (ctm/empty-modifiers) + (-> (ctm/empty) (cond-> displacement - (ctm/set-move displacement)) - (ctm/set-resize scalev resize-origin shape-transform shape-transform-inverse) + (ctm/move displacement)) + (ctm/resize scalev resize-origin shape-transform shape-transform-inverse) (cond-> set-fix-width? - (ctm/set-change-property :layout-item-h-sizing :fix)) + (ctm/change-property :layout-item-h-sizing :fix)) (cond-> set-fix-height? - (ctm/set-change-property :layout-item-v-sizing :fix)) + (ctm/change-property :layout-item-v-sizing :fix)) (cond-> scale-text - (ctm/set-scale-content (:x scalev)))) + (ctm/scale-content (:x scalev)))) modif-tree (dwm/create-modif-tree ids modifiers)] (rx/of (dwm/set-modifiers modif-tree)))) @@ -251,7 +251,7 @@ snap-pixel? (and (contains? (:workspace-layout state) :snap-pixel-grid) (int? value)) get-modifier - (fn [shape] (ctm/change-dimensions shape attr value)) + (fn [shape] (ctm/change-dimensions-modifiers shape attr value)) modif-tree (-> (dwm/build-modif-tree ids objects get-modifier) @@ -486,7 +486,7 @@ (->> move-stream (rx/map (fn [[move-vector target-frame drop-index]] - (-> (dwm/create-modif-tree ids (ctm/move move-vector)) + (-> (dwm/create-modif-tree ids (ctm/move-modifiers move-vector)) (dwm/build-change-frame-modifiers objects selected target-frame drop-index) (dwm/set-modifiers))))) @@ -540,7 +540,7 @@ (rx/merge (->> move-events (rx/scan #(gpt/add %1 mov-vec) (gpt/point 0 0)) - (rx/map #(dwm/create-modif-tree selected (ctm/move %))) + (rx/map #(dwm/create-modif-tree selected (ctm/move-modifiers %))) (rx/map (partial dwm/set-modifiers)) (rx/take-until stopper)) (rx/of (move-selected direction shift?))) @@ -573,7 +573,7 @@ (or (:y position) (:y bbox))) delta (gpt/subtract pos cpos) - modif-tree (dwm/create-modif-tree [id] (ctm/move delta))] + modif-tree (dwm/create-modif-tree [id] (ctm/move-modifiers delta))] (rx/of (dwm/set-modifiers modif-tree) (dwm/apply-modifiers)))))) @@ -633,9 +633,9 @@ modif-tree (dwm/create-modif-tree selected - (-> (ctm/empty-modifiers) - (ctm/set-resize (gpt/point -1.0 1.0) origin) - (ctm/set-move (gpt/point (:width selrect) 0))))] + (-> (ctm/empty) + (ctm/resize (gpt/point -1.0 1.0) origin) + (ctm/move (gpt/point (:width selrect) 0))))] (rx/of (dwm/set-modifiers modif-tree true) (dwm/apply-modifiers)))))) @@ -652,9 +652,9 @@ modif-tree (dwm/create-modif-tree selected - (-> (ctm/empty-modifiers) - (ctm/set-resize (gpt/point 1.0 -1.0) origin) - (ctm/set-move (gpt/point 0 (:height selrect)))))] + (-> (ctm/empty) + (ctm/resize (gpt/point 1.0 -1.0) origin) + (ctm/move (gpt/point 0 (:height selrect)))))] (rx/of (dwm/set-modifiers modif-tree true) (dwm/apply-modifiers)))))) diff --git a/frontend/src/app/main/render.cljs b/frontend/src/app/main/render.cljs index a2627d2da..c12236ad1 100644 --- a/frontend/src/app/main/render.cljs +++ b/frontend/src/app/main/render.cljs @@ -187,7 +187,7 @@ mod-ids (cons object-id (cph/get-children-ids objects object-id)) - updt-fn #(update %1 %2 gsh/transform-shape (ctm/move vector))] + updt-fn #(update %1 %2 gsh/transform-shape (ctm/move-modifiers vector))] (reduce updt-fn objects mod-ids))) @@ -254,14 +254,14 @@ objects (mf/with-memo [frame-id objects vector] - (let [update-fn #(update %1 %2 gsh/transform-shape (ctm/move vector))] + (let [update-fn #(update %1 %2 gsh/transform-shape (ctm/move-modifiers vector))] (->> children-ids (into [frame-id]) (reduce update-fn objects)))) frame (mf/with-memo [vector] - (gsh/transform-shape frame (ctm/move vector))) + (gsh/transform-shape frame (ctm/move-modifiers vector))) frame (cond-> frame @@ -313,7 +313,7 @@ (mf/deps vector objects group-id) (fn [] (let [children-ids (cons group-id (cph/get-children-ids objects group-id)) - update-fn #(update %1 %2 gsh/transform-shape (ctm/move vector))] + update-fn #(update %1 %2 gsh/transform-shape (ctm/move-modifiers vector))] (reduce update-fn objects children-ids)))) group (get objects group-id) diff --git a/frontend/src/app/main/ui/viewer/interactions.cljs b/frontend/src/app/main/ui/viewer/interactions.cljs index 51b136d11..47bd71143 100644 --- a/frontend/src/app/main/ui/viewer/interactions.cljs +++ b/frontend/src/app/main/ui/viewer/interactions.cljs @@ -33,7 +33,7 @@ (let [frame-id (:id frame) vector (-> (gpt/point (:x size) (:y size)) (gpt/negate)) - update-fn #(d/update-when %1 %2 gsh/transform-shape (ctm/move vector))] + update-fn #(d/update-when %1 %2 gsh/transform-shape (ctm/move-modifiers vector))] (->> (cph/get-children-ids objects frame-id) (into [frame-id]) (reduce update-fn objects)))) diff --git a/frontend/src/app/main/ui/workspace/shapes/frame/dynamic_modifiers.cljs b/frontend/src/app/main/ui/workspace/shapes/frame/dynamic_modifiers.cljs index b5a34ba65..5b2a0a800 100644 --- a/frontend/src/app/main/ui/workspace/shapes/frame/dynamic_modifiers.cljs +++ b/frontend/src/app/main/ui/workspace/shapes/frame/dynamic_modifiers.cljs @@ -188,7 +188,7 @@ (/ (:height shape) (:height shape')))] ;; Reverse the change in size so we can recalculate the layout (-> modifiers - (ctm/set-resize scalev (-> shape' :points first) (:transform shape') (:transform-inverse shape'))))) + (ctm/resize scalev (-> shape' :points first) (:transform shape') (:transform-inverse shape'))))) (defn use-dynamic-modifiers [objects node modifiers] @@ -205,7 +205,7 @@ (ctm/modifiers->transform modifiers))) modifiers)))) - add-children (mf/use-memo (mf/deps modifiers) #(ctm/get-frame-add-children modifiers)) + add-children (mf/use-memo (mf/deps modifiers) #(ctm/added-children-frames modifiers)) add-children (hooks/use-equal-memo add-children) add-children-prev (hooks/use-previous add-children) diff --git a/frontend/src/app/main/ui/workspace/shapes/text/viewport_texts_html.cljs b/frontend/src/app/main/ui/workspace/shapes/text/viewport_texts_html.cljs index 50e2e6ebc..96d946f26 100644 --- a/frontend/src/app/main/ui/workspace/shapes/text/viewport_texts_html.cljs +++ b/frontend/src/app/main/ui/workspace/shapes/text/viewport_texts_html.cljs @@ -42,7 +42,7 @@ deltav (gpt/to-vec (gpt/point (:selrect shape')) (gpt/point (:selrect shape)))] - (gsh/transform-shape shape' (ctm/move deltav)))) + (gsh/transform-shape shape' (ctm/move-modifiers deltav)))) (defn process-shape [modifiers {:keys [id] :as shape}] (let [modifier (dm/get-in modifiers [id :modifiers])]