From 9f9d9277a62d3541721700fe13fd1a58628b69a4 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Wed, 25 Jan 2023 16:33:23 +0100 Subject: [PATCH] :bug: Fix problem with space-around and auto-width/height --- .../geom/shapes/flex_layout/bounds.cljc | 21 ++++++-- .../common/geom/shapes/flex_layout/lines.cljc | 54 +++++++++++++------ 2 files changed, 55 insertions(+), 20 deletions(-) diff --git a/common/src/app/common/geom/shapes/flex_layout/bounds.cljc b/common/src/app/common/geom/shapes/flex_layout/bounds.cljc index 64e673fd2..d52c6be9c 100644 --- a/common/src/app/common/geom/shapes/flex_layout/bounds.cljc +++ b/common/src/app/common/geom/shapes/flex_layout/bounds.cljc @@ -87,11 +87,24 @@ (let [parent-id (:id parent) parent-bounds @(get bounds parent-id) + row? (ctl/row? parent) + col? (ctl/col? parent) + space-around? (ctl/space-around? parent) + [layout-gap-row layout-gap-col] (ctl/gaps parent) + + row-pad (if (and col? space-around?) + layout-gap-row + 0) + + col-pad (if (and row? space-around?) + layout-gap-col + 0) + {pad-top :p1 pad-right :p2 pad-bottom :p3 pad-left :p4} layout-padding - pad-top (or pad-top 0) - pad-right (or pad-right 0) - pad-bottom (or pad-bottom 0) - pad-left (or pad-left 0) + pad-top (+ (or pad-top 0) row-pad) + pad-right (+ (or pad-right 0) col-pad) + pad-bottom (+ (or pad-bottom 0) row-pad) + pad-left (+ (or pad-left 0) col-pad) child-bounds (fn [child] diff --git a/common/src/app/common/geom/shapes/flex_layout/lines.cljc b/common/src/app/common/geom/shapes/flex_layout/lines.cljc index b2eb709dd..3801097b1 100644 --- a/common/src/app/common/geom/shapes/flex_layout/lines.cljc +++ b/common/src/app/common/geom/shapes/flex_layout/lines.cljc @@ -26,6 +26,7 @@ (let [col? (ctl/col? shape) row? (ctl/row? shape) + space-around? (ctl/space-around? shape) wrap? (and (ctl/wrap? shape) (or col? (not (ctl/auto-width? shape))) @@ -77,8 +78,18 @@ next-max-width (+ child-margin-width (if fill-width? child-max-width child-width)) next-max-height (+ child-margin-height (if fill-height? child-max-height child-height)) - next-line-min-width (+ line-min-width next-min-width (* layout-gap-col num-children)) - next-line-min-height (+ line-min-height next-min-height (* layout-gap-row num-children))] + total-gap-col (if space-around? + (* layout-gap-col (+ num-children 2)) + (* layout-gap-col num-children)) + + total-gap-row (if space-around? + (* layout-gap-row (+ num-children 2)) + (* layout-gap-row num-children)) + + next-line-min-width (+ line-min-width next-min-width total-gap-col) + next-line-min-height (+ line-min-height next-min-height total-gap-row) + + ] (if (and (some? line-data) (or (not wrap?) @@ -226,16 +237,38 @@ row? (ctl/row? shape) col? (ctl/col? shape) + auto-height? (ctl/auto-height? shape) + auto-width? (ctl/auto-width? shape) space-between? (ctl/space-between? shape) space-around? (ctl/space-around? shape) [layout-gap-row layout-gap-col] (ctl/gaps shape) + margin-x + (cond (and row? space-around? (not auto-width?)) + (max layout-gap-col (/ (- width line-width) (inc num-children))) + + (and row? space-around? auto-width?) + layout-gap-col + + :else + 0) + + margin-y + (cond (and col? space-around? (not auto-height?)) + (max layout-gap-row (/ (- height line-height) (inc num-children))) + + (and col? space-around? auto-height?) + layout-gap-row + + :else + 0) + layout-gap-col (cond (and row? space-around?) 0 - (and row? space-between?) + (and row? space-between? (not auto-width?)) (max layout-gap-col (/ (- width line-width) (dec num-children))) :else @@ -245,21 +278,11 @@ (cond (and col? space-around?) 0 - (and col? space-between?) + (and col? space-between? (not auto-height?)) (max layout-gap-row (/ (- height line-height) (dec num-children))) :else - layout-gap-row) - - margin-x - (if (and row? space-around?) - (/ (- width line-width) (inc num-children)) - 0) - - margin-y - (if (and col? space-around?) - (/ (- height line-height) (inc num-children)) - 0)] + layout-gap-row)] (assoc line-data :layout-bounds layout-bounds :layout-gap-row layout-gap-row @@ -308,4 +331,3 @@ {:layout-lines layout-lines :layout-bounds layout-bounds :reverse? reverse?})) -