mirror of
https://github.com/penpot/penpot.git
synced 2026-08-01 19:06:18 +00:00
🐛 Fix problem with hug and item margins
This commit is contained in:
parent
029efefb62
commit
2fbd1d8078
@ -8,7 +8,6 @@
|
|||||||
(:require
|
(:require
|
||||||
[app.common.geom.point :as gpt]
|
[app.common.geom.point :as gpt]
|
||||||
[app.common.geom.shapes.points :as gpo]
|
[app.common.geom.shapes.points :as gpo]
|
||||||
[app.common.math :as mth]
|
|
||||||
[app.common.types.shape.layout :as ctl]))
|
[app.common.types.shape.layout :as ctl]))
|
||||||
|
|
||||||
(defn child-layout-bound-points
|
(defn child-layout-bound-points
|
||||||
@ -55,38 +54,32 @@
|
|||||||
(gpt/add (hv (/ width 2)))
|
(gpt/add (hv (/ width 2)))
|
||||||
|
|
||||||
(and col? h-end?)
|
(and col? h-end?)
|
||||||
(gpt/add (hv width)))]
|
(gpt/add (hv width)))
|
||||||
|
|
||||||
(cond-> [base-p]
|
;; We need some height/width to calculate the bounds. We stablish the minimum
|
||||||
(and (mth/almost-zero? min-width) (mth/almost-zero? min-height))
|
min-width (max min-width 0.01)
|
||||||
(conj (cond-> base-p
|
min-height (max min-height 0.01)]
|
||||||
row?
|
|
||||||
(gpt/add (hv width))
|
|
||||||
|
|
||||||
col?
|
(-> [base-p]
|
||||||
(gpt/add (vv height))))
|
(conj (cond-> base-p
|
||||||
|
(or row? h-start?)
|
||||||
|
(gpt/add (hv min-width))
|
||||||
|
|
||||||
(not (mth/almost-zero? min-width))
|
(and col? h-center?)
|
||||||
(conj (cond-> base-p
|
(gpt/add (hv (/ min-width 2)))
|
||||||
(or row? h-start?)
|
|
||||||
(gpt/add (hv min-width))
|
|
||||||
|
|
||||||
(and col? h-center?)
|
(and col? h-center?)
|
||||||
(gpt/add (hv (/ min-width 2)))
|
(gpt/subtract (hv min-width))))
|
||||||
|
|
||||||
(and col? h-center?)
|
(conj (cond-> base-p
|
||||||
(gpt/subtract (hv min-width))))
|
(or col? v-start?)
|
||||||
|
(gpt/add (vv min-height))
|
||||||
|
|
||||||
(not (mth/almost-zero? min-height))
|
(and row? v-center?)
|
||||||
(conj (cond-> base-p
|
(gpt/add (vv (/ min-height 2)))
|
||||||
(or col? v-start?)
|
|
||||||
(gpt/add (vv min-height))
|
|
||||||
|
|
||||||
(and row? v-center?)
|
(and row? v-end?)
|
||||||
(gpt/add (vv (/ min-height 2)))
|
(gpt/subtract (vv min-height)))))))
|
||||||
|
|
||||||
(and row? v-end?)
|
|
||||||
(gpt/subtract (vv min-height)))))))
|
|
||||||
|
|
||||||
(defn layout-content-bounds
|
(defn layout-content-bounds
|
||||||
[bounds {:keys [layout-padding] :as parent} children]
|
[bounds {:keys [layout-padding] :as parent} children]
|
||||||
@ -107,8 +100,11 @@
|
|||||||
child-bounds
|
child-bounds
|
||||||
(if (or (ctl/fill-height? child) (ctl/fill-height? child))
|
(if (or (ctl/fill-height? child) (ctl/fill-height? child))
|
||||||
(child-layout-bound-points parent child parent-bounds child-bounds)
|
(child-layout-bound-points parent child parent-bounds child-bounds)
|
||||||
child-bounds)]
|
child-bounds)
|
||||||
(gpo/parent-coords-bounds child-bounds parent-bounds)))]
|
|
||||||
|
[margin-top margin-right margin-bottom margin-left] (ctl/child-margins child)]
|
||||||
|
(-> (gpo/parent-coords-bounds child-bounds parent-bounds)
|
||||||
|
(gpo/pad-points (- margin-top) (- margin-right) (- margin-bottom) (- margin-left)))))]
|
||||||
|
|
||||||
(as-> children $
|
(as-> children $
|
||||||
(map child-bounds $)
|
(map child-bounds $)
|
||||||
|
|||||||
@ -75,8 +75,8 @@
|
|||||||
points [start-p
|
points [start-p
|
||||||
(-> start-p (gpt/add (xv line-width)))
|
(-> start-p (gpt/add (xv line-width)))
|
||||||
(-> start-p (gpt/add (xv line-width)) (gpt/add (yv line-height)))
|
(-> start-p (gpt/add (xv line-width)) (gpt/add (yv line-height)))
|
||||||
(-> start-p (gpt/add (yv line-height)))
|
(-> start-p (gpt/add (yv line-height)))]]
|
||||||
]]
|
|
||||||
[:g.layout-line {:key (dm/str "line-" idx)}
|
[:g.layout-line {:key (dm/str "line-" idx)}
|
||||||
[:polygon {:points (->> points (map #(dm/fmt "%, %" (:x %) (:y %))) (str/join " "))
|
[:polygon {:points (->> points (map #(dm/fmt "%, %" (:x %) (:y %))) (str/join " "))
|
||||||
:style {:stroke "red" :stroke-width (/ 2 zoom) :stroke-dasharray (dm/str (/ 10 zoom) " " (/ 5 zoom))}}]]))]))))
|
:style {:stroke "red" :stroke-width (/ 2 zoom) :stroke-dasharray (dm/str (/ 10 zoom) " " (/ 5 zoom))}}]]))]))))
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user