0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-03-12 07:41:43 -05:00

Adapted dynamic modifiers and options for new modifiers

This commit is contained in:
alonso.torres 2022-10-21 16:03:11 +02:00
parent af098bb64d
commit 58fd20094a
4 changed files with 29 additions and 23 deletions

View file

@ -27,6 +27,7 @@
;; * reflow
;; - structure-child: Structure recursive
;; * scale-content
;; * rotation
;;
(def conjv (fnil conj []))
@ -62,6 +63,8 @@
(defn set-rotation
[modifiers center angle]
(-> modifiers
(update :structure-child conjv {:type :rotation
:rotation angle})
(update :geometry conjv {:type :rotation
:center center
:rotation angle})))
@ -327,11 +330,12 @@
(let [remove? (set children-to-remove)]
(d/removev remove? shapes)))
apply-modifier
(fn [shape {:keys [type value index]}]
(fn [shape {:keys [type value index rotation]}]
(cond-> shape
(= type :rotation)
(update :rotation #(mod (+ % rotation) 360))
(and (= type :add-children) (some? index))
(update :shapes
(fn [shapes]
@ -348,7 +352,6 @@
(= type :scale-content)
(apply-scale-content value)))]
(as-> shape $
(reduce apply-modifier $ (:structure-parent modifiers))
(reduce apply-modifier $ (:structure-child modifiers)))))

View file

@ -248,18 +248,22 @@
(mf/use-layout-effect
(mf/deps transforms)
(fn []
(let [is-prev-val? (d/not-empty? @prev-modifiers)
is-cur-val? (d/not-empty? modifiers)]
(when (and (not is-prev-val?) is-cur-val?)
(start-transform! node shapes))
(let [curr-shapes-set (into #{} (map :id) shapes)
prev-shapes-set (into #{} (map :id) @prev-shapes)
(when is-cur-val?
new-shapes (->> shapes (remove #(contains? prev-shapes-set (:id %))))
removed-shapes (->> @prev-shapes (remove #(contains? curr-shapes-set (:id %))))]
(when (d/not-empty? new-shapes)
(start-transform! node new-shapes))
(when (d/not-empty? shapes)
(update-transform! node shapes transforms modifiers))
(when (and is-prev-val? (not is-cur-val?))
(remove-transform! node @prev-shapes))
(when (d/not-empty? removed-shapes)
(remove-transform! node @prev-shapes)))
(reset! prev-modifiers modifiers)
(reset! prev-transforms transforms)
(reset! prev-shapes shapes))))))
(reset! prev-modifiers modifiers)
(reset! prev-transforms transforms)
(reset! prev-shapes shapes)))))

View file

@ -60,12 +60,9 @@
{::mf/wrap [mf/memo]}
[{:keys [selected section shapes shapes-with-children page-id file-id]}]
(let [drawing (mf/deref refs/workspace-drawing)
base-objects (-> (mf/deref refs/workspace-page-objects))
objects (mf/deref refs/workspace-page-objects)
shared-libs (mf/deref refs/workspace-libraries)
modifiers (mf/deref refs/workspace-modifiers)
objects-modified (mf/with-memo [base-objects modifiers]
(ctm/merge-modifiers base-objects modifiers))
selected-shapes (into [] (keep (d/getf objects-modified)) selected)]
selected-shapes (into [] (keep (d/getf objects)) selected)]
[:div.tool-window
[:div.tool-window-content
[:& tab-container {:on-change-tab #(st/emit! (udw/set-options-mode %))

View file

@ -68,7 +68,9 @@
;; -- User/drawing coords
(mf/defc measures-menu
[{:keys [ids ids-with-children values type all-types shape] :as props}]
(let [options (if (= type :multiple)
(let [workspace-modifiers (mf/deref refs/workspace-modifiers)
options (if (= type :multiple)
(reduce #(union %1 %2) (map #(get type->options %) all-types))
(get type->options type))
@ -83,7 +85,9 @@
;; the shape with the mouse, generate a copy of the shapes applying
;; the transient transformations.
shapes (as-> old-shapes $
#_(map gsh/transform-shape $)
(map (fn [shape]
(let [modifiers (get-in workspace-modifiers [(:id shape) :modifiers])]
(gsh/transform-shape shape modifiers))) $)
(map gsh/translate-to-frame $ frames))
;; For rotated or stretched shapes, the origin point we show in the menu
@ -441,5 +445,3 @@
(tr "workspace.options.show-in-viewer")]])
]]]))