Merge pull request #2799 from penpot/alotor-polishing-5

Polishing
This commit is contained in:
Eva Marco 2023-01-18 11:38:40 +01:00 committed by GitHub
commit c5d8d77070
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 123 additions and 79 deletions

View File

@ -274,12 +274,12 @@
(Point. (mth/precision (dm/get-prop pt :x) decimals) (Point. (mth/precision (dm/get-prop pt :x) decimals)
(mth/precision (dm/get-prop pt :y) decimals)))) (mth/precision (dm/get-prop pt :y) decimals))))
(defn half-round (defn round-step
"Round the coordinates to the closest half-point" "Round the coordinates to the closest half-point"
[pt] [pt step]
(assert (point? pt) "expected point instance") (assert (point? pt) "expected point instance")
(Point. (mth/half-round (dm/get-prop pt :x)) (Point. (mth/round (dm/get-prop pt :x) step)
(mth/half-round (dm/get-prop pt :y)))) (mth/round (dm/get-prop pt :y) step)))
(defn transform (defn transform
"Transform a point applying a matrix transformation." "Transform a point applying a matrix transformation."

View File

@ -382,15 +382,24 @@
result)) result))
(defn set-objects-modifiers (defn set-objects-modifiers
([modif-tree objects ignore-constraints snap-pixel?] ([modif-tree objects]
(set-objects-modifiers nil modif-tree objects ignore-constraints snap-pixel?)) (set-objects-modifiers modif-tree objects nil))
([old-modif-tree modif-tree objects ignore-constraints snap-pixel?] ([modif-tree objects params]
(set-objects-modifiers nil modif-tree objects params))
([old-modif-tree modif-tree objects
{:keys [ignore-constraints snap-pixel? snap-precision]
:or {ignore-constraints false snap-pixel? false snap-precision 1}}]
(let [objects (-> objects (let [objects (-> objects
(cond-> (some? old-modif-tree) (cond-> (some? old-modif-tree)
(apply-structure-modifiers old-modif-tree)) (apply-structure-modifiers old-modif-tree))
(apply-structure-modifiers modif-tree)) (apply-structure-modifiers modif-tree))
modif-tree
(cond-> modif-tree
snap-pixel? (gpp/adjust-pixel-precision objects snap-precision))
bounds (d/lazy-map (keys objects) #(dm/get-in objects [% :points])) bounds (d/lazy-map (keys objects) #(dm/get-in objects [% :points]))
bounds (cond-> bounds bounds (cond-> bounds
(some? old-modif-tree) (some? old-modif-tree)
@ -417,11 +426,7 @@
modif-tree modif-tree
(if old-modif-tree (if old-modif-tree
(merge-modif-tree old-modif-tree modif-tree) (merge-modif-tree old-modif-tree modif-tree)
modif-tree) modif-tree)]
modif-tree
(cond-> modif-tree
snap-pixel? (gpp/adjust-pixel-precision objects))]
;;#?(:cljs ;;#?(:cljs
;; (.log js/console ">result" (modif->js modif-tree objects))) ;; (.log js/console ">result" (modif->js modif-tree objects)))

View File

@ -18,7 +18,7 @@
[app.common.types.modifiers :as ctm])) [app.common.types.modifiers :as ctm]))
(defn size-pixel-precision (defn size-pixel-precision
[modifiers shape points] [modifiers shape points precision]
(let [origin (gpo/origin points) (let [origin (gpo/origin points)
curr-width (gpo/width-points points) curr-width (gpo/width-points points)
curr-height (gpo/height-points points) curr-height (gpo/height-points points)
@ -29,8 +29,8 @@
vertical-line? (and path? (<= curr-width 0.01)) vertical-line? (and path? (<= curr-width 0.01))
horizontal-line? (and path? (<= curr-height 0.01)) horizontal-line? (and path? (<= curr-height 0.01))
target-width (if vertical-line? curr-width (max 1 (mth/round curr-width))) target-width (if vertical-line? curr-width (max 1 (mth/round curr-width precision)))
target-height (if horizontal-line? curr-height (max 1 (mth/round curr-height))) target-height (if horizontal-line? curr-height (max 1 (mth/round curr-height precision)))
ratio-width (/ target-width curr-width) ratio-width (/ target-width curr-width)
ratio-height (/ target-height curr-height) ratio-height (/ target-height curr-height)
@ -39,23 +39,23 @@
(ctm/resize scalev origin transform transform-inverse {:precise? true})))) (ctm/resize scalev origin transform transform-inverse {:precise? true}))))
(defn position-pixel-precision (defn position-pixel-precision
[modifiers _ points] [modifiers _ points precision]
(let [bounds (gpr/bounds->rect points) (let [bounds (gpr/bounds->rect points)
corner (gpt/point bounds) corner (gpt/point bounds)
target-corner (gpt/round corner) target-corner (gpt/round-step corner precision)
deltav (gpt/to-vec corner target-corner)] deltav (gpt/to-vec corner target-corner)]
(ctm/move modifiers deltav))) (ctm/move modifiers deltav)))
(defn set-pixel-precision (defn set-pixel-precision
"Adjust modifiers so they adjust to the pixel grid" "Adjust modifiers so they adjust to the pixel grid"
[modifiers shape] [modifiers shape precision]
(let [points (-> shape :points (gco/transform-points (ctm/modifiers->transform modifiers))) (let [points (-> shape :points (gco/transform-points (ctm/modifiers->transform modifiers)))
has-resize? (not (ctm/only-move? modifiers)) has-resize? (not (ctm/only-move? modifiers))
[modifiers points] [modifiers points]
(let [modifiers (let [modifiers
(cond-> modifiers (cond-> modifiers
has-resize? (size-pixel-precision shape points)) has-resize? (size-pixel-precision shape points precision))
points points
(if has-resize? (if has-resize?
@ -63,16 +63,16 @@
(gco/transform-points (ctm/modifiers->transform modifiers)) ) (gco/transform-points (ctm/modifiers->transform modifiers)) )
points)] points)]
[modifiers points])] [modifiers points])]
(position-pixel-precision modifiers shape points))) (position-pixel-precision modifiers shape points precision)))
(defn adjust-pixel-precision (defn adjust-pixel-precision
[modif-tree objects] [modif-tree objects precision]
(let [update-modifiers (let [update-modifiers
(fn [modif-tree shape] (fn [modif-tree shape]
(let [modifiers (dm/get-in modif-tree [(:id shape) :modifiers])] (let [modifiers (dm/get-in modif-tree [(:id shape) :modifiers])]
(cond-> modif-tree (cond-> modif-tree
(ctm/has-geometry? modifiers) (ctm/has-geometry? modifiers)
(update-in [(:id shape) :modifiers] set-pixel-precision shape))))] (update-in [(:id shape) :modifiers] set-pixel-precision shape precision))))]
(->> (keys modif-tree) (->> (keys modif-tree)
(map (d/getf objects)) (map (d/getf objects))

View File

@ -104,15 +104,16 @@
(defn round (defn round
"Returns the value of a number rounded to "Returns the value of a number rounded to
the nearest integer." the nearest integer.
[v] If given step rounds to the next closest step, for example:
#?(:cljs (js/Math.round v) (round 13.4 0.5) => 13.5
:clj (Math/round (float v)))) (round 13.4 0.3) => 13.3"
([v step]
(* (round (/ v step)) step))
(defn half-round ([v]
"Returns a value rounded to the next point or half point" #?(:cljs (js/Math.round v)
[v] :clj (Math/round (float v)))))
(/ (round (* v 2)) 2))
(defn ceil (defn ceil
"Returns the smallest integer greater than "Returns the smallest integer greater than

View File

@ -203,7 +203,7 @@
(t/deftest halft-round-point (t/deftest halft-round-point
(let [p1 (gpt/point 1.34567 3.34567) (let [p1 (gpt/point 1.34567 3.34567)
rs (gpt/half-round p1)] rs (gpt/round-step p1 0.5)]
(t/is (gpt/point? rs)) (t/is (gpt/point? rs))
(t/is (mth/close? 1.5 (:x rs))) (t/is (mth/close? 1.5 (:x rs)))
(t/is (mth/close? 3.5 (:y rs))))) (t/is (mth/close? 3.5 (:y rs)))))

View File

@ -190,3 +190,5 @@
{:name "YouTube thumb" {:name "YouTube thumb"
:width 1280 :width 1280
:height 720}]) :height 720}])
(def zoom-half-pixel-precision 8)

View File

@ -16,6 +16,7 @@
[app.common.types.shape-tree :as ctst] [app.common.types.shape-tree :as ctst]
[app.common.types.shape.layout :as ctl] [app.common.types.shape.layout :as ctl]
[app.common.uuid :as uuid] [app.common.uuid :as uuid]
[app.main.constants :refer [zoom-half-pixel-precision]]
[app.main.data.workspace.drawing.common :as common] [app.main.data.workspace.drawing.common :as common]
[app.main.data.workspace.state-helpers :as wsh] [app.main.data.workspace.state-helpers :as wsh]
[app.main.snap :as snap] [app.main.snap :as snap]
@ -70,14 +71,15 @@
(let [stoper? #(or (ms/mouse-up? %) (= % :interrupt)) (let [stoper? #(or (ms/mouse-up? %) (= % :interrupt))
stoper (rx/filter stoper? stream) stoper (rx/filter stoper? stream)
layout (get state :workspace-layout) layout (get state :workspace-layout)
zoom (get-in state [:workspace-local :zoom] 1)
snap-pixel? (contains? layout :snap-pixel-grid) snap-pixel? (contains? layout :snap-pixel-grid)
initial (cond-> @ms/mouse-position snap-pixel? gpt/round) snap-precision (if (>= zoom zoom-half-pixel-precision) 0.5 1)
initial (cond-> @ms/mouse-position snap-pixel? (gpt/round-step snap-precision))
page-id (:current-page-id state) page-id (:current-page-id state)
objects (wsh/lookup-page-objects state page-id) objects (wsh/lookup-page-objects state page-id)
focus (:workspace-focus-selected state) focus (:workspace-focus-selected state)
zoom (get-in state [:workspace-local :zoom] 1)
fid (ctst/top-nested-frame objects initial) fid (ctst/top-nested-frame objects initial)
layout? (ctl/layout? objects fid) layout? (ctl/layout? objects fid)
@ -119,7 +121,7 @@
(rx/map #(conj current %))))) (rx/map #(conj current %)))))
(rx/map (rx/map
(fn [[_ shift? point]] (fn [[_ shift? point]]
#(update-drawing % initial (cond-> point snap-pixel? gpt/round) shift?))))) #(update-drawing % initial (cond-> point snap-pixel? (gpt/round-step snap-precision)) shift?)))))
(rx/take-until stoper)) (rx/take-until stoper))
(->> (rx/of (common/handle-finish-drawing)) (->> (rx/of (common/handle-finish-drawing))

View File

@ -8,6 +8,7 @@
(:require (:require
[app.common.exceptions :as ex] [app.common.exceptions :as ex]
[app.common.logging :as log] [app.common.logging :as log]
[app.common.math :as mth]
[app.common.pages.changes-builder :as pcb] [app.common.pages.changes-builder :as pcb]
[app.common.spec :as us] [app.common.spec :as us]
[app.common.types.container :as ctn] [app.common.types.container :as ctn]
@ -52,8 +53,8 @@
shape {:name name shape {:name name
:width width :width width
:height height :height height
:x (- x (/ width 2)) :x (mth/round (- x (/ width 2)))
:y (- y (/ height 2)) :y (mth/round (- y (/ height 2)))
:metadata {:width width :metadata {:width width
:height height :height height
:mtype mtype :mtype mtype

View File

@ -17,6 +17,7 @@
[app.common.spec :as us] [app.common.spec :as us]
[app.common.types.modifiers :as ctm] [app.common.types.modifiers :as ctm]
[app.common.types.shape.layout :as ctl] [app.common.types.shape.layout :as ctl]
[app.main.constants :refer [zoom-half-pixel-precision]]
[app.main.data.workspace.changes :as dch] [app.main.data.workspace.changes :as dch]
[app.main.data.workspace.comments :as-alias dwcm] [app.main.data.workspace.comments :as-alias dwcm]
[app.main.data.workspace.guides :as-alias dwg] [app.main.data.workspace.guides :as-alias dwg]
@ -244,12 +245,15 @@
(wsh/lookup-page-objects state) (wsh/lookup-page-objects state)
snap-pixel? snap-pixel?
(and (not ignore-snap-pixel) (contains? (:workspace-layout state) :snap-pixel-grid))] (and (not ignore-snap-pixel) (contains? (:workspace-layout state) :snap-pixel-grid))
zoom (dm/get-in state [:workspace-local :zoom])
snap-precision (if (>= zoom zoom-half-pixel-precision) 0.5 1)]
(as-> objects $ (as-> objects $
(apply-text-modifiers $ (get state :workspace-text-modifier)) (apply-text-modifiers $ (get state :workspace-text-modifier))
;;(apply-path-modifiers $ (get-in state [:workspace-local :edit-path])) ;;(apply-path-modifiers $ (get-in state [:workspace-local :edit-path]))
(gsh/set-objects-modifiers modif-tree $ ignore-constraints snap-pixel?))))) (gsh/set-objects-modifiers modif-tree $ {:ignore-constraints ignore-constraints :snap-pixel? snap-pixel? :snap-precision snap-precision})))))
(defn- calculate-update-modifiers (defn- calculate-update-modifiers
[old-modif-tree state ignore-constraints ignore-snap-pixel modif-tree] [old-modif-tree state ignore-constraints ignore-snap-pixel modif-tree]
@ -259,10 +263,13 @@
snap-pixel? snap-pixel?
(and (not ignore-snap-pixel) (contains? (:workspace-layout state) :snap-pixel-grid)) (and (not ignore-snap-pixel) (contains? (:workspace-layout state) :snap-pixel-grid))
zoom (dm/get-in state [:workspace-local :zoom])
snap-precision (if (>= zoom zoom-half-pixel-precision) 0.5 1)
objects objects
(-> objects (-> objects
(apply-text-modifiers (get state :workspace-text-modifier)))] (apply-text-modifiers (get state :workspace-text-modifier)))]
(gsh/set-objects-modifiers old-modif-tree modif-tree objects ignore-constraints snap-pixel?))) (gsh/set-objects-modifiers old-modif-tree modif-tree objects {:ignore-constraints ignore-constraints :snap-pixel? snap-pixel? :snap-precision snap-precision})))
(defn update-modifiers (defn update-modifiers
([modif-tree] ([modif-tree]
@ -312,7 +319,7 @@
modif-tree modif-tree
(-> (build-modif-tree ids objects get-modifier) (-> (build-modif-tree ids objects get-modifier)
(gsh/set-objects-modifiers objects false false))] (gsh/set-objects-modifiers objects))]
(assoc state :workspace-modifiers modif-tree)))))) (assoc state :workspace-modifiers modif-tree))))))

View File

@ -8,6 +8,7 @@
(:require (:require
[app.common.geom.point :as gpt] [app.common.geom.point :as gpt]
[app.common.geom.shapes.path :as upg] [app.common.geom.shapes.path :as upg]
[app.main.constants :refer [zoom-half-pixel-precision]]
[app.main.data.workspace.path.state :as state] [app.main.data.workspace.path.state :as state]
[app.main.snap :as snap] [app.main.snap :as snap]
[app.main.store :as st] [app.main.store :as st]
@ -17,7 +18,6 @@
[potok.core :as ptk])) [potok.core :as ptk]))
(defonce drag-threshold 5) (defonce drag-threshold 5)
(def zoom-half-pixel-precision 8)
(defn dragging? [start zoom] (defn dragging? [start zoom]
(fn [current] (fn [current]
@ -36,7 +36,7 @@
position position
(>= zoom zoom-half-pixel-precision) (>= zoom zoom-half-pixel-precision)
(gpt/half-round position) (gpt/round-step position 0.5)
:else :else
(gpt/round position)))) (gpt/round position))))

View File

@ -11,6 +11,7 @@
[app.common.geom.matrix :as gmt] [app.common.geom.matrix :as gmt]
[app.common.geom.point :as gpt] [app.common.geom.point :as gpt]
[app.common.geom.shapes :as gsh] [app.common.geom.shapes :as gsh]
[app.common.math :as mth]
[app.common.pages.changes-builder :as pcb] [app.common.pages.changes-builder :as pcb]
[app.common.pages.helpers :as cph] [app.common.pages.helpers :as cph]
[app.common.spec :as us :refer [max-safe-int min-safe-int]] [app.common.spec :as us :refer [max-safe-int min-safe-int]]
@ -477,15 +478,17 @@
(rx/reduce (fn [acc [url image]] (assoc acc url image)) {}))) (rx/reduce (fn [acc [url image]] (assoc acc url image)) {})))
(defn create-svg-shapes (defn create-svg-shapes
[svg-data {:keys [x y] :as position} objects frame-id parent-id selected center?] [svg-data {:keys [x y]} objects frame-id parent-id selected center?]
(try (try
(let [[vb-x vb-y vb-width vb-height] (svg-dimensions svg-data) (let [[vb-x vb-y vb-width vb-height] (svg-dimensions svg-data)
x (if center? x (mth/round
(- x vb-x (/ vb-width 2)) (if center?
x) (- x vb-x (/ vb-width 2))
y (if center? x))
(- y vb-y (/ vb-height 2)) y (mth/round
y) (if center?
(- y vb-y (/ vb-height 2))
y))
unames (ctst/retrieve-used-names objects) unames (ctst/retrieve-used-names objects)

View File

@ -240,14 +240,12 @@
ptk/UpdateEvent ptk/UpdateEvent
(update [_ state] (update [_ state]
(let [objects (wsh/lookup-page-objects state) (let [objects (wsh/lookup-page-objects state)
snap-pixel? (and (contains? (:workspace-layout state) :snap-pixel-grid)
(int? value))
get-modifier get-modifier
(fn [shape] (ctm/change-dimensions-modifiers shape attr value)) (fn [shape] (ctm/change-dimensions-modifiers shape attr value))
modif-tree modif-tree
(-> (dwm/build-modif-tree ids objects get-modifier) (-> (dwm/build-modif-tree ids objects get-modifier)
(gsh/set-objects-modifiers objects false snap-pixel?))] (gsh/set-objects-modifiers objects))]
(assoc state :workspace-modifiers modif-tree))) (assoc state :workspace-modifiers modif-tree)))
@ -265,14 +263,13 @@
ptk/UpdateEvent ptk/UpdateEvent
(update [_ state] (update [_ state]
(let [objects (wsh/lookup-page-objects state) (let [objects (wsh/lookup-page-objects state)
snap-pixel? (contains? (get state :workspace-layout) :snap-pixel-grid)
get-modifier get-modifier
(fn [shape] (ctm/change-orientation-modifiers shape orientation)) (fn [shape] (ctm/change-orientation-modifiers shape orientation))
modif-tree modif-tree
(-> (dwm/build-modif-tree ids objects get-modifier) (-> (dwm/build-modif-tree ids objects get-modifier)
(gsh/set-objects-modifiers objects false snap-pixel?))] (gsh/set-objects-modifiers objects))]
(assoc state :workspace-modifiers modif-tree))) (assoc state :workspace-modifiers modif-tree)))
@ -623,7 +620,7 @@
(->> move-events (->> move-events
(rx/scan #(gpt/add %1 mov-vec) (gpt/point 0 0)) (rx/scan #(gpt/add %1 mov-vec) (gpt/point 0 0))
(rx/map #(dwm/create-modif-tree selected (ctm/move-modifiers %))) (rx/map #(dwm/create-modif-tree selected (ctm/move-modifiers %)))
(rx/map (partial dwm/set-modifiers)) (rx/map #(dwm/set-modifiers % false true))
(rx/take-until stopper)) (rx/take-until stopper))
(rx/of (nudge-selected-shapes direction shift?))) (rx/of (nudge-selected-shapes direction shift?)))
@ -669,11 +666,12 @@
cpos (gpt/point (:x bbox) (:y bbox)) cpos (gpt/point (:x bbox) (:y bbox))
pos (gpt/point (or (:x position) (:x bbox)) pos (gpt/point (or (:x position) (:x bbox))
(or (:y position) (:y bbox))) (or (:y position) (:y bbox)))
delta (gpt/subtract pos cpos) delta (gpt/subtract pos cpos)
modif-tree (dwm/create-modif-tree [id] (ctm/move-modifiers delta))] modif-tree (dwm/create-modif-tree [id] (ctm/move-modifiers delta))]
(rx/of (dwm/set-modifiers modif-tree) (rx/of (dwm/set-modifiers modif-tree false true)
(dwm/apply-modifiers)))))) (dwm/apply-modifiers))))))
(defn- move-shapes-to-frame (defn- move-shapes-to-frame
@ -688,7 +686,6 @@
shapes (->> ids (cph/clean-loops objects) (keep lookup)) shapes (->> ids (cph/clean-loops objects) (keep lookup))
moving-shapes moving-shapes
(cond->> shapes (cond->> shapes
(not layout?) (not layout?)

View File

@ -11,6 +11,7 @@
[app.common.geom.matrix :as gmt] [app.common.geom.matrix :as gmt]
[app.common.geom.point :as gpt] [app.common.geom.point :as gpt]
[app.common.geom.shapes :as gsh] [app.common.geom.shapes :as gsh]
[app.common.pages.helpers :as cph]
[app.common.types.modifiers :as ctm] [app.common.types.modifiers :as ctm]
[app.main.store :as st] [app.main.store :as st]
[app.main.ui.hooks :as hooks] [app.main.ui.hooks :as hooks]
@ -30,14 +31,14 @@
(defn get-nodes (defn get-nodes
"Retrieve the DOM nodes to apply the matrix transformation" "Retrieve the DOM nodes to apply the matrix transformation"
[base-node {:keys [id type masked-group?] :as shape}] [base-node {:keys [id parent-id] :as shape}]
(when (some? base-node) (when (some? base-node)
(let [shape-node (get-shape-node base-node id) (let [shape-node (get-shape-node base-node id)
parent-node (get-shape-node base-node parent-id)
frame? (= :frame type) frame? (cph/frame-shape? shape)
group? (= :group type) group? (cph/group-shape? shape)
text? (= :text type) text? (cph/text-shape? shape)
mask? (and group? masked-group?)] masking-child? (:masking-child? (meta shape))]
(cond (cond
frame? frame?
[shape-node [shape-node
@ -48,9 +49,10 @@
;; For groups we don't want to transform the whole group but only ;; For groups we don't want to transform the whole group but only
;; its filters/masks ;; its filters/masks
mask? masking-child?
[(dom/query shape-node ".mask-clip-path") [shape-node
(dom/query shape-node ".mask-shape")] (dom/query parent-node ".mask-clip-path")
(dom/query parent-node ".mask-shape")]
group? group?
(let [shape-defs (dom/query shape-node "defs")] (let [shape-defs (dom/query shape-node "defs")]
@ -74,10 +76,12 @@
(-> (dom/get-attribute node "data-old-width") d/parse-double) (-> (dom/get-attribute node "data-old-width") d/parse-double)
(-> (dom/get-attribute node "data-old-height") d/parse-double)) (-> (dom/get-attribute node "data-old-height") d/parse-double))
(gsh/transform-selrect modifiers))] (gsh/transform-selrect modifiers))]
(dom/set-attribute! node "x" x)
(dom/set-attribute! node "y" y) (when (and (some? x) (some? y) (some? width) (some? height))
(dom/set-attribute! node "width" width) (dom/set-attribute! node "x" x)
(dom/set-attribute! node "height" height))) (dom/set-attribute! node "y" y)
(dom/set-attribute! node "width" width)
(dom/set-attribute! node "height" height))))
(defn start-transform! (defn start-transform!
[base-node shapes] [base-node shapes]
@ -169,6 +173,11 @@
(or (= (dom/get-tag-name node) "mask") (or (= (dom/get-tag-name node) "mask")
(= (dom/get-tag-name node) "filter")) (= (dom/get-tag-name node) "filter"))
(do (do
(dom/set-attribute! node "x" (dom/get-attribute node "data-old-x"))
(dom/set-attribute! node "y" (dom/get-attribute node "data-old-y"))
(dom/set-attribute! node "width" (dom/get-attribute node "data-old-width"))
(dom/set-attribute! node "height" (dom/get-attribute node "data-old-height"))
(dom/remove-attribute! node "data-old-x") (dom/remove-attribute! node "data-old-x")
(dom/remove-attribute! node "data-old-y") (dom/remove-attribute! node "data-old-y")
(dom/remove-attribute! node "data-old-width") (dom/remove-attribute! node "data-old-width")
@ -190,6 +199,18 @@
(-> modifiers (-> modifiers
(ctm/resize scalev (-> shape' :points first) (:transform shape') (:transform-inverse shape'))))) (ctm/resize scalev (-> shape' :points first) (:transform shape') (:transform-inverse shape')))))
(defn add-masking-child?
"Adds to the object the information about if the current shape is a masking child. We use the metadata
to not adding new parameters to the object."
[objects]
(fn [{:keys [id parent-id] :as shape}]
(let [parent (get objects parent-id)
masking-child? (and (cph/mask-shape? parent) (= id (first (:shapes parent))))]
(cond-> shape
masking-child?
(with-meta {:masking-child? true})))))
(defn use-dynamic-modifiers (defn use-dynamic-modifiers
[objects node modifiers] [objects node modifiers]
@ -198,11 +219,15 @@
(mf/deps modifiers) (mf/deps modifiers)
(fn [] (fn []
(when (some? modifiers) (when (some? modifiers)
(d/mapm (fn [id {modifiers :modifiers}] (d/mapm (fn [id {current-modifiers :modifiers}]
(let [shape (get objects id) (let [shape (get objects id)
adapt-text? (and (= :text (:type shape)) (not (ctm/only-move? modifiers))) adapt-text? (and (= :text (:type shape)) (not (ctm/only-move? current-modifiers)))
modifiers (cond-> modifiers adapt-text? (adapt-text-modifiers shape))]
(ctm/modifiers->transform modifiers))) current-modifiers
(cond-> current-modifiers
adapt-text?
(adapt-text-modifiers shape))]
(ctm/modifiers->transform current-modifiers)))
modifiers)))) modifiers))))
add-children (mf/use-memo (mf/deps modifiers) #(ctm/added-children-frames modifiers)) add-children (mf/use-memo (mf/deps modifiers) #(ctm/added-children-frames modifiers))
@ -215,7 +240,7 @@
(fn [] (fn []
(->> (keys transforms) (->> (keys transforms)
(filter #(some? (get transforms %))) (filter #(some? (get transforms %)))
(mapv (d/getf objects))))) (mapv (comp (add-masking-child? objects) (d/getf objects))))))
prev-shapes (mf/use-var nil) prev-shapes (mf/use-var nil)
prev-modifiers (mf/use-var nil) prev-modifiers (mf/use-var nil)
@ -252,7 +277,6 @@
(mf/use-layout-effect (mf/use-layout-effect
(mf/deps transforms) (mf/deps transforms)
(fn [] (fn []
(let [curr-shapes-set (into #{} (map :id) shapes) (let [curr-shapes-set (into #{} (map :id) shapes)
prev-shapes-set (into #{} (map :id) @prev-shapes) prev-shapes-set (into #{} (map :id) @prev-shapes)
@ -266,7 +290,7 @@
(update-transform! node shapes transforms modifiers)) (update-transform! node shapes transforms modifiers))
(when (d/not-empty? removed-shapes) (when (d/not-empty? removed-shapes)
(remove-transform! node @prev-shapes))) (remove-transform! node removed-shapes)))
(reset! prev-modifiers modifiers) (reset! prev-modifiers modifiers)
(reset! prev-transforms transforms) (reset! prev-transforms transforms)

View File

@ -22,6 +22,7 @@
[app.main.ui.workspace.viewport.path-actions :refer [path-actions]] [app.main.ui.workspace.viewport.path-actions :refer [path-actions]]
[app.main.ui.workspace.viewport.utils :as vwu] [app.main.ui.workspace.viewport.utils :as vwu]
[app.util.dom :as dom] [app.util.dom :as dom]
[app.util.timers :as ts]
[debug :refer [debug?]] [debug :refer [debug?]]
[rumext.v2 :as mf])) [rumext.v2 :as mf]))
@ -86,7 +87,8 @@
(mf/defc frame-title (mf/defc frame-title
{::mf/wrap [mf/memo]} {::mf/wrap [mf/memo
#(mf/deferred % ts/raf)]}
[{:keys [frame selected? zoom show-artboard-names? on-frame-enter on-frame-leave on-frame-select]}] [{:keys [frame selected? zoom show-artboard-names? on-frame-enter on-frame-leave on-frame-select]}]
(let [workspace-read-only? (mf/use-ctx ctx/workspace-read-only?) (let [workspace-read-only? (mf/use-ctx ctx/workspace-read-only?)
on-mouse-down on-mouse-down