Fix problems with flipped layouts

This commit is contained in:
alonso.torres 2022-11-07 17:26:28 +01:00
parent a2e26210d1
commit e61e76a074
10 changed files with 84 additions and 24 deletions

View file

@ -9,6 +9,7 @@
[app.common.geom.point :as gpt]
[app.common.geom.shapes.common :as gco]
[app.common.geom.shapes.intersect :as gsi]
[app.common.geom.shapes.points :as gpo]
[app.common.geom.shapes.rect :as gre]
[app.common.geom.shapes.transforms :as gst]
[app.common.math :as mth]
@ -235,9 +236,7 @@
child-bb-after (gst/parent-coords-rect transformed-child transformed-parent)
scale-x (/ (:width child-bb-before) (:width child-bb-after))
scale-y (/ (:height child-bb-before) (:height child-bb-after))
;; TODO LAYOUT: Is the first always the origin?
resize-origin (-> transformed-parent :points first)]
resize-origin (-> transformed-parent :points gpo/origin)]
(cond-> modifiers
(not= :scale constraints-h)

View file

@ -22,13 +22,8 @@
[pad-top pad-right pad-bottom pad-left]
(if (= layout-padding-type :multiple)
[pad-top pad-right pad-bottom pad-left]
[pad-top pad-top pad-top pad-top])
;; Normalize the points to remove flips
;; TODO LAYOUT: Need function to normalize the points
points (gst/parent-coords-points shape shape)]
(gpo/pad-points points pad-top pad-right pad-bottom pad-left)))
[pad-top pad-top pad-top pad-top])]
(gpo/pad-points (:points shape) pad-top pad-right pad-bottom pad-left)))
(defn init-layout-lines
"Calculates the lines basic data and accumulated values. The positions will be calculated in a different operation"
@ -312,5 +307,6 @@
(mapv (partial add-children-resizes shape)))]
{:layout-lines layout-lines
:layout-bounds layout-bounds
:reverse? reverse?}))

View file

@ -22,8 +22,7 @@
child-bb-after (gst/parent-coords-rect transformed-child transformed-parent)
scale-x (/ (:width child-bb-before) (:width child-bb-after))
scale-y (/ (:height child-bb-before) (:height child-bb-after))
resize-origin (-> transformed-parent :points first) ;; TODO LAYOUT: IS always the origin
resize-origin (-> transformed-parent :points gpo/origin)
resize-vector (gpt/point scale-x scale-y)]
(-> modifiers
(ctm/select-child-modifiers)

View file

@ -249,6 +249,16 @@
(some? margin-y)
(gpt/add (vv margin-y)))
;; Fix position when layout is flipped
corner-p
(cond-> corner-p
(:flip-x parent)
(gpt/add (hv child-width))
(:flip-y parent)
(gpt/add (vv child-height)))
next-p
(cond-> start-p
row?

View file

@ -311,7 +311,6 @@
(cond-> (some? selrect)
(assoc :selrect selrect))
;; TODO LAYOUT: Make sure the order of points is alright
(cond-> (d/not-empty? points)
(assoc :points points))
(assoc :rotation rotation))))

View file

@ -196,13 +196,17 @@
(defn rotation-modifiers
[shape center angle]
(let [shape-center (gco/center-shape shape)
rotation (-> (gmt/matrix)
(gmt/rotate angle center)
(gmt/rotate (- angle) shape-center))]
;; Translation caused by the rotation
move-vec
(gpt/transform
(gpt/point 0 0)
(-> (gmt/matrix)
(gmt/rotate angle center)
(gmt/rotate (- angle) shape-center)))]
(-> (empty)
(rotation shape-center angle)
(move (gpt/transform (gpt/point 0 0) rotation)))))
(move move-vec))))
(defn remove-children-modifiers
[shapes]