From 3a2e1b5c94373677a6b463387d06137f1f5e916a Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Wed, 8 Mar 2023 16:57:09 +0100 Subject: [PATCH] :sparkles: Adapt scale to flex elements --- .../app/common/geom/shapes/constraints.cljc | 16 ++++++------- common/src/app/common/types/modifiers.cljc | 9 ++++++- common/src/app/common/types/shape/layout.cljc | 24 +++++++++++++++++++ .../app/main/data/workspace/modifiers.cljs | 12 +++++++--- .../app/main/data/workspace/transforms.cljs | 2 +- 5 files changed, 50 insertions(+), 13 deletions(-) diff --git a/common/src/app/common/geom/shapes/constraints.cljc b/common/src/app/common/geom/shapes/constraints.cljc index 82ed2097b..6a9885e69 100644 --- a/common/src/app/common/geom/shapes/constraints.cljc +++ b/common/src/app/common/geom/shapes/constraints.cljc @@ -288,25 +288,25 @@ constraints-h (cond + ignore-constraints + :scale + (and (ctl/any-layout? parent) (not (ctl/layout-absolute? child))) :left - (not ignore-constraints) - (:constraints-h child (default-constraints-h child)) - :else - :scale) + (:constraints-h child (default-constraints-h child))) constraints-v (cond + ignore-constraints + :scale + (and (ctl/any-layout? parent) (not (ctl/layout-absolute? child))) :top - (not ignore-constraints) - (:constraints-v child (default-constraints-v child)) - :else - :scale)] + (:constraints-v child (default-constraints-v child)))] (if (and (= :scale constraints-h) (= :scale constraints-v)) modifiers diff --git a/common/src/app/common/types/modifiers.cljc b/common/src/app/common/types/modifiers.cljc index 3673eba1d..1884ff043 100644 --- a/common/src/app/common/types/modifiers.cljc +++ b/common/src/app/common/types/modifiers.cljc @@ -19,6 +19,7 @@ [app.common.pages.helpers :as cph] [app.common.spec :as us] [app.common.text :as txt] + [app.common.types.shape.layout :as ctl] #?(:cljs [cljs.core :as c] :clj [clojure.core :as c]))) @@ -672,7 +673,13 @@ (gse/update-shadows-scale value) (some? (:blur shape)) - (gse/update-blur-scale value)))] + (gse/update-blur-scale value) + + (ctl/flex-layout? shape) + (ctl/update-flex-scale value) + + :always + (ctl/update-flex-child value)))] (let [remove-children (fn [shapes children-to-remove] diff --git a/common/src/app/common/types/shape/layout.cljc b/common/src/app/common/types/shape/layout.cljc index c669aae62..6ae3ca0ed 100644 --- a/common/src/app/common/types/shape/layout.cljc +++ b/common/src/app/common/types/shape/layout.cljc @@ -497,6 +497,30 @@ :layout-item-align-self :layout-item-absolute :layout-item-z-index)) + +(defn update-flex-scale + [shape scale] + (-> shape + (d/update-in-when [:layout-gap :row-gap] * scale) + (d/update-in-when [:layout-gap :column-gap] * scale) + (d/update-in-when [:layout-padding :p1] * scale) + (d/update-in-when [:layout-padding :p2] * scale) + (d/update-in-when [:layout-padding :p3] * scale) + (d/update-in-when [:layout-padding :p4] * scale))) + +(defn update-flex-child + [shape scale] + (-> shape + (d/update-when :layout-item-max-h * scale) + (d/update-when :layout-item-min-h * scale) + (d/update-when :layout-item-max-w * scale) + (d/update-when :layout-item-min-w * scale) + (d/update-in-when [:layout-item-margin :m1] * scale) + (d/update-in-when [:layout-item-margin :m2] * scale) + (d/update-in-when [:layout-item-margin :m3] * scale) + (d/update-in-when [:layout-item-margin :m4] * scale))) + + (declare assign-cells) (def grid-cell-defaults diff --git a/frontend/src/app/main/data/workspace/modifiers.cljs b/frontend/src/app/main/data/workspace/modifiers.cljs index fa5935607..8c3a6dfca 100644 --- a/frontend/src/app/main/data/workspace/modifiers.cljs +++ b/frontend/src/app/main/data/workspace/modifiers.cljs @@ -438,14 +438,20 @@ :flip-x :flip-y :grow-type - :layout-item-h-sizing - :layout-item-v-sizing + :position-data + :layout-gap :layout-padding + :layout-item-h-sizing + :layout-item-margin + :layout-item-max-h + :layout-item-max-w + :layout-item-min-h + :layout-item-min-w + :layout-item-v-sizing :layout-padding-type :layout-gap :layout-item-margin :layout-item-margin-type - :position-data ]}) ;; We've applied the text-modifier so we can dissoc the temporary data (fn [state] diff --git a/frontend/src/app/main/data/workspace/transforms.cljs b/frontend/src/app/main/data/workspace/transforms.cljs index 88817b3be..2d07e0766 100644 --- a/frontend/src/app/main/data/workspace/transforms.cljs +++ b/frontend/src/app/main/data/workspace/transforms.cljs @@ -193,7 +193,7 @@ (ctm/scale-content (:x scalev)))) modif-tree (dwm/create-modif-tree ids modifiers)] - (rx/of (dwm/set-modifiers modif-tree (and (= :frame (:type shape)) scale-text))))) + (rx/of (dwm/set-modifiers modif-tree scale-text)))) ;; Unifies the instantaneous proportion lock modifier ;; activated by Shift key and the shapes own proportion