0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-04-05 03:21:26 -05:00

Improved modifiers lens

This commit is contained in:
alonso.torres 2023-01-03 16:58:10 +01:00
parent d5ab0eea1a
commit 98698cf2db
5 changed files with 41 additions and 37 deletions

View file

@ -100,15 +100,13 @@
(and (= :frame (:type shape)) (= :flex (:layout shape)))))
(defn layout-child? [objects shape]
(let [parent-id (:parent-id shape)
parent (get objects parent-id)]
(layout? parent)))
(let [frame-id (:frame-id shape)
frame (get objects frame-id)]
(layout? frame)))
(defn layout-child-id? [objects id]
(let [shape (get objects id)
parent-id (:parent-id shape)
parent (get objects parent-id)]
(layout? parent)))
(let [shape (get objects id)]
(layout-child? objects shape)))
(defn inside-layout?
"Check if the shape is inside a layout"

View file

@ -37,19 +37,21 @@
(assoc :x (- (:x point) (* sx (- dy dx)))))))
(defn resize-shape [{:keys [x y width height] :as shape} initial point lock?]
(let [draw-rect (gsh/make-rect initial (cond-> point lock? (adjust-ratio initial)))
shape-rect (gsh/make-rect x y width height)
(if (and (some? x) (some? y) (some? width) (some? height))
(let [draw-rect (gsh/make-rect initial (cond-> point lock? (adjust-ratio initial)))
shape-rect (gsh/make-rect x y width height)
scalev (gpt/point (/ (:width draw-rect) (:width shape-rect))
(/ (:height draw-rect) (:height shape-rect)))
scalev (gpt/point (/ (:width draw-rect) (:width shape-rect))
(/ (:height draw-rect) (:height shape-rect)))
movev (gpt/to-vec (gpt/point shape-rect) (gpt/point draw-rect))]
movev (gpt/to-vec (gpt/point shape-rect) (gpt/point draw-rect))]
(-> shape
(assoc :click-draw? false)
(gsh/transform-shape (-> (ctm/empty)
(ctm/resize scalev (gpt/point x y))
(ctm/move movev))))))
(-> shape
(assoc :click-draw? false)
(gsh/transform-shape (-> (ctm/empty)
(ctm/resize scalev (gpt/point x y))
(ctm/move movev)))))
shape))
(defn update-drawing [state initial point lock?]
(update-in state [:workspace-drawing :object] resize-shape initial point lock?))

View file

@ -219,6 +219,7 @@
(rx/concat
(->> ms/mouse-position
(rx/filter some?)
(rx/with-latest-from ms/mouse-position-shift ms/mouse-position-alt)
(rx/map normalize-proportion-lock)
(rx/switch-map (fn [[point _ _ :as current]]

View file

@ -324,11 +324,7 @@
(l/derived :workspace-editor-state st/state))
(def workspace-modifiers
(l/derived :workspace-modifiers st/state))
(defn workspace-modifiers-by-id
[ids]
(l/derived #(select-keys % ids) workspace-modifiers))
(l/derived :workspace-modifiers st/state =))
(def workspace-modifiers-with-objects
(l/derived
@ -340,20 +336,29 @@
(and (= (:modifiers a) (:modifiers b))
(identical? (:objects a) (:objects b))))))
(defn workspace-modifiers-by-frame-id
[frame-id]
(def workspace-frame-modifiers
(l/derived
(fn [{:keys [modifiers objects]}]
(let [keys (->> modifiers
(keys)
(filter (fn [id]
(let [shape (get objects id)]
(or (= frame-id id)
(and (= frame-id (:frame-id shape))
(not (= :frame (:type shape)))))))))]
(select-keys modifiers keys)))
workspace-modifiers-with-objects
=))
(->> modifiers
(reduce
(fn [result [id modifiers]]
(let [shape (get objects id)
frame-id (:frame-id shape)]
(cond
(cph/frame-shape? shape)
(assoc-in result [id id] modifiers)
(some? frame-id)
(assoc-in result [frame-id id] modifiers)
:else
result)))
{})))
workspace-modifiers-with-objects))
(defn workspace-modifiers-by-frame-id
[frame-id]
(l/derived #(get % frame-id) workspace-frame-modifiers =))
(defn select-bool-children [id]
(l/derived (partial wsh/select-bool-children id) st/state =))

View file

@ -110,9 +110,7 @@
:circle [:> circle-wrapper opts]
:svg-raw [:> svg-raw-wrapper opts]
:bool [:> bool-wrapper opts]
;; Only used when drawing a new frame.
:frame [:> nested-frame-wrapper opts]
:frame [:> nested-frame-wrapper opts]
nil)])))