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

🐛 Fix problem with fill width/height and alignment

This commit is contained in:
alonso.torres 2023-05-19 15:33:39 +02:00
parent b3b984d339
commit b0136fef29

View file

@ -96,18 +96,21 @@
fill-height fill-height
(when (ctl/fill-height? child) (when (ctl/fill-height? child)
(calc-fill-height-data parent transform transform-inverse child child-origin child-height cell-bounds))] (calc-fill-height-data parent transform transform-inverse child child-origin child-height cell-bounds))
child-width (or (:width fill-width) child-width)
child-height (or (:height fill-height) child-height)]
[child-width
child-height
(-> (ctm/empty) (-> (ctm/empty)
(cond-> fill-width (ctm/add-modifiers (:modifiers fill-width))) (cond-> fill-width (ctm/add-modifiers (:modifiers fill-width)))
(cond-> fill-height (ctm/add-modifiers (:modifiers fill-height)))))) (cond-> fill-height (ctm/add-modifiers (:modifiers fill-height))))]))
(defn child-modifiers
[parent parent-bounds child child-bounds layout-data cell-data]
(defn child-position-delta
[parent child-bounds child-width child-height layout-data cell-data]
(let [cell-bounds (cell-bounds layout-data cell-data) (let [cell-bounds (cell-bounds layout-data cell-data)
child-origin (gpo/origin child-bounds)
fill-modifiers (fill-modifiers parent parent-bounds child child-bounds layout-data cell-data)
align (:layout-align-items parent) align (:layout-align-items parent)
justify (:layout-justify-items parent) justify (:layout-justify-items parent)
@ -120,39 +123,46 @@
align (or align-self align) align (or align-self align)
justify (or justify-self justify) justify (or justify-self justify)
position-delta (gpt/point) origin-h (gpo/project-point cell-bounds :h child-origin)
origin-v (gpo/project-point cell-bounds :v child-origin)
hv (partial gpo/start-hv cell-bounds)
vv (partial gpo/start-vv cell-bounds)
;; Adjust alignment/justify ;; Adjust alignment/justify
[from-h to-h] [from-h to-h]
(case justify (case justify
:end :end
[(gpo/project-point cell-bounds :h (nth child-bounds 1)) [(gpt/add origin-h (hv child-width))
(nth cell-bounds 1)] (nth cell-bounds 1)]
:center :center
[(gpo/project-point cell-bounds :h (gpo/center child-bounds)) [(gpt/add origin-h (hv (/ child-width 2)))
(gpo/project-point cell-bounds :h (gpo/center cell-bounds))] (gpo/project-point cell-bounds :h (gpo/center cell-bounds))]
[(gpo/project-point cell-bounds :h (first child-bounds)) [origin-h (first cell-bounds)])
(first cell-bounds)])
[from-v to-v] [from-v to-v]
(case align (case align
:end :end
[(gpo/project-point cell-bounds :v (nth child-bounds 3)) [(gpt/add origin-v (vv child-height))
(nth cell-bounds 3)] (nth cell-bounds 3)]
:center :center
[(gpo/project-point cell-bounds :v (gpo/center child-bounds)) [(gpt/add origin-v (vv (/ child-height 2)))
(gpo/project-point cell-bounds :v (gpo/center cell-bounds))] (gpo/project-point cell-bounds :v (gpo/center cell-bounds))]
[(gpo/project-point cell-bounds :v (first child-bounds)) [origin-v (first cell-bounds)])]
(first cell-bounds)]) (-> (gpt/point)
position-delta
(-> position-delta
(gpt/add (gpt/to-vec from-h to-h)) (gpt/add (gpt/to-vec from-h to-h))
(gpt/add (gpt/to-vec from-v to-v)))] (gpt/add (gpt/to-vec from-v to-v)))))
(defn child-modifiers
[parent parent-bounds child child-bounds layout-data cell-data]
(let [[child-width child-height fill-modifiers]
(fill-modifiers parent parent-bounds child child-bounds layout-data cell-data)
position-delta (child-position-delta parent child-bounds child-width child-height layout-data cell-data)]
(cond-> (ctm/empty) (cond-> (ctm/empty)
(not (ctl/layout-absolute? child)) (not (ctl/layout-absolute? child))