Change behaviour of fill to respect minimum content size

This commit is contained in:
alonso.torres 2023-10-05 12:55:35 +02:00
parent 950fd60917
commit 785b58a6c4
14 changed files with 402 additions and 269 deletions

View file

@ -706,7 +706,9 @@
wrap-blocks
(let [block-children (->> children
(map #(vector (gpo/parent-coords-bounds (:points %) (:points frame)) %)))
layout-data (gsl/calc-layout-data frame block-children (:points frame))
bounds (d/lazy-map (keys objects) #(gsh/shape->points (get objects %)))
layout-data (gsl/calc-layout-data frame (:points frame) block-children bounds objects)
layout-bounds (:layout-bounds layout-data)
xv #(gpo/start-hv layout-bounds %)
yv #(gpo/start-vv layout-bounds %)]

View file

@ -6,13 +6,16 @@
(ns app.main.ui.shapes.grid-layout-viewer
(:require
[app.common.data :as d]
[app.common.data.macros :as dm]
[app.common.geom.matrix :as gmt]
[app.common.geom.point :as gpt]
[app.common.geom.shapes :as gsh]
[app.common.geom.shapes.grid-layout :as gsg]
[app.common.geom.shapes.points :as gpo]
[app.common.pages.helpers :as cph]
[app.common.types.shape.layout :as ctl]
[app.main.refs :as refs]
[rumext.v2 :as mf]))
(mf/defc grid-cell-area-label
@ -82,14 +85,15 @@
{::mf/wrap-props false}
[props]
(let [shape (unchecked-get props "shape")
childs (unchecked-get props "childs")
objects (mf/deref refs/workspace-page-objects)
bounds (d/lazy-map (keys objects) #(gsh/shape->points (get objects %)))
children
(->> childs
(->> (cph/get-immediate-children objects (:id shape))
(remove :hidden)
(map #(vector (gpo/parent-coords-bounds (:points %) (:points shape)) %)))
layout-data (gsg/calc-layout-data shape children (:points shape))]
layout-data (gsg/calc-layout-data shape (:points shape) children bounds objects)]
[:g.cells
(for [cell (ctl/get-cells shape {:sort? true})]

View file

@ -40,18 +40,23 @@
(let [children (->> (cph/get-immediate-children objects (:id shape))
(remove :hidden))
bounds (d/lazy-map (keys objects) #(dm/get-in objects [% :points]))
grid-layout-data
(when (ctl/grid-layout? shape)
(gsg/calc-layout-data shape (:points shape) children bounds objects))
layout-bounds
(cond (ctl/flex-layout? shape)
(gsl/layout-content-bounds bounds shape children)
(gsl/layout-content-bounds bounds shape children objects)
(ctl/grid-layout? shape)
(gsg/layout-content-bounds bounds shape children))
(gsg/layout-content-bounds bounds shape grid-layout-data))
layout-points
(cond (ctl/flex-layout? shape)
(flatten (gsl/layout-content-points bounds shape children))
(flatten (gsl/layout-content-points bounds shape children objects))
(ctl/grid-layout? shape)
(flatten (gsg/layout-content-points bounds shape children)))]
(flatten (gsg/layout-content-points bounds shape grid-layout-data)))]
[:g.debug-layout {:pointer-events "none"}
[:polygon {:points (->> layout-bounds (map #(dm/fmt "%, %" (:x %) (:y %))) (str/join " "))
@ -87,7 +92,10 @@
children (->> (cph/get-immediate-children objects (:id shape))
(remove :hidden)
(map #(vector (gpo/parent-coords-bounds (:points %) (:points shape)) %)))
layout-data (gsl/calc-layout-data shape children (:points shape))
bounds (d/lazy-map (keys objects) #(dm/get-in objects [% :points]))
layout-data (gsl/calc-layout-data shape (:points shape) children bounds objects)
layout-bounds (:layout-bounds layout-data)
xv #(gpo/start-hv layout-bounds %)
@ -121,10 +129,12 @@
(when (and (= (count selected-shapes) 1) (= :frame (-> selected-shapes first :type)))
(first selected-shapes))
shape (or selected-frame (get objects hover-top-frame-id))]
shape (or selected-frame (get objects hover-top-frame-id))
bounds (d/lazy-map (keys objects) #(dm/get-in objects [% :points]))]
(when (and shape (:layout shape))
(let [drop-areas (gsl/get-drop-areas shape objects)]
(let [drop-areas (gsl/get-drop-areas shape objects bounds)]
[:g.debug-layout {:pointer-events "none"
:transform (gsh/transform-str shape)}
(for [[idx drop-area] (d/enumerate drop-areas)]
@ -184,7 +194,9 @@
(first selected-shapes))
parent (or selected-frame (get objects hover-top-frame-id))
parent-bounds (:points parent)]
parent-bounds (:points parent)
bounds (d/lazy-map (keys objects) #(dm/get-in objects [% :points]))]
(when (and (some? parent) (not= uuid/zero (:id parent)))
(let [children (->> (cph/get-immediate-children objects (:id parent))
@ -200,7 +212,7 @@
(let [child-bounds (:points child)
points
(if (or (ctl/fill-height? child) (ctl/fill-height? child))
(gsl/child-layout-bound-points parent child parent-bounds child-bounds)
(gsl/child-layout-bound-points parent child parent-bounds child-bounds bounds objects)
child-bounds)]
(for [point points]
[:circle {:cx (:x point)
@ -222,7 +234,9 @@
(first selected-shapes))
parent (or selected-frame (get objects hover-top-frame-id))
parent-bounds (:points parent)]
parent-bounds (:points parent)
bounds (d/lazy-map (keys objects) #(dm/get-in objects [% :points]))]
(when (and (some? parent) (not= uuid/zero (:id parent)))
(let [children (->> (cph/get-immediate-children objects (:id parent))
@ -237,7 +251,7 @@
origin (gpo/origin parent-bounds)
{:keys [row-tracks column-tracks]}
(gsg/calc-layout-data parent children parent-bounds)]
(gsg/calc-layout-data parent parent-bounds children bounds objects)]
[:*
(for [row-data row-tracks]

View file

@ -762,10 +762,12 @@
height (gpo/height-points bounds)
origin (gpo/origin bounds)
all-bounds (d/lazy-map (keys objects) #(gsh/shape->points (get objects %)))
{:keys [row-tracks column-tracks] :as layout-data}
(mf/use-memo
(mf/deps shape children)
#(gsg/calc-layout-data shape children bounds))
#(gsg/calc-layout-data shape bounds children all-bounds objects))
handle-pointer-down
(mf/use-callback