mirror of
https://github.com/penpot/penpot.git
synced 2025-08-03 22:18:32 +02:00
✨ Fixed problems with masks
This commit is contained in:
parent
4c5e8f42ce
commit
7b2f0303e8
6 changed files with 75 additions and 46 deletions
|
@ -128,7 +128,7 @@
|
|||
(some? modifiers)
|
||||
(gtr/transform-shape modifiers)
|
||||
|
||||
(and (some? modifiers) (cph/group-like-shape? child))
|
||||
(cph/group-like-shape? child)
|
||||
(gtr/apply-group-modifiers objects modif-tree))))
|
||||
|
||||
(set-child-modifiers [parent [layout-line modif-tree] child]
|
||||
|
@ -226,13 +226,13 @@
|
|||
has-modifiers? (ctm/child-modifiers? modifiers)
|
||||
is-layout? (ctl/layout? parent)
|
||||
is-auto? (or (ctl/auto-height? transformed-parent) (ctl/auto-width? transformed-parent))
|
||||
is-parent? (or (cph/group-like-shape? parent) (and (cph/frame-shape? parent) (not (ctl/layout? parent))))
|
||||
is-parent? (or (cph/group-like-shape? parent) (cph/frame-shape? parent))
|
||||
|
||||
;; If the current child is inside the layout we ignore the constraints
|
||||
is-inside-layout? (ctl/inside-layout? objects parent)]
|
||||
|
||||
[(cond-> modif-tree
|
||||
(and has-modifiers? is-parent? (not root?))
|
||||
(and (not is-layout?) has-modifiers? is-parent? (not root?))
|
||||
(set-children-modifiers objects parent transformed-parent (or ignore-constraints is-inside-layout?) snap-pixel?)
|
||||
|
||||
is-layout?
|
||||
|
|
|
@ -407,17 +407,19 @@
|
|||
(apply-modifiers modifiers))))
|
||||
|
||||
(defn transform-bounds
|
||||
[points center modifiers]
|
||||
(let [transform (ctm/modifiers->transform modifiers)]
|
||||
(gco/transform-points points center transform)))
|
||||
([points modifiers]
|
||||
(transform-bounds points nil modifiers))
|
||||
|
||||
([points center modifiers]
|
||||
(let [transform (ctm/modifiers->transform modifiers)]
|
||||
(gco/transform-points points center transform))))
|
||||
|
||||
(defn transform-selrect
|
||||
[selrect modifiers]
|
||||
(let [center (gco/center-selrect selrect)]
|
||||
(-> selrect
|
||||
(gpr/rect->points)
|
||||
(transform-bounds center modifiers)
|
||||
(gpr/points->selrect))))
|
||||
(-> selrect
|
||||
(gpr/rect->points)
|
||||
(transform-bounds modifiers)
|
||||
(gpr/points->selrect)))
|
||||
|
||||
(defn transform-selrect-matrix
|
||||
[selrect mtx]
|
||||
|
@ -434,34 +436,45 @@
|
|||
(map (comp gpr/points->selrect :points transform-shape))
|
||||
(gpr/join-selrects)))
|
||||
|
||||
(declare apply-group-modifiers)
|
||||
|
||||
(defn apply-children-modifiers
|
||||
[objects modif-tree children]
|
||||
[objects modif-tree parent-modifiers children]
|
||||
(->> children
|
||||
(map (fn [child]
|
||||
(let [modifiers (get-in modif-tree [(:id child) :modifiers])
|
||||
child (transform-shape child modifiers)
|
||||
parent? (or (= :group (:type child)) (= :bool (:type child)))]
|
||||
(let [modifiers (->> (get-in modif-tree [(:id child) :modifiers])
|
||||
(ctm/add-modifiers parent-modifiers))
|
||||
child (transform-shape child modifiers)
|
||||
parent? (cph/group-like-shape? child)]
|
||||
(cond-> child
|
||||
parent?
|
||||
(apply-children-modifiers objects modif-tree)))))))
|
||||
(apply-group-modifiers objects (assoc-in modif-tree [(:id child) :modifiers] modifiers))))))))
|
||||
|
||||
(defn apply-group-modifiers
|
||||
"Apply the modifiers to the group children to calculate its selection rect"
|
||||
[parent objects modif-tree]
|
||||
[group objects modif-tree]
|
||||
|
||||
(let [children (->> (:shapes parent)
|
||||
(let [modifiers (get-in modif-tree [(:id group) :modifiers])
|
||||
children (->> (:shapes group)
|
||||
(map (d/getf objects))
|
||||
(apply-children-modifiers objects modif-tree))]
|
||||
(cond-> parent
|
||||
(cph/group-shape? parent)
|
||||
(update-group-selrect children))))
|
||||
(apply-children-modifiers objects modif-tree modifiers))]
|
||||
(cond
|
||||
(cph/mask-shape? group)
|
||||
(update-mask-selrect group children)
|
||||
|
||||
(cph/group-shape? group)
|
||||
(update-group-selrect group children)
|
||||
|
||||
:else
|
||||
group)))
|
||||
|
||||
(defn get-children-bounds
|
||||
[parent objects modif-tree]
|
||||
(let [children
|
||||
(let [modifiers (get-in modif-tree [(:id parent) :modifiers])
|
||||
children
|
||||
(->> (:shapes parent)
|
||||
(map (d/getf objects))
|
||||
(apply-children-modifiers objects modif-tree))]
|
||||
(apply-children-modifiers objects modif-tree modifiers))]
|
||||
(->> children (mapcat :points) gpr/points->rect)))
|
||||
|
||||
(defn parent-coords-rect
|
||||
|
|
|
@ -37,6 +37,10 @@
|
|||
[{:keys [type]}]
|
||||
(= type :group))
|
||||
|
||||
(defn mask-shape?
|
||||
[{:keys [type masked-group?]}]
|
||||
(and (= type :group) masked-group?))
|
||||
|
||||
(defn bool-shape?
|
||||
[{:keys [type]}]
|
||||
(= type :bool))
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
[app.common.types.pages-list :as ctpl]
|
||||
[app.common.types.shape :as cts]
|
||||
[app.common.types.shape-tree :as ctst]
|
||||
[app.common.types.shape.layout :as ctl]
|
||||
[app.common.uuid :as uuid]
|
||||
[app.config :as cfg]
|
||||
[app.main.data.comments :as dcm]
|
||||
|
@ -686,11 +687,16 @@
|
|||
shapes-to-detach
|
||||
shapes-to-reroot
|
||||
shapes-to-deroot
|
||||
ids)]
|
||||
ids)
|
||||
|
||||
layouts-to-update
|
||||
(into #{}
|
||||
(filter (partial ctl/layout? objects))
|
||||
(concat [parent-id] (cph/get-parent-ids objects parent-id)))]
|
||||
|
||||
(rx/of (dch/commit-changes changes)
|
||||
(dwco/expand-collapse parent-id)
|
||||
(dwul/update-layout-positions [parent-id]))))))
|
||||
(dwul/update-layout-positions layouts-to-update))))))
|
||||
|
||||
(defn relocate-selected-shapes
|
||||
[parent-id to-index]
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
[app.common.geom.shapes :as gsh]
|
||||
[app.common.math :as mth]
|
||||
[app.common.pages.helpers :as cph]
|
||||
[app.common.types.shape.layout :as ctl]
|
||||
[app.main.refs :as refs]
|
||||
[app.main.ui.formats :as fmt]
|
||||
[app.main.worker :as uw]
|
||||
|
@ -272,18 +273,20 @@
|
|||
frame-id (-> selected-shapes first :frame-id)
|
||||
frame (mf/deref (refs/object-by-id frame-id))
|
||||
selrect (gsh/selection-rect selected-shapes)]
|
||||
[:g.distance
|
||||
[:& shape-distance
|
||||
{:selrect selrect
|
||||
:page-id page-id
|
||||
:frame frame
|
||||
:zoom zoom
|
||||
:coord :x
|
||||
:selected selected}]
|
||||
[:& shape-distance
|
||||
{:selrect selrect
|
||||
:page-id page-id
|
||||
:frame frame
|
||||
:zoom zoom
|
||||
:coord :y
|
||||
:selected selected}]]))
|
||||
|
||||
(when-not (ctl/layout? frame)
|
||||
[:g.distance
|
||||
[:& shape-distance
|
||||
{:selrect selrect
|
||||
:page-id page-id
|
||||
:frame frame
|
||||
:zoom zoom
|
||||
:coord :x
|
||||
:selected selected}]
|
||||
[:& shape-distance
|
||||
{:selrect selrect
|
||||
:page-id page-id
|
||||
:frame frame
|
||||
:zoom zoom
|
||||
:coord :y
|
||||
:selected selected}]])))
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
[app.common.geom.shapes :as gsh]
|
||||
[app.common.pages.helpers :as cph]
|
||||
[app.common.spec :as us]
|
||||
[app.common.types.shape.layout :as ctl]
|
||||
[app.main.snap :as snap]
|
||||
[app.util.geom.snap-points :as sp]
|
||||
[beicon.core :as rx]
|
||||
|
@ -172,9 +173,11 @@
|
|||
(and (= type :layout) (= grid :square))
|
||||
(= type :guide))))
|
||||
|
||||
shapes (if drawing [drawing] shapes)]
|
||||
[:& snap-feedback {:shapes shapes
|
||||
:page-id page-id
|
||||
:remove-snap? remove-snap?
|
||||
:zoom zoom}]))
|
||||
shapes (if drawing [drawing] shapes)
|
||||
frame-id (snap/snap-frame-id shapes)]
|
||||
(when-not (ctl/layout? objects frame-id)
|
||||
[:& snap-feedback {:shapes shapes
|
||||
:page-id page-id
|
||||
:remove-snap? remove-snap?
|
||||
:zoom zoom}])))
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue