0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-02-09 16:48:16 -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)))
(defn change-dimensions-modifiers
[shape attr value]
[{:keys [transform transform-inverse] :as shape} attr value]
(us/assert map? shape)
(us/assert #{:width :height} attr)
(us/assert number? value)
@ -245,22 +245,17 @@
(-> size
(assoc :height value)
(assoc :width (* value proportion)))))
width (:width 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)
origin (cond-> (gpt/point (:selrect shape))
(some? shape-transform)
(gmt/transform-point-center shape-center shape-transform))
origin (-> shape :points first)
scalex (/ width sr-width)
scaley (/ height sr-height)]
scalev (gpt/divide (gpt/point width height)
(gpt/point sr-width sr-height))]
(resize-modifiers scalev origin shape-transform shape-transform-inv)))
(resize-modifiers (gpt/point scalex scaley) origin transform transform-inverse)))
(defn change-orientation-modifiers
[shape orientation]
@ -437,5 +432,3 @@
(as-> shape $
(reduce apply-modifier $ (:structure-parent modifiers))
(reduce apply-modifier $ (:structure-child modifiers))))))

View file

@ -394,7 +394,7 @@
ptk/UpdateEvent
(update [_ 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
(watch [_ state _]

View file

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