mirror of
https://github.com/penpot/penpot.git
synced 2025-08-01 16:18:33 +02:00
✨ Adapted dynamic modifiers and options for new modifiers
This commit is contained in:
parent
af098bb64d
commit
58fd20094a
4 changed files with 29 additions and 23 deletions
|
@ -27,6 +27,7 @@
|
||||||
;; * reflow
|
;; * reflow
|
||||||
;; - structure-child: Structure recursive
|
;; - structure-child: Structure recursive
|
||||||
;; * scale-content
|
;; * scale-content
|
||||||
|
;; * rotation
|
||||||
;;
|
;;
|
||||||
|
|
||||||
(def conjv (fnil conj []))
|
(def conjv (fnil conj []))
|
||||||
|
@ -62,6 +63,8 @@
|
||||||
(defn set-rotation
|
(defn set-rotation
|
||||||
[modifiers center angle]
|
[modifiers center angle]
|
||||||
(-> modifiers
|
(-> modifiers
|
||||||
|
(update :structure-child conjv {:type :rotation
|
||||||
|
:rotation angle})
|
||||||
(update :geometry conjv {:type :rotation
|
(update :geometry conjv {:type :rotation
|
||||||
:center center
|
:center center
|
||||||
:rotation angle})))
|
:rotation angle})))
|
||||||
|
@ -327,11 +330,12 @@
|
||||||
(let [remove? (set children-to-remove)]
|
(let [remove? (set children-to-remove)]
|
||||||
(d/removev remove? shapes)))
|
(d/removev remove? shapes)))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
apply-modifier
|
apply-modifier
|
||||||
(fn [shape {:keys [type value index]}]
|
(fn [shape {:keys [type value index rotation]}]
|
||||||
(cond-> shape
|
(cond-> shape
|
||||||
|
(= type :rotation)
|
||||||
|
(update :rotation #(mod (+ % rotation) 360))
|
||||||
|
|
||||||
(and (= type :add-children) (some? index))
|
(and (= type :add-children) (some? index))
|
||||||
(update :shapes
|
(update :shapes
|
||||||
(fn [shapes]
|
(fn [shapes]
|
||||||
|
@ -348,7 +352,6 @@
|
||||||
(= type :scale-content)
|
(= type :scale-content)
|
||||||
(apply-scale-content value)))]
|
(apply-scale-content value)))]
|
||||||
|
|
||||||
|
|
||||||
(as-> shape $
|
(as-> shape $
|
||||||
(reduce apply-modifier $ (:structure-parent modifiers))
|
(reduce apply-modifier $ (:structure-parent modifiers))
|
||||||
(reduce apply-modifier $ (:structure-child modifiers)))))
|
(reduce apply-modifier $ (:structure-child modifiers)))))
|
||||||
|
|
|
@ -248,18 +248,22 @@
|
||||||
(mf/use-layout-effect
|
(mf/use-layout-effect
|
||||||
(mf/deps transforms)
|
(mf/deps transforms)
|
||||||
(fn []
|
(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?)
|
(let [curr-shapes-set (into #{} (map :id) shapes)
|
||||||
(start-transform! node 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))
|
(update-transform! node shapes transforms modifiers))
|
||||||
|
|
||||||
(when (and is-prev-val? (not is-cur-val?))
|
(when (d/not-empty? removed-shapes)
|
||||||
(remove-transform! node @prev-shapes))
|
(remove-transform! node @prev-shapes)))
|
||||||
|
|
||||||
(reset! prev-modifiers modifiers)
|
(reset! prev-modifiers modifiers)
|
||||||
(reset! prev-transforms transforms)
|
(reset! prev-transforms transforms)
|
||||||
(reset! prev-shapes shapes))))))
|
(reset! prev-shapes shapes)))))
|
||||||
|
|
|
@ -60,12 +60,9 @@
|
||||||
{::mf/wrap [mf/memo]}
|
{::mf/wrap [mf/memo]}
|
||||||
[{:keys [selected section shapes shapes-with-children page-id file-id]}]
|
[{:keys [selected section shapes shapes-with-children page-id file-id]}]
|
||||||
(let [drawing (mf/deref refs/workspace-drawing)
|
(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)
|
shared-libs (mf/deref refs/workspace-libraries)
|
||||||
modifiers (mf/deref refs/workspace-modifiers)
|
selected-shapes (into [] (keep (d/getf objects)) selected)]
|
||||||
objects-modified (mf/with-memo [base-objects modifiers]
|
|
||||||
(ctm/merge-modifiers base-objects modifiers))
|
|
||||||
selected-shapes (into [] (keep (d/getf objects-modified)) selected)]
|
|
||||||
[:div.tool-window
|
[:div.tool-window
|
||||||
[:div.tool-window-content
|
[:div.tool-window-content
|
||||||
[:& tab-container {:on-change-tab #(st/emit! (udw/set-options-mode %))
|
[:& tab-container {:on-change-tab #(st/emit! (udw/set-options-mode %))
|
||||||
|
|
|
@ -68,7 +68,9 @@
|
||||||
;; -- User/drawing coords
|
;; -- User/drawing coords
|
||||||
(mf/defc measures-menu
|
(mf/defc measures-menu
|
||||||
[{:keys [ids ids-with-children values type all-types shape] :as props}]
|
[{: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))
|
(reduce #(union %1 %2) (map #(get type->options %) all-types))
|
||||||
(get type->options type))
|
(get type->options type))
|
||||||
|
|
||||||
|
@ -83,7 +85,9 @@
|
||||||
;; the shape with the mouse, generate a copy of the shapes applying
|
;; the shape with the mouse, generate a copy of the shapes applying
|
||||||
;; the transient transformations.
|
;; the transient transformations.
|
||||||
shapes (as-> old-shapes $
|
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))
|
(map gsh/translate-to-frame $ frames))
|
||||||
|
|
||||||
;; For rotated or stretched shapes, the origin point we show in the menu
|
;; For rotated or stretched shapes, the origin point we show in the menu
|
||||||
|
@ -441,5 +445,3 @@
|
||||||
(tr "workspace.options.show-in-viewer")]])
|
(tr "workspace.options.show-in-viewer")]])
|
||||||
|
|
||||||
]]]))
|
]]]))
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue