mirror of
https://github.com/penpot/penpot.git
synced 2025-03-13 08:11:30 -05:00
✨ Margins for grid elements
This commit is contained in:
parent
6f2a459cce
commit
52cbc7e09d
3 changed files with 30 additions and 18 deletions
|
@ -62,15 +62,17 @@
|
||||||
|
|
||||||
(defn child-min-width
|
(defn child-min-width
|
||||||
[child bounds]
|
[child bounds]
|
||||||
(if (ctl/fill-width? child)
|
(+ (if (ctl/fill-width? child)
|
||||||
(ctl/child-min-width child)
|
(ctl/child-min-width child)
|
||||||
(gpo/width-points bounds)))
|
(gpo/width-points bounds))
|
||||||
|
(ctl/child-width-margin child)))
|
||||||
|
|
||||||
(defn child-min-height
|
(defn child-min-height
|
||||||
[child bounds]
|
[child bounds]
|
||||||
(if (ctl/fill-height? child)
|
(+ (if (ctl/fill-height? child)
|
||||||
(ctl/child-min-height child)
|
(ctl/child-min-height child)
|
||||||
(gpo/height-points bounds)))
|
(gpo/height-points bounds))
|
||||||
|
(ctl/child-height-margin child)))
|
||||||
|
|
||||||
(defn calculate-initial-track-size
|
(defn calculate-initial-track-size
|
||||||
[total-value {:keys [type value] :as track}]
|
[total-value {:keys [type value] :as track}]
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
[app.common.types.shape.layout :as ctl]))
|
[app.common.types.shape.layout :as ctl]))
|
||||||
|
|
||||||
(defn cell-bounds
|
(defn cell-bounds
|
||||||
|
"Retrieves the points that define the bounds for given cell"
|
||||||
[{:keys [origin row-tracks column-tracks layout-bounds column-gap row-gap] :as layout-data} {:keys [row column row-span column-span] :as cell}]
|
[{:keys [origin row-tracks column-tracks layout-bounds column-gap row-gap] :as layout-data} {:keys [row column row-span column-span] :as cell}]
|
||||||
|
|
||||||
(let [hv #(gpo/start-hv layout-bounds %)
|
(let [hv #(gpo/start-hv layout-bounds %)
|
||||||
|
@ -55,11 +56,13 @@
|
||||||
[_parent
|
[_parent
|
||||||
transform
|
transform
|
||||||
transform-inverse
|
transform-inverse
|
||||||
_child
|
child
|
||||||
child-origin child-width
|
child-origin child-width
|
||||||
cell-bounds]
|
cell-bounds]
|
||||||
|
|
||||||
(let [target-width (max (gpo/width-points cell-bounds) 0.01)
|
(let [target-width (max (- (gpo/width-points cell-bounds) (ctl/child-width-margin child)) 0.01)
|
||||||
|
max-width (max (ctl/child-max-width child) 0.01)
|
||||||
|
target-width (mth/clamp target-width (ctl/child-min-width child) max-width)
|
||||||
fill-scale (/ target-width child-width)]
|
fill-scale (/ target-width child-width)]
|
||||||
{:width target-width
|
{:width target-width
|
||||||
:modifiers (ctm/resize-modifiers (gpt/point fill-scale 1) child-origin transform transform-inverse)}))
|
:modifiers (ctm/resize-modifiers (gpt/point fill-scale 1) child-origin transform transform-inverse)}))
|
||||||
|
@ -68,10 +71,12 @@
|
||||||
"Calculates the size and modifiers for the height of an auto-fill child"
|
"Calculates the size and modifiers for the height of an auto-fill child"
|
||||||
[_parent
|
[_parent
|
||||||
transform transform-inverse
|
transform transform-inverse
|
||||||
_child
|
child
|
||||||
child-origin child-height
|
child-origin child-height
|
||||||
cell-bounds]
|
cell-bounds]
|
||||||
(let [target-height (max (gpo/height-points cell-bounds) 0.01)
|
(let [target-height (max (- (gpo/height-points cell-bounds) (ctl/child-height-margin child)) 0.01)
|
||||||
|
max-height (max (ctl/child-max-height child) 0.01)
|
||||||
|
target-height (mth/clamp target-height (ctl/child-min-height child) max-height)
|
||||||
fill-scale (/ target-height child-height)]
|
fill-scale (/ target-height child-height)]
|
||||||
{:height target-height
|
{:height target-height
|
||||||
:modifiers (ctm/resize-modifiers (gpt/point 1 fill-scale) child-origin transform transform-inverse)}))
|
:modifiers (ctm/resize-modifiers (gpt/point 1 fill-scale) child-origin transform transform-inverse)}))
|
||||||
|
@ -106,7 +111,7 @@
|
||||||
(cond-> fill-height (ctm/add-modifiers (:modifiers fill-height))))]))
|
(cond-> fill-height (ctm/add-modifiers (:modifiers fill-height))))]))
|
||||||
|
|
||||||
(defn child-position-delta
|
(defn child-position-delta
|
||||||
[parent child-bounds child-width child-height layout-data cell-data]
|
[parent child 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)
|
child-origin (gpo/origin child-bounds)
|
||||||
|
|
||||||
|
@ -126,30 +131,35 @@
|
||||||
hv (partial gpo/start-hv cell-bounds)
|
hv (partial gpo/start-hv cell-bounds)
|
||||||
vv (partial gpo/start-vv cell-bounds)
|
vv (partial gpo/start-vv cell-bounds)
|
||||||
|
|
||||||
|
[top-m right-m bottom-m left-m] (ctl/child-margins child)
|
||||||
|
|
||||||
;; Adjust alignment/justify
|
;; Adjust alignment/justify
|
||||||
[from-h to-h]
|
[from-h to-h]
|
||||||
(case justify
|
(case justify
|
||||||
:end
|
:end
|
||||||
[(gpt/add origin-h (hv child-width))
|
[(gpt/add origin-h (hv child-width))
|
||||||
(nth cell-bounds 1)]
|
(gpt/subtract (nth cell-bounds 1) (hv right-m))]
|
||||||
|
|
||||||
:center
|
:center
|
||||||
[(gpt/add origin-h (hv (/ child-width 2)))
|
[(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))]
|
||||||
|
|
||||||
[origin-h (first cell-bounds)])
|
[origin-h
|
||||||
|
(gpt/add (first cell-bounds) (hv left-m))])
|
||||||
|
|
||||||
[from-v to-v]
|
[from-v to-v]
|
||||||
(case align
|
(case align
|
||||||
:end
|
:end
|
||||||
[(gpt/add origin-v (vv child-height))
|
[(gpt/add origin-v (vv child-height))
|
||||||
(nth cell-bounds 3)]
|
(gpt/subtract (nth cell-bounds 3) (vv bottom-m))]
|
||||||
|
|
||||||
:center
|
:center
|
||||||
[(gpt/add origin-v (vv (/ child-height 2)))
|
[(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))]
|
||||||
|
|
||||||
[origin-v (first cell-bounds)])]
|
[origin-v
|
||||||
|
(gpt/add (first cell-bounds) (vv top-m))])]
|
||||||
|
|
||||||
(-> (gpt/point)
|
(-> (gpt/point)
|
||||||
(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)))))
|
||||||
|
@ -160,7 +170,7 @@
|
||||||
(let [[child-width child-height fill-modifiers]
|
(let [[child-width child-height fill-modifiers]
|
||||||
(fill-modifiers parent parent-bounds child child-bounds layout-data cell-data)
|
(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)]
|
position-delta (child-position-delta parent child 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))
|
||||||
|
|
|
@ -533,7 +533,7 @@
|
||||||
:nillable true
|
:nillable true
|
||||||
:value (:layout-item-z-index values)}]])]
|
:value (:layout-item-z-index values)}]])]
|
||||||
|
|
||||||
(when is-layout-child?
|
(when (and is-layout-child? is-flex-parent?)
|
||||||
[:div {:class (stl/css :second-row)}
|
[:div {:class (stl/css :second-row)}
|
||||||
[:& align-self-row {:is-col? is-col?
|
[:& align-self-row {:is-col? is-col?
|
||||||
:align-self align-self
|
:align-self align-self
|
||||||
|
@ -667,7 +667,7 @@
|
||||||
:on-change-behaviour-v-refactor on-change-behaviour-v
|
:on-change-behaviour-v-refactor on-change-behaviour-v
|
||||||
:on-change on-change-behaviour}]]
|
:on-change on-change-behaviour}]]
|
||||||
|
|
||||||
(when is-layout-child?
|
(when (and is-layout-child? is-flex-parent?)
|
||||||
[:div.layout-row
|
[:div.layout-row
|
||||||
[:div.row-title "Align"]
|
[:div.row-title "Align"]
|
||||||
[:div.btn-wrapper
|
[:div.btn-wrapper
|
||||||
|
|
Loading…
Add table
Reference in a new issue