Adds autolayout positions calculations

This commit is contained in:
alonso.torres 2022-09-29 13:37:54 +02:00
parent 5050c35257
commit c01c46041d
37 changed files with 938 additions and 594 deletions

View file

@ -159,8 +159,8 @@
build-move-event
(fn [comment-thread]
(let [frame (get objects (:frame-id comment-thread))
frame' (-> (merge frame (get object-modifiers (:frame-id comment-thread)))
(gsh/transform-shape))
modifiers (get object-modifiers (:frame-id comment-thread))
frame' (gsh/transform-shape frame modifiers)
moved (gpt/to-vec (gpt/point (:x frame) (:y frame))
(gpt/point (:x frame') (:y frame')))
position (get-in threads-position-map [(:id comment-thread) :position])

View file

@ -10,6 +10,7 @@
[app.common.geom.shapes :as gsh]
[app.common.math :as mth]
[app.common.pages.helpers :as cph]
[app.common.types.modifiers :as ctm]
[app.common.types.shape :as cts]
[app.common.types.shape-tree :as ctst]
[app.common.uuid :as uuid]
@ -37,9 +38,7 @@
scalev)]
(-> shape
(assoc :click-draw? false)
(assoc-in [:modifiers :resize-vector] scalev)
(assoc-in [:modifiers :resize-origin] (gpt/point x y))
(assoc-in [:modifiers :resize-rotation] 0))))
(gsh/transform-shape (ctm/resize scalev (gpt/point x y))))))
(defn update-drawing [state point lock?]
(update-in state [:workspace-drawing :object] resize-shape point lock?))

View file

@ -6,10 +6,10 @@
(ns app.main.data.workspace.drawing.common
(:require
[app.common.geom.matrix :as gmt]
[app.common.geom.shapes :as gsh]
[app.common.math :as mth]
[app.common.pages.helpers :as cph]
[app.common.types.modifiers :as ctm]
[app.common.types.shape :as cts]
[app.main.data.workspace.shapes :as dwsh]
[app.main.data.workspace.state-helpers :as wsh]
@ -51,8 +51,8 @@
(and click-draw? (not text?))
(-> (assoc :width min-side :height min-side)
(assoc-in [:modifiers :displacement]
(gmt/translate-matrix (- (/ min-side 2)) (- (/ min-side 2)))))
(gsh/transform-shape (ctm/move (- (/ min-side 2)) (- (/ min-side 2))))
#_(ctm/add-move (- (/ min-side 2)) (- (/ min-side 2))))
(and click-draw? text?)
(assoc :height 17 :width 4 :grow-type :auto-width)
@ -61,8 +61,7 @@
(cts/setup-rect-selrect)
:always
(-> (gsh/transform-shape)
(dissoc :initialized? :click-draw?)))]
(dissoc :initialized? :click-draw?))]
;; Add & select the created shape to the workspace
(rx/concat
(if (= :text (:type shape))

View file

@ -79,8 +79,7 @@
build-move-event
(fn [guide]
(let [frame (get objects (:frame-id guide))
frame' (-> (merge frame (get object-modifiers (:frame-id guide)))
(gsh/transform-shape))
frame' (gsh/transform-shape (get object-modifiers (:frame-id guide)))
moved (gpt/to-vec (gpt/point (:x frame) (:y frame))
(gpt/point (:x frame') (:y frame')))

View file

@ -55,7 +55,7 @@
(dwt/apply-modifiers))
(rx/empty))))))
;; TODO: Remove constraints from children
;; TODO LAYOUT: Remove constraints from children
(defn create-layout
[ids type]
(ptk/reify ::create-layout

View file

@ -8,9 +8,9 @@
(:require
[app.common.data :as d]
[app.common.data.macros :as dm]
[app.common.geom.shapes :as gsh]
[app.common.pages.helpers :as cph]
[app.common.path.commands :as upc]))
[app.common.path.commands :as upc]
[app.common.types.modifiers :as ctm]))
(defn lookup-page
([state]
@ -137,5 +137,6 @@
children (select-keys objects children-ids)]
(as-> children $
(gsh/merge-modifiers $ modifiers)
;; TODO LAYOUT: REVIEW THIS
(ctm/merge-modifiers $ modifiers)
(d/mapm (set-content-modifiers state) $))))

View file

@ -13,6 +13,7 @@
[app.common.math :as mth]
[app.common.pages.helpers :as cph]
[app.common.text :as txt]
[app.common.types.modifiers :as ctm]
[app.common.uuid :as uuid]
[app.main.data.workspace.changes :as dch]
[app.main.data.workspace.common :as dwc]
@ -319,17 +320,16 @@
(letfn [(update-fn [shape]
(let [{:keys [selrect grow-type]} shape
{shape-width :width shape-height :height} selrect
modifier-width (gsh/resize-modifiers shape :width new-width)
modifier-height (gsh/resize-modifiers shape :height new-height)]
modifier-width (ctm/resize-modifiers shape :width new-width)
modifier-height (ctm/resize-modifiers shape :height new-height)]
;; TODO LAYOUT: MEZCLAR ESTOS EN UN UNICO MODIFIER
(cond-> shape
(and (not-changed? shape-width new-width) (= grow-type :auto-width))
(-> (assoc :modifiers modifier-width)
(gsh/transform-shape))
(gsh/transform-shape modifier-width)
(and (not-changed? shape-height new-height)
(or (= grow-type :auto-height) (= grow-type :auto-width)))
(-> (assoc :modifiers modifier-height)
(gsh/transform-shape)))))]
(gsh/transform-shape modifier-height))))]
(rx/of (dch/update-shapes [id] update-fn {:reg-objects? true :save-undo? false}))))))
@ -346,18 +346,17 @@
(defn apply-text-modifier
[shape {:keys [width height position-data]}]
(let [modifier-width (when width (gsh/resize-modifiers shape :width width))
modifier-height (when height (gsh/resize-modifiers shape :height height))
(let [modifier-width (when width (ctm/resize-modifiers shape :width width))
modifier-height (when height (ctm/resize-modifiers shape :height height))
;; TODO LAYOUT: MEZCLAR LOS DOS EN UN UNICO MODIFIER
new-shape
(cond-> shape
(some? modifier-width)
(-> (assoc :modifiers modifier-width)
(gsh/transform-shape))
(gsh/transform-shape modifier-width)
(some? modifier-height)
(-> (assoc :modifiers modifier-height)
(gsh/transform-shape))
(gsh/transform-shape modifier-height)
(some? position-data)
(assoc :position-data position-data))

View file

@ -16,6 +16,7 @@
[app.common.pages.common :as cpc]
[app.common.pages.helpers :as cph]
[app.common.spec :as us]
[app.common.types.modifiers :as ctm]
[app.common.types.shape-tree :as ctst]
[app.main.data.workspace.changes :as dch]
[app.main.data.workspace.collapse :as dwc]
@ -154,14 +155,14 @@
ids
(->> shapes
(remove #(get % :blocked false))
(mapcat #(cph/get-children objects (:id %)))
(concat shapes)
#_(mapcat #(cph/get-children objects (:id %)))
#_(concat shapes)
(filter #((cpc/editable-attrs (:type %)) :rotation))
(map :id))
get-modifier
(fn [shape]
(gsh/rotation-modifiers shape center angle))
(ctm/rotation-modifiers shape center angle))
modif-tree
(gsh/set-objects-modifiers ids objects get-modifier false false)]
@ -193,7 +194,7 @@
(let [objects (wsh/lookup-page-objects state)
object-modifiers (get state :workspace-modifiers)
ids (keys object-modifiers)
ids (or (keys object-modifiers) [])
ids-with-children (into (vec ids) (mapcat #(cph/get-children-ids objects %)) ids)
shapes (map (d/getf objects) ids)
@ -209,11 +210,10 @@
(dch/update-shapes
ids
(fn [shape]
(let [modif (get object-modifiers (:id shape))
(let [modif (get-in object-modifiers [(:id shape) :modifiers])
text-shape? (cph/text-shape? shape)]
(-> shape
(merge modif)
(gsh/transform-shape)
(gsh/transform-shape modif)
(cond-> text-shape?
(update-grow-type shape)))))
{:reg-objects? true
@ -295,7 +295,7 @@
(let [children (map (d/getf objects) (:shapes shape))
shape-id (:id shape)
transformed-shape (gsh/transform-shape (merge shape (get modif-tree shape-id)))
transformed-shape (gsh/transform-shape shape (get modif-tree shape-id))
[root transformed-root ignore-geometry?]
(check-delta shape root transformed-shape transformed-root objects modif-tree)
@ -331,10 +331,10 @@
rotation (or rotation 0)
initial (gsh/transform-point-center initial shape-center shape-transform-inverse)
initial (gmt/transform-point-center initial shape-center shape-transform-inverse)
initial (fix-init-point initial handler shape)
point (gsh/transform-point-center (if (= rotation 0) point-snap point)
point (gmt/transform-point-center (if (= rotation 0) point-snap point)
shape-center shape-transform-inverse)
shapev (-> (gpt/point width height))
@ -381,14 +381,28 @@
(gpt/transform shape-transform)))
resize-origin
(cond-> (gsh/transform-point-center handler-origin shape-center shape-transform)
(cond-> (gmt/transform-point-center handler-origin shape-center shape-transform)
(some? displacement)
(gpt/add displacement))
displacement (when (some? displacement)
(gmt/translate-matrix displacement))]
(gpt/add displacement))]
(rx/of (set-modifiers ids
{:v2 (-> []
(cond-> displacement
(conj {:type :move
:vector displacement}))
(conj {:type :resize
:vector scalev
:origin resize-origin
:transform shape-transform
:transform-inverse shape-transform-inverse}))
;;:displacement displacement
;;:resize-vector scalev
;;:resize-origin resize-origin
;;:resize-transform shape-transform
;;:resize-scale-text scale-text
;;:resize-transform-inverse shape-transform-inverse
}))
#_(rx/of (set-modifiers ids
{:displacement displacement
:resize-vector scalev
:resize-origin resize-origin
@ -444,7 +458,7 @@
snap-pixel? (and (contains? (:workspace-layout state) :snap-pixel-grid)
(int? value))
get-modifier
(fn [shape] (gsh/resize-modifiers shape attr value))
(fn [shape] (ctm/resize-modifiers shape attr value))
modif-tree
(gsh/set-objects-modifiers ids objects get-modifier false snap-pixel?)]
@ -468,7 +482,7 @@
snap-pixel? (contains? (get state :workspace-layout) :snap-pixel-grid)
get-modifier
(fn [shape] (gsh/change-orientation-modifiers shape orientation))
(fn [shape] (ctm/change-orientation-modifiers shape orientation))
modif-tree
(gsh/set-objects-modifiers ids objects get-modifier false snap-pixel?)]
@ -655,7 +669,10 @@
(rx/with-latest vector snap-delta)
;; We try to use the previous snap so we don't have to wait for the result of the new
(rx/map snap/correct-snap-point)
(rx/map #(hash-map :displacement (gmt/translate-matrix %)))
#_(rx/map #(hash-map :displacement (gmt/translate-matrix %)))
(rx/map #(array-map :v2 [{:type :move :vector %}]))
(rx/map (partial set-modifiers ids))
(rx/take-until stopper))
@ -704,7 +721,7 @@
(rx/merge
(->> move-events
(rx/scan #(gpt/add %1 mov-vec) (gpt/point 0 0))
(rx/map #(hash-map :displacement (gmt/translate-matrix %)))
(rx/map #(ctm/move %))
(rx/map (partial set-modifiers selected))
(rx/take-until stopper))
(rx/of (move-selected direction shift?)))
@ -735,11 +752,11 @@
cpos (gpt/point (:x bbox) (:y bbox))
pos (gpt/point (or (:x position) (:x bbox))
(or (:y position) (:y bbox)))
delta (gpt/subtract pos cpos)
displ (gmt/translate-matrix delta)]
delta (gpt/subtract pos cpos)]
(rx/of (set-modifiers [id] {:displacement displ} false true)
(apply-modifiers [id]))))))
(rx/of
(set-modifiers [id] (ctm/move delta))
(apply-modifiers [id]))))))
(defn- calculate-frame-for-move
[ids]
@ -787,11 +804,16 @@
(let [objects (wsh/lookup-page-objects state)
selected (wsh/lookup-selected state {:omit-blocked? true})
shapes (map #(get objects %) selected)
selrect (gsh/selection-rect (->> shapes (map gsh/transform-shape)))
selrect (gsh/selection-rect shapes)
origin (gpt/point (:x selrect) (+ (:y selrect) (/ (:height selrect) 2)))]
(rx/of (set-modifiers selected
{:resize-vector (gpt/point -1.0 1.0)
{:v2 [{:type :resize
:vector (gpt/point -1.0 1.0)
:origin origin}
{:type :move
:vector (gpt/point (:width selrect) 0)}]}
#_{:resize-vector (gpt/point -1.0 1.0)
:resize-origin origin
:displacement (gmt/translate-matrix (gpt/point (- (:width selrect)) 0))}
true)
@ -804,11 +826,16 @@
(let [objects (wsh/lookup-page-objects state)
selected (wsh/lookup-selected state {:omit-blocked? true})
shapes (map #(get objects %) selected)
selrect (gsh/selection-rect (->> shapes (map gsh/transform-shape)))
selrect (gsh/selection-rect shapes)
origin (gpt/point (+ (:x selrect) (/ (:width selrect) 2)) (:y selrect))]
(rx/of (set-modifiers selected
{:resize-vector (gpt/point 1.0 -1.0)
{:v2 [{:type :resize
:vector (gpt/point 1.0 -1.0)
:origin origin}
{:type :move
:vector (gpt/point 0 (:height selrect))}]}
#_{:resize-vector (gpt/point 1.0 -1.0)
:resize-origin origin
:displacement (gmt/translate-matrix (gpt/point 0 (- (:height selrect))))}
true)

View file

@ -15,12 +15,12 @@
["react-dom/server" :as rds]
[app.common.colors :as clr]
[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.common.geom.shapes.bounds :as gsb]
[app.common.math :as mth]
[app.common.pages.helpers :as cph]
[app.common.types.modifiers :as ctm]
[app.common.types.shape-tree :as ctst]
[app.config :as cfg]
[app.main.fonts :as fonts]
@ -82,7 +82,8 @@
(let [render-thumbnails? (mf/use-ctx muc/render-thumbnails)
childs (mapv #(get objects %) (:shapes shape))
shape (gsh/transform-shape shape)]
;;shape (gsh/transform-shape shape)
]
(if (and render-thumbnails? (some? (:thumbnail shape)))
[:& frame/frame-thumbnail {:shape shape :bounds (:children-bounds shape)}]
[:& frame-shape {:shape shape :childs childs}])))))
@ -135,7 +136,7 @@
bool-wrapper (mf/use-memo (mf/deps objects) #(bool-wrapper-factory objects))
frame-wrapper (mf/use-memo (mf/deps objects) #(frame-wrapper-factory objects))]
(when (and shape (not (:hidden shape)))
(let [shape (gsh/transform-shape shape)
(let [;;shape (gsh/transform-shape shape)
opts #js {:shape shape}
svg-raw? (= :svg-raw (:type shape))]
(if-not svg-raw?
@ -167,7 +168,8 @@
(let [shapes (cph/get-immediate-children objects)
srect (gsh/selection-rect shapes)
object (merge object (select-keys srect [:x :y :width :height]))
object (gsh/transform-shape object)]
;; object (gsh/transform-shape object)
]
(assoc object :fill-color "#f0f0f0")))
(defn adapt-objects-for-shape
@ -180,14 +182,12 @@
;; Replace the previous object with the new one
objects (assoc objects object-id object)
modifier (-> (gpt/point (:x object) (:y object))
(gpt/negate)
(gmt/translate-matrix))
vector (-> (gpt/point (:x object) (:y object))
(gpt/negate))
mod-ids (cons object-id (cph/get-children-ids objects object-id))
updt-fn #(-> %1
(assoc-in [%2 :modifiers :displacement] modifier)
(update %2 gsh/transform-shape))]
updt-fn #(update %1 %2 gsh/transform-shape (ctm/move vector))]
(reduce updt-fn objects mod-ids)))
@ -247,24 +247,21 @@
bounds2 (gsb/get-object-bounds objects (dissoc frame :shadow :blur))
delta-bounds (gpt/point (:x bounds) (:y bounds))
modifier (gmt/translate-matrix (gpt/negate delta-bounds))
vector (gpt/negate delta-bounds)
children-ids
(cph/get-children-ids objects frame-id)
objects
(mf/with-memo [frame-id objects modifier]
(let [update-fn #(assoc-in %1 [%2 :modifiers :displacement] modifier)]
(mf/with-memo [frame-id objects vector]
(let [update-fn #(update-in %1 %2 ctm/add-move vector)]
(->> children-ids
(into [frame-id])
(reduce update-fn objects))))
frame
(mf/with-memo [modifier]
(-> frame
(assoc-in [:modifiers :displacement] modifier)
(gsh/transform-shape)))
(mf/with-memo [vector]
(gsh/transform-shape frame (ctm/move vector)))
frame
(cond-> frame
@ -305,22 +302,21 @@
(let [group-id (:id group)
include-metadata? (mf/use-ctx export/include-metadata-ctx)
modifier
vector
(mf/use-memo
(mf/deps (:x group) (:y group))
(fn []
(-> (gpt/point (:x group) (:y group))
(gpt/negate)
(gmt/translate-matrix))))
(gpt/negate))))
objects
(mf/use-memo
(mf/deps modifier objects group-id)
(mf/deps vector objects group-id)
(fn []
(let [modifier-ids (cons group-id (cph/get-children-ids objects group-id))
update-fn #(assoc-in %1 [%2 :modifiers :displacement] modifier)
update-fn #(update %1 %2 ctm/add-move vector)
modifiers (reduce update-fn {} modifier-ids)]
(gsh/merge-modifiers objects modifiers))))
(ctm/merge-modifiers objects modifiers))))
group (get objects group-id)
width (* (:width group) zoom)

View file

@ -6,7 +6,6 @@
(ns app.main.ui.shapes.bool
(:require
[app.common.data :as d]
[app.common.data.macros :as dm]
[app.common.geom.shapes :as gsh]
[app.main.ui.hooks :refer [use-equal-memo]]
@ -15,6 +14,7 @@
[app.util.object :as obj]
[rumext.v2 :as mf]))
;; TODO LAYOUT: REVIEW DYNAMIC CHANGES IN BOOLEANS
(defn bool-shape
[shape-wrapper]
(mf/fnc bool-shape
@ -35,7 +35,7 @@
(some? childs)
(->> childs
(d/mapm #(gsh/transform-shape %2))
#_(d/mapm #(gsh/transform-shape %2))
(gsh/calc-bool-content shape)))))]
[:*

View file

@ -7,6 +7,7 @@
(ns app.main.ui.shapes.mask
(:require
[app.common.data :as d]
[app.common.data.macros :as dm]
[app.common.geom.shapes :as gsh]
[app.main.ui.context :as muc]
[cuerdas.core :as str]
@ -50,9 +51,7 @@
render-id (mf/use-ctx muc/render-id)
svg-text? (and (= :text (:type mask)) (some? (:position-data mask)))
mask-bb (-> (gsh/transform-shape mask)
(:points))
mask-bb (:points mask)
mask-bb-rect (gsh/points->rect mask-bb)]
[:defs
[:filter {:id (filter-id render-id mask)}
@ -68,7 +67,7 @@
[:clipPath {:class "mask-clip-path"
:id (clip-id render-id mask)}
[:polyline {:points (->> mask-bb
(map #(str (:x %) "," (:y %)))
(map #(dm/str (:x %) "," (:y %)))
(str/join " "))}]]
;; When te shape is a text we pass to the shape the info and disable the filter.

View file

@ -88,7 +88,7 @@
[props]
(let [shape (unchecked-get props "shape")
childs (mapv #(get objects %) (:shapes shape))
shape (gsh/transform-shape shape)
;;shape (gsh/transform-shape shape)
props (-> (obj/create)
(obj/merge! props)
@ -171,8 +171,7 @@
(mf/use-memo (mf/deps objects)
#(svg-raw-container-factory objects))]
(when (and shape (not (:hidden shape)))
(let [shape (-> (gsh/transform-shape shape)
(gsh/translate-to-frame frame))
(let [shape (gsh/translate-to-frame shape frame)
opts #js {:shape shape
:frame frame}]
(case (:type shape)

View file

@ -8,9 +8,9 @@
(: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.pages.helpers :as cph]
[app.common.types.modifiers :as ctm]
[app.common.types.page :as ctp]
[app.common.uuid :as uuid]
[app.main.data.comments :as dcm]
@ -31,11 +31,10 @@
[frame size objects]
(let [
frame-id (:id frame)
modifier (-> (gpt/point (:x size) (:y size))
(gpt/negate)
(gmt/translate-matrix))
vector (-> (gpt/point (:x size) (:y size))
(gpt/negate))
update-fn #(d/update-when %1 %2 assoc-in [:modifiers :displacement] modifier)]
update-fn #(d/update-when %1 %2 ctm/add-move vector)]
(->> (cph/get-children-ids objects frame-id)
(into [frame-id])

View file

@ -350,7 +350,7 @@
[props]
(let [shape (obj/get props "shape")
childs (mapv #(get objects %) (:shapes shape))
shape (gsh/transform-shape shape)
;;shape (gsh/transform-shape shape)
props (obj/merge! #js {} props
#js {:shape shape
:childs childs
@ -429,7 +429,8 @@
(mf/with-memo [objects]
(svg-raw-container-factory objects))]
(when (and shape (not (:hidden shape)))
(let [shape (-> (gsh/transform-shape shape)
(let [shape (-> shape
#_(gsh/transform-shape)
(gsh/translate-to-frame frame))
opts #js {:shape shape

View file

@ -11,6 +11,7 @@
[app.common.geom.matrix :as gmt]
[app.common.geom.point :as gpt]
[app.common.geom.shapes :as gsh]
[app.common.types.modifiers :as ctm]
[app.main.store :as st]
[app.main.ui.workspace.viewport.utils :as vwu]
[app.util.dom :as dom]
@ -184,6 +185,7 @@
text? (= type :text)
transform-text? (and text? (and (nil? (:resize-vector modifiers)) (nil? (:resize-vector-2 modifiers))))]
;; TODO LAYOUT: Adapt to new modifiers
(doseq [node nodes]
(cond
;; Text shapes need special treatment because their resize only change
@ -197,7 +199,7 @@
(dom/class? node "text-container")
(let [modifiers (dissoc modifiers :displacement :rotation)]
(when (not (gsh/empty-modifiers? modifiers))
(when (not (ctm/empty-modifiers? modifiers))
(let [mtx (-> shape
(assoc :modifiers modifiers)
(gsh/transform-shape)
@ -260,12 +262,15 @@
(d/mapm (fn [id {modifiers :modifiers}]
(let [shape (get objects id)
center (gsh/center-shape shape)
;; TODO LAYOUT: Adapt to new modifiers
modifiers (cond-> modifiers
;; For texts we only use the displacement because
;; resize needs to recalculate the text layout
(= :text (:type shape))
(select-keys [:displacement :rotation]))]
(gsh/modifiers->transform center modifiers)))
(select-keys [:displacement :rotation]))
]
(ctm/modifiers->transform center modifiers)))
modifiers))))
shapes

View file

@ -58,7 +58,7 @@
:height height
:style {:fill "none" :stroke "red"}}]
;; Text baselineazo
;; Text baseline
[:line {:x1 (mth/round x)
:y1 (mth/round (- (:y data) (:height data)))
:x2 (mth/round (+ x width))

View file

@ -13,6 +13,7 @@
[app.common.math :as mth]
[app.common.pages.helpers :as cph]
[app.common.text :as txt]
[app.common.types.modifiers :as ctm]
[app.main.data.workspace.texts :as dwt]
[app.main.fonts :as fonts]
[app.main.refs :as refs]
@ -33,6 +34,7 @@
(with-meta (meta (:position-data shape))))
(dissoc :position-data :transform :transform-inverse)))
;; TODO LAYOUT: Adapt to new modifiers
(defn strip-modifier
[modifier]
(if (or (some? (dm/get-in modifier [:modifiers :resize-vector]))
@ -43,9 +45,9 @@
(defn process-shape [modifiers {:keys [id] :as shape}]
(let [modifier (-> (get modifiers id) strip-modifier)
shape (cond-> shape
(not (gsh/empty-modifiers? (:modifiers modifier)))
(not (ctm/empty-modifiers? (:modifiers modifier)))
(-> (assoc :grow-type :fixed)
(merge modifier) gsh/transform-shape))]
(gsh/transform-shape modifier)))]
(-> shape
(cond-> (nil? (:position-data shape))
(assoc :migrate true))

View file

@ -7,7 +7,7 @@
(ns app.main.ui.workspace.sidebar.options
(:require
[app.common.data :as d]
[app.common.geom.shapes :as gsh]
[app.common.types.modifiers :as ctm]
[app.main.data.workspace :as udw]
[app.main.refs :as refs]
[app.main.store :as st]
@ -64,7 +64,7 @@
shared-libs (mf/deref refs/workspace-libraries)
modifiers (mf/deref refs/workspace-modifiers)
objects-modified (mf/with-memo [base-objects modifiers]
(gsh/merge-modifiers base-objects modifiers))
(ctm/merge-modifiers base-objects modifiers))
selected-shapes (into [] (keep (d/getf objects-modified)) selected)]
[:div.tool-window
[:div.tool-window-content

View file

@ -79,8 +79,7 @@
modifiers (mf/deref refs/workspace-modifiers)
objects-modified (mf/with-memo [base-objects modifiers]
(gsh/merge-modifiers base-objects modifiers))
(gsh/apply-objects-modifiers base-objects modifiers))
background (get options :background clr/canvas)
;; STATE
@ -203,7 +202,7 @@
{:key (dm/str "texts-" page-id)
:page-id page-id
:objects objects
:modifiers modifiers
;;:modifiers modifiers
:edition edition}]]]]
(when show-comments?
@ -336,10 +335,9 @@
(when show-prototypes?
[:& widgets/frame-flows
{:flows (:flows options)
:objects base-objects
:objects objects-modified
:selected selected
:zoom zoom
:modifiers modifiers
:on-frame-enter on-frame-enter
:on-frame-leave on-frame-leave
:on-frame-select on-frame-select}])
@ -348,8 +346,7 @@
[:& drawarea/draw-area
{:shape drawing-obj
:zoom zoom
:tool drawing-tool
:modifiers modifiers}])
:tool drawing-tool}])
(when show-grids?
[:& frame-grid/frame-grid
@ -371,9 +368,8 @@
:zoom zoom
:page-id page-id
:selected selected
:objects base-objects
:focus focus
:modifiers modifiers}])
:objects objects-modified
:focus focus}])
(when show-snap-distance?
[:& snap-distances/snap-distances
@ -416,7 +412,6 @@
{:zoom zoom
:vbox vbox
:hover-frame frame-parent
:modifiers modifiers
:disabled-guides? disabled-guides?}])
(when show-selection-handlers?

View file

@ -7,7 +7,6 @@
(ns app.main.ui.workspace.viewport.drawarea
"Drawing components."
(:require
[app.common.geom.shapes :as gsh]
[app.common.math :as mth]
[app.main.ui.shapes.path :refer [path-shape]]
[app.main.ui.workspace.shapes :as shapes]
@ -22,7 +21,7 @@
[:g.draw-area
[:g {:style {:pointer-events "none"}}
[:& shapes/shape-wrapper {:shape (gsh/transform-shape shape)}]]
[:& shapes/shape-wrapper {:shape shape}]]
(case tool
:path [:& path-editor {:shape shape :zoom zoom}]
@ -31,7 +30,7 @@
(mf/defc generic-draw-area
[{:keys [shape zoom]}]
(let [{:keys [x y width height]} (:selrect (gsh/transform-shape shape))]
(let [{:keys [x y width height]} (:selrect shape)]
(when (and x y
(not (mth/nan? x))
(not (mth/nan? y)))

View file

@ -278,7 +278,7 @@
frame]} (use-guide handle-change-position get-hover-frame zoom guide)
base-frame (or frame hover-frame)
frame (gsh/transform-shape (merge base-frame frame-modifier))
frame (gsh/transform-shape base-frame frame-modifier)
move-vec (gpt/to-vec (gpt/point (:x base-frame) (:y base-frame))
(gpt/point (:x frame) (:y frame)))

View file

@ -9,7 +9,6 @@
(:require
[app.common.data :as d]
[app.common.data.macros :as dm]
[app.common.geom.shapes :as gsh]
[app.common.pages.helpers :as cph]
[app.common.types.shape.interactions :as ctsi]
[app.main.data.workspace :as dw]
@ -254,13 +253,11 @@
(mf/defc interactions
[{:keys [current-transform objects zoom selected hover-disabled?] :as props}]
(let [active-shapes (into []
(comp (filter #(seq (:interactions %)))
(map gsh/transform-shape))
(comp (filter #(seq (:interactions %))))
(vals objects))
selected-shapes (into []
(comp (map (d/getf objects))
(map gsh/transform-shape))
(map (d/getf objects))
selected)
{:keys [editing-interaction-index

View file

@ -72,7 +72,7 @@
"var(--color-primary)" "var(--color-component-highlight)")]
(for [shape shapes]
[:& outline {:key (str "outline-" (:id shape))
:shape (gsh/transform-shape shape)
:shape shape
:zoom zoom
:color color}])))

View file

@ -341,7 +341,7 @@
(let [shape (mf/use-memo
(mf/deps shapes)
#(->> shapes
(map gsh/transform-shape)
#_(map gsh/transform-shape)
(gsh/selection-rect)
(cts/setup-shape)))
on-resize
@ -369,7 +369,7 @@
(let [shape (mf/use-memo
(mf/deps shapes)
#(->> shapes
(map gsh/transform-shape)
#_(map gsh/transform-shape)
(gsh/selection-rect)
(cts/setup-shape)))]
@ -384,7 +384,7 @@
(mf/defc single-handlers
[{:keys [shape zoom color disable-handlers] :as props}]
(let [shape-id (:id shape)
shape (gsh/transform-shape shape)
;;shape (gsh/transform-shape shape)
on-resize
(fn [current-position _initial-position event]
@ -408,14 +408,13 @@
(mf/defc single-selection
[{:keys [shape zoom color disable-handlers on-move-selected on-context-menu] :as props}]
(let [shape (gsh/transform-shape shape)]
[:& controls-selection
{:shape shape
:zoom zoom
:color color
:disable-handlers disable-handlers
:on-move-selected on-move-selected
:on-context-menu on-context-menu}]))
[:& controls-selection
{:shape shape
:zoom zoom
:color color
:disable-handlers disable-handlers
:on-move-selected on-move-selected
:on-context-menu on-context-menu}])
(mf/defc selection-area
{::mf/wrap [mf/memo]}

View file

@ -50,20 +50,14 @@
:opacity line-opacity}])
(defn get-snap
[coord {:keys [shapes page-id remove-snap? zoom modifiers]}]
(let [shapes-sr
(->> shapes
;; Merge modifiers into shapes
(map #(merge % (get modifiers (:id %))))
;; Create the bounding rectangle for the shapes
(gsh/selection-rect))
[coord {:keys [shapes page-id remove-snap? zoom]}]
(let [bounds (gsh/selection-rect shapes)
frame-id (snap/snap-frame-id shapes)]
frame-id (snap/snap-frame-id shapes)]
(->> (rx/of shapes-sr)
(->> (rx/of bounds)
(rx/flat-map
(fn [selrect]
(->> (sp/selrect-snap-points selrect)
(fn [bounds]
(->> (sp/selrect-snap-points bounds)
(map #(vector frame-id %)))))
(rx/flat-map
@ -159,7 +153,7 @@
(mf/defc snap-points
{::mf/wrap [mf/memo]}
[{:keys [layout zoom objects selected page-id drawing modifiers focus] :as props}]
[{:keys [layout zoom objects selected page-id drawing focus] :as props}]
(us/assert set? selected)
(let [shapes (into [] (keep (d/getf objects)) selected)
@ -182,6 +176,5 @@
[:& snap-feedback {:shapes shapes
:page-id page-id
:remove-snap? remove-snap?
:zoom zoom
:modifiers modifiers}]))
:zoom zoom}]))

View file

@ -53,9 +53,7 @@
(defn text-transform
[{:keys [x y]} zoom]
(let [inv-zoom (/ 1 zoom)]
(str
"scale(" inv-zoom ", " inv-zoom ") "
"translate(" (* zoom x) ", " (* zoom y) ")")))
(dm/fmt "scale(%, %) translate(%, %)" inv-zoom inv-zoom (* zoom x) (* zoom y))))
(defn title-transform [frame zoom]
(let [frame-transform (gsh/transform-str frame {:no-flip true})

View file

@ -9,7 +9,6 @@
[app.common.data :as d]
[app.common.data.macros :as dm]
[app.common.geom.point :as gpt]
[app.common.geom.shapes :as gsh]
[app.common.types.shape-tree :as ctt]
[app.common.uuid :as uuid]
[app.main.data.workspace :as dw]
@ -182,8 +181,8 @@
:on-frame-select on-frame-select}]))]))
(mf/defc frame-flow
[{:keys [flow frame modifiers selected? zoom on-frame-enter on-frame-leave on-frame-select]}]
(let [{:keys [x y]} (gsh/transform-shape frame)
[{:keys [flow frame selected? zoom on-frame-enter on-frame-leave on-frame-select]}]
(let [{:keys [x y]} frame
flow-pos (gpt/point x (- y (/ 35 zoom)))
on-mouse-down
@ -217,9 +216,7 @@
:y -15
:width 100000
:height 24
:transform (str (when (and selected? modifiers)
(str (:displacement modifiers) " " ))
(vwu/text-transform flow-pos zoom))}
:transform (vwu/text-transform flow-pos zoom)}
[:div.flow-badge {:class (dom/classnames :selected selected?)}
[:div.content {:on-mouse-down on-mouse-down
:on-double-click on-double-click
@ -234,7 +231,6 @@
(let [flows (unchecked-get props "flows")
objects (unchecked-get props "objects")
zoom (unchecked-get props "zoom")
modifiers (unchecked-get props "modifiers")
selected (or (unchecked-get props "selected") #{})
on-frame-enter (unchecked-get props "on-frame-enter")
@ -248,7 +244,6 @@
:frame frame
:selected? (contains? selected (:id frame))
:zoom zoom
:modifiers modifiers
:on-frame-enter on-frame-enter
:on-frame-leave on-frame-leave
:on-frame-select on-frame-select}]))]))

View file

@ -29,10 +29,9 @@
(defn shape-snap-points
[{:keys [hidden blocked] :as shape}]
(when (and (not blocked) (not hidden))
(let [shape (gsh/transform-shape shape)]
(case (:type shape)
:frame (-> shape :points gsh/points->selrect frame-snap-points)
(into #{(gsh/center-shape shape)} (:points shape))))))
(case (:type shape)
:frame (-> shape :points gsh/points->selrect frame-snap-points)
(into #{(gsh/center-shape shape)} (:points shape)))))
(defn guide-snap-points
[guide frame]