mirror of
https://github.com/penpot/penpot.git
synced 2025-03-13 16:21:57 -05:00
✨ Fixes problem with bool shapes
This commit is contained in:
parent
32756db1c1
commit
afa6a97693
7 changed files with 54 additions and 33 deletions
|
@ -160,6 +160,7 @@
|
|||
(dm/export gpr/join-selrects)
|
||||
(dm/export gpr/contains-selrect?)
|
||||
(dm/export gpr/contains-point?)
|
||||
(dm/export gpr/close-selrect?)
|
||||
|
||||
(dm/export gtr/move)
|
||||
(dm/export gtr/absolute-move)
|
||||
|
@ -170,6 +171,7 @@
|
|||
(dm/export gtr/calculate-adjust-matrix)
|
||||
(dm/export gtr/update-group-selrect)
|
||||
(dm/export gtr/update-mask-selrect)
|
||||
(dm/export gtr/update-bool-selrect)
|
||||
(dm/export gtr/transform-shape)
|
||||
(dm/export gtr/transform-selrect)
|
||||
(dm/export gtr/transform-selrect-matrix)
|
||||
|
@ -194,7 +196,7 @@
|
|||
(dm/export gin/rect-contains-shape?)
|
||||
|
||||
;; Bool
|
||||
(dm/export gsb/update-bool-selrect)
|
||||
|
||||
(dm/export gsb/calc-bool-content)
|
||||
|
||||
;; Constraints
|
||||
|
|
|
@ -7,8 +7,6 @@
|
|||
(ns app.common.geom.shapes.bool
|
||||
(:require
|
||||
[app.common.data :as d]
|
||||
[app.common.geom.shapes.path :as gsp]
|
||||
[app.common.geom.shapes.transforms :as gtr]
|
||||
[app.common.path.bool :as pb]
|
||||
[app.common.path.shapes-to-path :as stp]))
|
||||
|
||||
|
@ -25,17 +23,5 @@
|
|||
(into [] extract-content-xf (:shapes shape))]
|
||||
(pb/content-bool (:bool-type shape) shapes-content)))
|
||||
|
||||
(defn update-bool-selrect
|
||||
"Calculates the selrect+points for the boolean shape"
|
||||
[shape children objects]
|
||||
|
||||
(let [bool-content (calc-bool-content shape objects)
|
||||
shape (assoc shape :bool-content bool-content)
|
||||
[points selrect] (gsp/content->points+selrect shape bool-content)]
|
||||
|
||||
(if (and (some? selrect) (d/not-empty? points))
|
||||
(-> shape
|
||||
(assoc :selrect selrect)
|
||||
(assoc :points points))
|
||||
(gtr/update-group-selrect shape children))))
|
||||
|
||||
|
|
|
@ -133,13 +133,17 @@
|
|||
[modif-tree objects parent]
|
||||
|
||||
(letfn [(apply-modifiers [modif-tree child]
|
||||
(let [modifiers (dm/get-in modif-tree [(:id child) :modifiers])]
|
||||
(cond-> child
|
||||
(and (not (cph/group-shape? child)) (some? modifiers))
|
||||
(gtr/transform-shape modifiers)
|
||||
(let [modifiers (-> (dm/get-in modif-tree [(:id child) :modifiers])
|
||||
(ctm/select-geometry))]
|
||||
(cond
|
||||
(cph/group-like-shape? child)
|
||||
(gtr/apply-group-modifiers child objects modif-tree)
|
||||
|
||||
(cph/group-shape? child)
|
||||
(gtr/apply-group-modifiers objects modif-tree))))
|
||||
(some? modifiers)
|
||||
(gtr/transform-shape child modifiers)
|
||||
|
||||
:else
|
||||
child)))
|
||||
|
||||
(set-child-modifiers [parent [layout-line modif-tree] child]
|
||||
(let [[modifiers layout-line]
|
||||
|
@ -208,7 +212,8 @@
|
|||
[objects ignore-constraints [modif-tree autolayouts] parent]
|
||||
(let [parent-id (:id parent)
|
||||
root? (= uuid/zero parent-id)
|
||||
modifiers (dm/get-in modif-tree [parent-id :modifiers])
|
||||
modifiers (-> (dm/get-in modif-tree [parent-id :modifiers])
|
||||
(ctm/select-geometry))
|
||||
transformed-parent (gtr/transform-shape parent modifiers)
|
||||
|
||||
has-modifiers? (ctm/child-modifiers? modifiers)
|
||||
|
@ -233,10 +238,9 @@
|
|||
(defn- apply-structure-modifiers
|
||||
[objects modif-tree]
|
||||
(letfn [(apply-shape [objects [id {:keys [modifiers]}]]
|
||||
(if (ctm/has-structure? modifiers)
|
||||
(let [shape (get objects id)]
|
||||
(update objects id ctm/apply-structure-modifiers modifiers))
|
||||
objects))]
|
||||
(cond-> objects
|
||||
(ctm/has-structure? modifiers)
|
||||
(update id ctm/apply-structure-modifiers modifiers)))]
|
||||
(reduce apply-shape objects modif-tree)))
|
||||
|
||||
(defn- apply-partial-objects-modifiers
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
[app.common.data.macros :as dm]
|
||||
[app.common.geom.matrix :as gmt]
|
||||
[app.common.geom.point :as gpt]
|
||||
[app.common.geom.shapes.bool :as gshb]
|
||||
[app.common.geom.shapes.common :as gco]
|
||||
[app.common.geom.shapes.path :as gpa]
|
||||
[app.common.geom.shapes.rect :as gpr]
|
||||
|
@ -408,6 +409,20 @@
|
|||
(assoc :flip-x (-> mask :flip-x))
|
||||
(assoc :flip-y (-> mask :flip-y)))))
|
||||
|
||||
(defn update-bool-selrect
|
||||
"Calculates the selrect+points for the boolean shape"
|
||||
[shape children objects]
|
||||
|
||||
(let [bool-content (gshb/calc-bool-content shape objects)
|
||||
shape (assoc shape :bool-content bool-content)
|
||||
[points selrect] (gpa/content->points+selrect shape bool-content)]
|
||||
|
||||
(if (and (some? selrect) (d/not-empty? points))
|
||||
(-> shape
|
||||
(assoc :selrect selrect)
|
||||
(assoc :points points))
|
||||
(update-group-selrect shape children))))
|
||||
|
||||
(defn transform-shape
|
||||
([shape]
|
||||
(let [modifiers (:modifiers shape)]
|
||||
|
@ -513,6 +528,9 @@
|
|||
(cph/mask-shape? group)
|
||||
(update-mask-selrect group children)
|
||||
|
||||
(cph/bool-shape? group)
|
||||
(transform-shape group modifiers)
|
||||
|
||||
(cph/group-shape? group)
|
||||
(update-group-selrect group children)
|
||||
|
||||
|
|
|
@ -11,7 +11,6 @@
|
|||
[app.common.data.macros :as dm]
|
||||
[app.common.exceptions :as ex]
|
||||
[app.common.geom.shapes :as gsh]
|
||||
[app.common.geom.shapes.bool :as gshb]
|
||||
[app.common.math :as mth]
|
||||
[app.common.pages.common :refer [component-sync-attrs]]
|
||||
[app.common.pages.helpers :as cph]
|
||||
|
@ -170,7 +169,7 @@
|
|||
group
|
||||
|
||||
(= :bool (:type group))
|
||||
(gshb/update-bool-selrect group children objects)
|
||||
(gsh/update-bool-selrect group children objects)
|
||||
|
||||
(:masked-group? group)
|
||||
(set-mask-selrect group children)
|
||||
|
|
|
@ -12,8 +12,6 @@
|
|||
[app.common.geom.matrix :as gmt]
|
||||
[app.common.geom.point :as gpt]
|
||||
[app.common.geom.shapes :as gsh]
|
||||
[app.common.geom.shapes.bool :as gshb]
|
||||
[app.common.geom.shapes.rect :as gshr]
|
||||
[app.common.math :as mth]
|
||||
[app.common.pages :as cp]
|
||||
[app.common.pages.helpers :as cph]
|
||||
|
@ -419,7 +417,7 @@
|
|||
(every? #(apply gpt/close? %) (d/zip old-val new-val))
|
||||
|
||||
(= attr :selrect)
|
||||
(gshr/close-selrect? old-val new-val)
|
||||
(gsh/close-selrect? old-val new-val)
|
||||
|
||||
:else
|
||||
(= old-val new-val))]
|
||||
|
@ -438,7 +436,7 @@
|
|||
nil ;; so it does not need resize
|
||||
|
||||
(= (:type parent) :bool)
|
||||
(gshb/update-bool-selrect parent children objects)
|
||||
(gsh/update-bool-selrect parent children objects)
|
||||
|
||||
(= (:type parent) :group)
|
||||
(if (:masked-group? parent)
|
||||
|
|
|
@ -150,6 +150,19 @@
|
|||
child-set (set (get-in objects [target-frame :shapes]))
|
||||
layout? (ctl/layout? objects target-frame)
|
||||
|
||||
set-parent-ids
|
||||
(fn [modif-tree shapes target-frame]
|
||||
(reduce
|
||||
(fn [modif-tree id]
|
||||
(update-in
|
||||
modif-tree
|
||||
[id :modifiers]
|
||||
#(-> %
|
||||
(ctm/change-property :frame-id target-frame)
|
||||
(ctm/change-property :parent-id target-frame))))
|
||||
modif-tree
|
||||
shapes))
|
||||
|
||||
update-frame-modifiers
|
||||
(fn [modif-tree [original-frame shapes]]
|
||||
(let [shapes (->> shapes (d/removev #(= target-frame %)))
|
||||
|
@ -160,7 +173,8 @@
|
|||
(cond-> modif-tree
|
||||
(not= original-frame target-frame)
|
||||
(-> (update-in [original-frame :modifiers] ctm/remove-children shapes)
|
||||
(update-in [target-frame :modifiers] ctm/add-children shapes drop-index))
|
||||
(update-in [target-frame :modifiers] ctm/add-children shapes drop-index)
|
||||
(set-parent-ids shapes target-frame))
|
||||
|
||||
(and layout? (= original-frame target-frame))
|
||||
(update-in [target-frame :modifiers] ctm/add-children shapes drop-index))))]
|
||||
|
|
Loading…
Add table
Reference in a new issue