0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-03-16 01:31:22 -05:00

🐛 Fix problems with content between/around and auto-width

This commit is contained in:
alonso.torres 2023-01-26 12:55:33 +01:00
parent 1984109436
commit 38fe6e856a
3 changed files with 32 additions and 16 deletions

View file

@ -87,16 +87,19 @@
(let [parent-id (:id parent) (let [parent-id (:id parent)
parent-bounds @(get bounds parent-id) parent-bounds @(get bounds parent-id)
row? (ctl/row? parent) row? (ctl/row? parent)
col? (ctl/col? parent) col? (ctl/col? parent)
space-around? (ctl/space-around? parent) space-around? (ctl/space-around? parent)
content-around? (ctl/content-around? parent)
[layout-gap-row layout-gap-col] (ctl/gaps parent) [layout-gap-row layout-gap-col] (ctl/gaps parent)
row-pad (if (and col? space-around?) row-pad (if (or (and col? space-around?)
(and row? content-around?))
layout-gap-row layout-gap-row
0) 0)
col-pad (if (and row? space-around?) col-pad (if (or(and row? space-around?)
(and col? content-around?))
layout-gap-col layout-gap-col
0) 0)

View file

@ -152,6 +152,8 @@
(let [row? (ctl/row? parent) (let [row? (ctl/row? parent)
col? (ctl/col? parent) col? (ctl/col? parent)
auto-width? (ctl/auto-width? parent)
auto-height? (ctl/auto-height? parent)
[layout-gap-row layout-gap-col] (ctl/gaps parent) [layout-gap-row layout-gap-col] (ctl/gaps parent)
@ -186,12 +188,12 @@
;; When align-items is stretch we need to adjust the main axis size to grow for the full content ;; When align-items is stretch we need to adjust the main axis size to grow for the full content
stretch-width-fix stretch-width-fix
(if (and col? (ctl/content-stretch? parent)) (if (and col? (ctl/content-stretch? parent) (not auto-width?))
(/ (- layout-width (* layout-gap-col (dec num-lines)) total-max-width) num-lines) (/ (- layout-width (* layout-gap-col (dec num-lines)) total-max-width) num-lines)
0) 0)
stretch-height-fix stretch-height-fix
(if (and row? (ctl/content-stretch? parent)) (if (and row? (ctl/content-stretch? parent) (not auto-height?))
(/ (- layout-height (* layout-gap-row (dec num-lines)) total-max-height) num-lines) (/ (- layout-height (* layout-gap-row (dec num-lines)) total-max-height) num-lines)
0) 0)

View file

@ -43,7 +43,7 @@
(gpt/add (vv free-height-gap)) (gpt/add (vv free-height-gap))
around? around?
(gpt/add (vv (/ free-height (inc num-lines))))) (gpt/add (vv (max lines-gap-row (/ free-height (inc num-lines))))))
col? col?
(cond-> center? (cond-> center?
@ -53,7 +53,7 @@
(gpt/add (hv free-width-gap)) (gpt/add (hv free-width-gap))
around? around?
(gpt/add (hv (/ free-width (inc num-lines)))))))) (gpt/add (hv (max lines-gap-col (/ free-width (inc num-lines)))))))))
(defn get-next-line (defn get-next-line
[parent layout-bounds {:keys [line-width line-height]} base-p total-width total-height num-lines] [parent layout-bounds {:keys [line-width line-height]} base-p total-width total-height num-lines]
@ -63,6 +63,9 @@
row? (ctl/row? parent) row? (ctl/row? parent)
col? (ctl/col? parent) col? (ctl/col? parent)
auto-width? (ctl/auto-width? parent)
auto-height? (ctl/auto-height? parent)
[layout-gap-row layout-gap-col] (ctl/gaps parent) [layout-gap-row layout-gap-col] (ctl/gaps parent)
hv #(gpo/start-hv layout-bounds %) hv #(gpo/start-hv layout-bounds %)
@ -75,8 +78,11 @@
free-width (- layout-width total-width) free-width (- layout-width total-width)
free-height (- layout-height total-height) free-height (- layout-height total-height)
line-gap-row line-gap-col
(cond (cond
auto-width?
layout-gap-col
stretch? stretch?
(/ free-width num-lines) (/ free-width num-lines)
@ -89,8 +95,11 @@
:else :else
layout-gap-col) layout-gap-col)
line-gap-col line-gap-row
(cond (cond
auto-height?
layout-gap-row
stretch? stretch?
(/ free-height num-lines) (/ free-height num-lines)
@ -105,10 +114,10 @@
(cond-> base-p (cond-> base-p
row? row?
(gpt/add (vv (+ line-height (max layout-gap-row line-gap-col)))) (gpt/add (vv (+ line-height (max layout-gap-row line-gap-row))))
col? col?
(gpt/add (hv (+ line-width (max layout-gap-col line-gap-row))))))) (gpt/add (hv (+ line-width (max layout-gap-col line-gap-col)))))))
(defn get-start-line (defn get-start-line
"Cross axis line. It's position is fixed along the different lines" "Cross axis line. It's position is fixed along the different lines"
@ -126,18 +135,20 @@
v-center? (ctl/v-center? parent) v-center? (ctl/v-center? parent)
v-end? (ctl/v-end? parent) v-end? (ctl/v-end? parent)
content-stretch? (ctl/content-stretch? parent) content-stretch? (ctl/content-stretch? parent)
auto-width? (ctl/auto-width? parent)
auto-height? (ctl/auto-height? parent)
hv (partial gpo/start-hv layout-bounds) hv (partial gpo/start-hv layout-bounds)
vv (partial gpo/start-vv layout-bounds) vv (partial gpo/start-vv layout-bounds)
children-gap-width (* layout-gap-col (dec num-children)) children-gap-width (* layout-gap-col (dec num-children))
children-gap-height (* layout-gap-row (dec num-children)) children-gap-height (* layout-gap-row (dec num-children))
line-height line-height
(if (and row? content-stretch?) (if (and row? content-stretch? (not auto-height?))
(+ line-height (/ (- layout-height total-height) num-lines)) (+ line-height (/ (- layout-height total-height) num-lines))
line-height) line-height)
line-width line-width
(if (and col? content-stretch?) (if (and col? content-stretch? (not auto-width?))
(+ line-width (/ (- layout-width total-width) num-lines)) (+ line-width (/ (- layout-width total-width) num-lines))
line-width) line-width)
@ -263,7 +274,7 @@
col? col?
(-> (gpt/add (vv (+ margin-top margin-bottom))) (-> (gpt/add (vv (+ margin-top margin-bottom)))
(gpt/add (vv (+ child-height layout-gap-row)))) (gpt/add (vv (+ child-height layout-gap-row))))
(some? margin-x) (some? margin-x)
(gpt/add (hv margin-x)) (gpt/add (hv margin-x))