mirror of
https://github.com/penpot/penpot.git
synced 2025-01-10 17:00:36 -05:00
🐛 Fix constraints detection on rotated structures
This commit is contained in:
parent
71759386c5
commit
d89a4a1218
2 changed files with 45 additions and 17 deletions
|
@ -368,14 +368,27 @@
|
||||||
(dissoc :modifiers)))
|
(dissoc :modifiers)))
|
||||||
shape))))
|
shape))))
|
||||||
|
|
||||||
|
|
||||||
(defn calc-child-modifiers
|
(defn calc-child-modifiers
|
||||||
[parent transformed-parent child parent-modifiers]
|
"Given the modifiers to apply to the parent, calculate the corresponding
|
||||||
|
modifiers for the child, depending on the child constraints."
|
||||||
|
[parent child parent-modifiers]
|
||||||
(let [parent-rect (:selrect parent)
|
(let [parent-rect (:selrect parent)
|
||||||
transformed-parent-rect (:selrect transformed-parent)
|
|
||||||
child-rect (:selrect child)
|
child-rect (:selrect child)
|
||||||
|
|
||||||
origin (:resize-origin parent-modifiers)
|
; If the modifiers include a resize vector, apply it to the parent,
|
||||||
|
; and then calculate the displacement of the side opposite to the
|
||||||
|
; origin of the vector.
|
||||||
|
origin (-> (:resize-origin parent-modifiers)
|
||||||
|
((d/nilf transform-point-center)
|
||||||
|
(gco/center-shape parent)
|
||||||
|
(:resize-transform-inverse parent-modifiers (gmt/matrix))))
|
||||||
|
|
||||||
|
transformed-parent-rect (-> parent-rect
|
||||||
|
(gpr/rect->points)
|
||||||
|
(transform-points
|
||||||
|
origin
|
||||||
|
(gmt/scale-matrix (get parent-modifiers :resize-vector (gpt/point 1 1))))
|
||||||
|
(gpr/points->selrect))
|
||||||
|
|
||||||
orig-h (when origin
|
orig-h (when origin
|
||||||
(cond
|
(cond
|
||||||
|
@ -407,6 +420,8 @@
|
||||||
|
|
||||||
:else 0))
|
:else 0))
|
||||||
|
|
||||||
|
;; Calculate the modifiers in the horizontal and vertical directions
|
||||||
|
;; depending on the constraints, and the origin of the resize vector.
|
||||||
constraints-h (get child :constraints-h (spec/default-constraints-h child))
|
constraints-h (get child :constraints-h (spec/default-constraints-h child))
|
||||||
constraints-v (get child :constraints-v (spec/default-constraints-v child))
|
constraints-v (get child :constraints-v (spec/default-constraints-v child))
|
||||||
|
|
||||||
|
@ -423,13 +438,19 @@
|
||||||
|
|
||||||
:leftright
|
:leftright
|
||||||
(cond (= orig-h :left)
|
(cond (= orig-h :left)
|
||||||
{:resize-origin (gpt/point (:x1 child-rect) (:y1 child-rect))
|
{:resize-origin (-> (gpt/point (:x1 child-rect) (:y1 child-rect))
|
||||||
|
(transform-point-center
|
||||||
|
(gco/center-shape child)
|
||||||
|
(:transform child (gmt/matrix))))
|
||||||
:resize-vector (gpt/point (/ (+ (:width child-rect) delta-h)
|
:resize-vector (gpt/point (/ (+ (:width child-rect) delta-h)
|
||||||
(:width child-rect))
|
(:width child-rect))
|
||||||
1)}
|
1)}
|
||||||
|
|
||||||
(= orig-h :right)
|
(= orig-h :right)
|
||||||
{:resize-origin (gpt/point (:x2 child-rect) (:y1 child-rect))
|
{:resize-origin (-> (gpt/point (:x2 child-rect) (:y1 child-rect))
|
||||||
|
(transform-point-center
|
||||||
|
(gco/center-shape child)
|
||||||
|
(:transform child (gmt/matrix))))
|
||||||
:resize-vector (gpt/point (/ (- (:width child-rect) delta-h)
|
:resize-vector (gpt/point (/ (- (:width child-rect) delta-h)
|
||||||
(:width child-rect))
|
(:width child-rect))
|
||||||
1)}
|
1)}
|
||||||
|
@ -460,13 +481,19 @@
|
||||||
|
|
||||||
:topbottom
|
:topbottom
|
||||||
(cond (= orig-v :top)
|
(cond (= orig-v :top)
|
||||||
{:resize-origin (gpt/point (:x1 child-rect) (:y1 child-rect))
|
{:resize-origin (-> (gpt/point (:x1 child-rect) (:y1 child-rect))
|
||||||
|
(transform-point-center
|
||||||
|
(gco/center-shape child)
|
||||||
|
(:transform child (gmt/matrix))))
|
||||||
:resize-vector (gpt/point 1
|
:resize-vector (gpt/point 1
|
||||||
(/ (+ (:height child-rect) delta-v)
|
(/ (+ (:height child-rect) delta-v)
|
||||||
(:height child-rect)))}
|
(:height child-rect)))}
|
||||||
|
|
||||||
(= orig-v :bottom)
|
(= orig-v :bottom)
|
||||||
{:resize-origin (gpt/point (:x1 child-rect) (:y2 child-rect))
|
{:resize-origin (-> (gpt/point (:x1 child-rect) (:y2 child-rect))
|
||||||
|
(transform-point-center
|
||||||
|
(gco/center-shape child)
|
||||||
|
(:transform child (gmt/matrix))))
|
||||||
:resize-vector (gpt/point 1
|
:resize-vector (gpt/point 1
|
||||||
(/ (- (:height child-rect) delta-v)
|
(/ (- (:height child-rect) delta-v)
|
||||||
(:height child-rect)))}
|
(:height child-rect)))}
|
||||||
|
@ -487,18 +514,25 @@
|
||||||
(cond-> {}
|
(cond-> {}
|
||||||
(or (:displacement modifiers-h) (:displacement modifiers-v))
|
(or (:displacement modifiers-h) (:displacement modifiers-v))
|
||||||
(assoc :displacement (gmt/translate-matrix
|
(assoc :displacement (gmt/translate-matrix
|
||||||
(gpt/point (get (:displacement modifiers-h) :x 0)
|
(-> (gpt/point (get (:displacement modifiers-h) :x 0)
|
||||||
(get (:displacement modifiers-v) :y 0))))
|
(get (:displacement modifiers-v) :y 0))
|
||||||
|
(gpt/transform
|
||||||
|
(:resize-transform parent-modifiers (gmt/matrix))))))
|
||||||
|
|
||||||
(or (:resize-vector modifiers-h) (:resize-vector modifiers-v))
|
(or (:resize-vector modifiers-h) (:resize-vector modifiers-v))
|
||||||
(assoc :resize-origin (or (:resize-origin modifiers-h) ;; we assume that the origin is the same
|
(assoc :resize-origin (or (:resize-origin modifiers-h) ;; we assume that the origin is the same
|
||||||
(:resize-origin modifiers-v)) ;; in any direction
|
(:resize-origin modifiers-v)) ;; in any direction
|
||||||
:resize-vector (gpt/point (get (:resize-vector modifiers-h) :x 1)
|
:resize-vector (gpt/point (get (:resize-vector modifiers-h) :x 1)
|
||||||
(get (:resize-vector modifiers-v) :y 1)))
|
(get (:resize-vector modifiers-v) :y 1)))
|
||||||
|
|
||||||
(:displacement parent-modifiers)
|
(:displacement parent-modifiers)
|
||||||
(update :displacement #(if (nil? %)
|
(update :displacement #(if (nil? %)
|
||||||
(:displacement parent-modifiers)
|
(:displacement parent-modifiers)
|
||||||
(gmt/add-translate % (:displacement parent-modifiers)))))))
|
(gmt/add-translate % (:displacement parent-modifiers))))
|
||||||
|
|
||||||
|
(:resize-transform parent-modifiers)
|
||||||
|
(assoc :resize-transform (:resize-transform parent-modifiers)
|
||||||
|
:resize-transform-inverse (:resize-transform-inverse parent-modifiers)))))
|
||||||
|
|
||||||
(defn update-group-viewbox
|
(defn update-group-viewbox
|
||||||
"Updates the viewbox for groups imported from SVG's"
|
"Updates the viewbox for groups imported from SVG's"
|
||||||
|
|
|
@ -471,14 +471,8 @@
|
||||||
|
|
||||||
modifiers (assoc modifiers :ignore-geometry? ignore-geometry?)
|
modifiers (assoc modifiers :ignore-geometry? ignore-geometry?)
|
||||||
|
|
||||||
resized-shape (when (seq children) ; <- don't calculate it if not needed
|
|
||||||
(gsh/transform-shape
|
|
||||||
(assoc shape :modifiers (select-keys modifiers
|
|
||||||
[:resize-origin
|
|
||||||
:resize-vector]))))
|
|
||||||
set-child (fn [modif-tree child]
|
set-child (fn [modif-tree child]
|
||||||
(let [child-modifiers (gsh/calc-child-modifiers shape
|
(let [child-modifiers (gsh/calc-child-modifiers shape
|
||||||
resized-shape
|
|
||||||
child
|
child
|
||||||
modifiers)]
|
modifiers)]
|
||||||
(set-modifiers-recursive modif-tree
|
(set-modifiers-recursive modif-tree
|
||||||
|
|
Loading…
Reference in a new issue