0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-09 08:20:45 -05:00

🐛 Fix problem with layout sizing

This commit is contained in:
alonso.torres 2023-11-07 11:26:13 +01:00
parent bec683d1ef
commit 6d5af8d6ef
3 changed files with 48 additions and 50 deletions

View file

@ -70,11 +70,8 @@
child-max-width (ctl/child-max-width child)
child-max-height (ctl/child-max-height child)
[child-margin-top child-margin-right child-margin-bottom child-margin-left]
(ctl/child-margins child)
child-margin-width (+ child-margin-left child-margin-right)
child-margin-height (+ child-margin-top child-margin-bottom)
child-margin-width (ctl/child-width-margin child)
child-margin-height (ctl/child-height-margin child)
fill-width? (ctl/fill-width? child)
fill-height? (ctl/fill-height? child)

View file

@ -61,13 +61,15 @@
(defn child-min-width
[child child-bounds bounds objects]
(-child-min-width child child-bounds bounds objects))
(+ (ctl/child-width-margin child)
(-child-min-width child child-bounds bounds objects)))
(def -child-min-height nil)
(defn child-min-height
[child child-bounds bounds objects]
(-child-min-height child child-bounds bounds objects))
(+ (ctl/child-height-margin child)
(-child-min-height child child-bounds bounds objects)))
(defn layout-bounds
[parent shape-bounds]

View file

@ -17,53 +17,53 @@
(defn child-min-width
[child child-bounds bounds objects]
(let [min-width
(cond
(and (ctl/fill-width? child) (ctl/flex-layout? child))
(let [children (cph/get-immediate-children objects (dm/get-prop child :id) {:remove-hidden true})]
(max (ctl/child-min-width child)
(gpo/width-points (fb/layout-content-bounds bounds child children objects))))
(and (ctl/fill-width? child)
(ctl/grid-layout? child))
(let [children
(->> (cph/get-immediate-children objects (:id child) {:remove-hidden true})
(map #(vector @(get bounds (:id %)) %)))
layout-data (gd/calc-layout-data child @(get bounds (:id child)) children bounds objects true)]
(max (ctl/child-min-width child)
(gpo/width-points (gb/layout-content-bounds bounds child layout-data))))
(ctl/fill-width? child)
(ctl/child-min-width child)
(cond
(and (ctl/fill-width? child) (ctl/flex-layout? child))
(ctl/child-min-width child)
;; Uncomment this to activate "auto" as min size
#_(let [children (cph/get-immediate-children objects (dm/get-prop child :id) {:remove-hidden true})]
(max (ctl/child-min-width child)
(gpo/width-points (fb/layout-content-bounds bounds child children objects))))
:else
(gpo/width-points child-bounds))]
(+ min-width (ctl/child-width-margin child))))
(and (ctl/fill-width? child)
(ctl/grid-layout? child))
(let [children
(->> (cph/get-immediate-children objects (:id child) {:remove-hidden true})
(map #(vector @(get bounds (:id %)) %)))
layout-data (gd/calc-layout-data child @(get bounds (:id child)) children bounds objects true)]
(max (ctl/child-min-width child)
(gpo/width-points (gb/layout-content-bounds bounds child layout-data))))
(ctl/fill-width? child)
(ctl/child-min-width child)
:else
(gpo/width-points child-bounds)))
(defn child-min-height
[child child-bounds bounds objects]
(let [min-height
(cond
(and (ctl/fill-height? child) (ctl/flex-layout? child))
(let [children (cph/get-immediate-children objects (dm/get-prop child :id) {:remove-hidden true})]
(max (ctl/child-min-height child)
(gpo/height-points (fb/layout-content-bounds bounds child children objects))))
(and (ctl/fill-height? child) (ctl/grid-layout? child))
(let [children
(->> (cph/get-immediate-children objects (dm/get-prop child :id) {:remove-hidden true})
(map (fn [child] [@(get bounds (:id child)) child])))
layout-data (gd/calc-layout-data child (:points child) children bounds objects true)
auto-bounds (gb/layout-content-bounds bounds child layout-data)]
(max (ctl/child-min-height child)
(gpo/height-points auto-bounds)))
(ctl/fill-height? child)
(ctl/child-min-height child)
(cond
(and (ctl/fill-height? child) (ctl/flex-layout? child))
;; Uncomment this to activate "auto" as min size
(ctl/child-min-height child)
#_(let [children (cph/get-immediate-children objects (dm/get-prop child :id) {:remove-hidden true})]
(max (ctl/child-min-height child)
(gpo/height-points (fb/layout-content-bounds bounds child children objects))))
:else
(gpo/height-points child-bounds))]
(+ min-height (ctl/child-height-margin child))))
(and (ctl/fill-height? child) (ctl/grid-layout? child))
(let [children
(->> (cph/get-immediate-children objects (dm/get-prop child :id) {:remove-hidden true})
(map (fn [child] [@(get bounds (:id child)) child])))
layout-data (gd/calc-layout-data child (:points child) children bounds objects true)
auto-bounds (gb/layout-content-bounds bounds child layout-data)]
(max (ctl/child-min-height child)
(gpo/height-points auto-bounds)))
(ctl/fill-height? child)
(ctl/child-min-height child)
:else
(gpo/height-points child-bounds)))
#?(:cljs
(do (set! fd/-child-min-width child-min-width)
@ -80,4 +80,3 @@
(alter-var-root #'fb/-child-min-height (constantly child-min-height))
(alter-var-root #'gd/-child-min-width (constantly child-min-width))
(alter-var-root #'gd/-child-min-height (constantly child-min-height))))