0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-02-13 10:38:13 -05:00

Fixed problem with new modifiers and text auto-heigh

This commit is contained in:
alonso.torres 2022-11-08 17:08:41 +01:00
parent 39041bb63b
commit 6e35b5c6b6
3 changed files with 27 additions and 29 deletions

View file

@ -229,7 +229,7 @@
(scale-content value))) (scale-content value)))
(defn change-dimensions-modifiers (defn change-dimensions-modifiers
[shape attr value] [{:keys [transform transform-inverse] :as shape} attr value]
(us/assert map? shape) (us/assert map? shape)
(us/assert #{:width :height} attr) (us/assert #{:width :height} attr)
(us/assert number? value) (us/assert number? value)
@ -245,22 +245,17 @@
(-> size (-> size
(assoc :height value) (assoc :height value)
(assoc :width (* value proportion))))) (assoc :width (* value proportion)))))
width (:width new-size) width (:width new-size)
height (:height new-size) height (:height new-size)
shape-transform (:transform shape)
shape-transform-inv (:transform-inverse shape)
shape-center (gco/center-shape shape)
{sr-width :width sr-height :height} (:selrect shape) {sr-width :width sr-height :height} (:selrect shape)
origin (cond-> (gpt/point (:selrect shape)) origin (-> shape :points first)
(some? shape-transform) scalex (/ width sr-width)
(gmt/transform-point-center shape-center shape-transform)) scaley (/ height sr-height)]
scalev (gpt/divide (gpt/point width height) (resize-modifiers (gpt/point scalex scaley) origin transform transform-inverse)))
(gpt/point sr-width sr-height))]
(resize-modifiers scalev origin shape-transform shape-transform-inv)))
(defn change-orientation-modifiers (defn change-orientation-modifiers
[shape orientation] [shape orientation]
@ -437,5 +432,3 @@
(as-> shape $ (as-> shape $
(reduce apply-modifier $ (:structure-parent modifiers)) (reduce apply-modifier $ (:structure-parent modifiers))
(reduce apply-modifier $ (:structure-child modifiers)))))) (reduce apply-modifier $ (:structure-child modifiers))))))

View file

@ -394,7 +394,7 @@
ptk/UpdateEvent ptk/UpdateEvent
(update [_ state] (update [_ state]
(let [ids (keys (::update-position-data state))] (let [ids (keys (::update-position-data state))]
(update state :workspace-text-modifiers #(apply dissoc % ids)))) (update state :workspace-text-modifier #(apply dissoc % ids))))
ptk/WatchEvent ptk/WatchEvent
(watch [_ state _] (watch [_ state _]

View file

@ -33,7 +33,7 @@
(-> shape (-> shape
(cond-> (some? (meta (:position-data shape))) (cond-> (some? (meta (:position-data shape)))
(with-meta (meta (:position-data shape)))) (with-meta (meta (:position-data shape))))
(dissoc :position-data :transform :transform-inverse))) (dissoc :position-data)))
(defn fix-position [shape modifier] (defn fix-position [shape modifier]
(let [shape' (-> shape (let [shape' (-> shape
@ -92,20 +92,26 @@
(defn- update-text-modifier (defn- update-text-modifier
[{:keys [grow-type id]} node] [{:keys [grow-type id]} node]
(p/let [position-data (tsp/calc-position-data id) (ts/raf
props {:position-data position-data} #(p/let [position-data (tsp/calc-position-data id)
props {:position-data position-data}
props props
(if (contains? #{:auto-height :auto-width} grow-type) (if (contains? #{:auto-height :auto-width} grow-type)
(let [{:keys [width height]} (-> (dom/query node ".paragraph-set") (dom/get-client-size)) (let [{:keys [width height]} (-> (dom/query node ".paragraph-set") (dom/get-client-size))
width (mth/ceil width) width (mth/ceil width)
height (mth/ceil height)] height (mth/ceil height)]
(if (and (not (mth/almost-zero? width)) (not (mth/almost-zero? height))) (if (and (not (mth/almost-zero? width)) (not (mth/almost-zero? height)))
(assoc props :width width :height height) (cond-> props
props)) (= grow-type :auto-width)
props)] (assoc :width width)
(st/emit! (dwt/update-text-modifier id props)))) (or (= grow-type :auto-height) (= grow-type :auto-width))
(assoc :height height))
props))
props)]
(st/emit! (dwt/update-text-modifier id props)))))
(mf/defc text-container (mf/defc text-container
{::mf/wrap-props false {::mf/wrap-props false
@ -163,10 +169,9 @@
handle-update-modifier (mf/use-callback update-text-modifier) handle-update-modifier (mf/use-callback update-text-modifier)
handle-update-shape (mf/use-callback update-text-shape)] handle-update-shape (mf/use-callback update-text-shape)]
[:* [:*
(for [{:keys [id] :as shape} changed-texts] (for [{:keys [id] :as shape} changed-texts]
[:& text-container {:shape (gsh/transform-shape shape) [:& text-container {:shape shape
:on-update (if (some? (get modifiers (:id shape))) :on-update (if (some? (get modifiers (:id shape)))
handle-update-modifier handle-update-modifier
handle-update-shape) handle-update-shape)