diff --git a/common/src/app/common/geom/shapes/modifiers.cljc b/common/src/app/common/geom/shapes/modifiers.cljc index 270df14d5..1966fc03f 100644 --- a/common/src/app/common/geom/shapes/modifiers.cljc +++ b/common/src/app/common/geom/shapes/modifiers.cljc @@ -317,33 +317,47 @@ modif-tree))) (defn set-objects-modifiers - [modif-tree objects ignore-constraints snap-pixel?] + ([modif-tree objects ignore-constraints snap-pixel?] + (set-objects-modifiers nil modif-tree objects ignore-constraints snap-pixel?)) - (let [objects (apply-structure-modifiers objects modif-tree) + ([old-modif-tree modif-tree objects ignore-constraints snap-pixel?] + (let [objects (-> objects + (cond-> (some? old-modif-tree) + (apply-structure-modifiers old-modif-tree)) + (apply-structure-modifiers modif-tree)) - bounds (d/lazy-map (keys objects) #(dm/get-in objects [% :points])) - shapes-tree (resolve-tree-sequence (-> modif-tree keys set) objects) + bounds (d/lazy-map (keys objects) #(dm/get-in objects [% :points])) + bounds (cond-> bounds + (some? old-modif-tree) + (transform-bounds objects old-modif-tree)) - ;; Calculate the input transformation and constraints - modif-tree (reduce #(propagate-modifiers-constraints objects bounds ignore-constraints %1 %2) modif-tree shapes-tree) - bounds (transform-bounds bounds objects modif-tree shapes-tree) + shapes-tree (resolve-tree-sequence (-> modif-tree keys set) objects) - [modif-tree-layout sizing-auto-layouts] - (reduce #(propagate-modifiers-layout objects bounds ignore-constraints %1 %2) [{} #{}] shapes-tree) + ;; Calculate the input transformation and constraints + modif-tree (reduce #(propagate-modifiers-constraints objects bounds ignore-constraints %1 %2) modif-tree shapes-tree) + bounds (transform-bounds bounds objects modif-tree shapes-tree) - modif-tree (merge-modif-tree modif-tree modif-tree-layout) + [modif-tree-layout sizing-auto-layouts] + (reduce #(propagate-modifiers-layout objects bounds ignore-constraints %1 %2) [{} #{}] shapes-tree) - ;; Calculate hug layouts positions - bounds (transform-bounds bounds objects modif-tree-layout shapes-tree) + modif-tree (merge-modif-tree modif-tree modif-tree-layout) - modif-tree - (-> modif-tree - (sizing-auto-modifiers sizing-auto-layouts objects bounds ignore-constraints)) + ;; Calculate hug layouts positions + bounds (transform-bounds bounds objects modif-tree-layout shapes-tree) - modif-tree - (cond-> modif-tree - snap-pixel? (gpp/adjust-pixel-precision objects))] + modif-tree + (-> modif-tree + (sizing-auto-modifiers sizing-auto-layouts objects bounds ignore-constraints)) - ;;#?(:cljs - ;; (.log js/console ">result" (modif->js modif-tree objects))) - modif-tree)) + modif-tree + (if old-modif-tree + (merge-modif-tree old-modif-tree modif-tree) + modif-tree) + + modif-tree + (cond-> modif-tree + snap-pixel? (gpp/adjust-pixel-precision objects))] + + ;;#?(:cljs + ;; (.log js/console ">result" (modif->js modif-tree objects))) + modif-tree))) diff --git a/frontend/src/app/main/data/workspace/modifiers.cljs b/frontend/src/app/main/data/workspace/modifiers.cljs index 808798457..ec2688421 100644 --- a/frontend/src/app/main/data/workspace/modifiers.cljs +++ b/frontend/src/app/main/data/workspace/modifiers.cljs @@ -190,26 +190,27 @@ [(get-in objects [k :name]) v])) modif-tree))) +(defn apply-text-modifier + [shape {:keys [width height]}] + (cond-> shape + (some? width) + (assoc :width width) + + (some? height) + (assoc :height height) + + (or (some? width) (some? height)) + (cts/setup-rect-selrect))) + (defn apply-text-modifiers [objects text-modifiers] - (letfn [(apply-text-modifier - [shape {:keys [width height]}] - (cond-> shape - (some? width) - (assoc :width width) - - (some? height) - (assoc :height height) - - (or (some? width) (some? height)) - (cts/setup-rect-selrect)))] - (loop [modifiers (seq text-modifiers) - result objects] - (if (empty? modifiers) - result - (let [[id text-modifier] (first modifiers)] - (recur (rest modifiers) - (update objects id apply-text-modifier text-modifier))))))) + (loop [modifiers (seq text-modifiers) + result objects] + (if (empty? modifiers) + result + (let [[id text-modifier] (first modifiers)] + (recur (rest modifiers) + (update objects id apply-text-modifier text-modifier)))))) #_(defn apply-path-modifiers [objects path-modifiers] @@ -242,6 +243,33 @@ ;;(apply-path-modifiers $ (get-in state [:workspace-local :edit-path])) (gsh/set-objects-modifiers modif-tree $ ignore-constraints snap-pixel?))))) +(defn- calculate-update-modifiers + [old-modif-tree state ignore-constraints ignore-snap-pixel modif-tree] + (let [objects + (wsh/lookup-page-objects state) + + snap-pixel? + (and (not ignore-snap-pixel) (contains? (:workspace-layout state) :snap-pixel-grid)) + + objects + (-> objects + (apply-text-modifiers (get state :workspace-text-modifier)))] + + (gsh/set-objects-modifiers old-modif-tree modif-tree objects ignore-constraints snap-pixel?))) + +(defn update-modifiers + ([modif-tree] + (update-modifiers modif-tree false)) + + ([modif-tree ignore-constraints] + (update-modifiers modif-tree ignore-constraints false)) + + ([modif-tree ignore-constraints ignore-snap-pixel] + (ptk/reify ::update-modifiers + ptk/UpdateEvent + (update [_ state] + (update state :workspace-modifiers calculate-update-modifiers state ignore-constraints ignore-snap-pixel modif-tree))))) + (defn set-modifiers ([modif-tree] (set-modifiers modif-tree false)) diff --git a/frontend/src/app/main/data/workspace/texts.cljs b/frontend/src/app/main/data/workspace/texts.cljs index 7659f8b35..1d4c0098f 100644 --- a/frontend/src/app/main/data/workspace/texts.cljs +++ b/frontend/src/app/main/data/workspace/texts.cljs @@ -408,8 +408,7 @@ (not (mth/close? (:height props) current-height)))) (let [modif-tree (dwm/create-modif-tree [id] (ctm/reflow-modifiers))] - (->> (rx/of (dwm/set-modifiers modif-tree)) - (rx/observe-on :async))) + (rx/of (dwm/update-modifiers modif-tree))) (rx/empty))))))) (defn clean-text-modifier diff --git a/frontend/src/app/main/ui/shapes/text/svg_text.cljs b/frontend/src/app/main/ui/shapes/text/svg_text.cljs index 5e93ce855..64edf8503 100644 --- a/frontend/src/app/main/ui/shapes/text/svg_text.cljs +++ b/frontend/src/app/main/ui/shapes/text/svg_text.cljs @@ -8,8 +8,6 @@ (:require [app.common.data :as d] [app.common.data.macros :as dm] - [app.common.geom.matrix :as gmt] - [app.common.geom.point :as gpt] [app.common.geom.shapes :as gsh] [app.config :as cf] [app.main.ui.context :as muc]