0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-03-25 22:21:44 -05:00

Adapt scale to flex elements

This commit is contained in:
alonso.torres 2023-03-08 16:57:09 +01:00
parent 44c35e6aee
commit 3a2e1b5c94
5 changed files with 50 additions and 13 deletions
common/src/app/common
frontend/src/app/main/data/workspace

View file

@ -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

View file

@ -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]

View file

@ -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

View file

@ -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]

View file

@ -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