mirror of https://github.com/penpot/penpot.git
🐛 Fix problem with text grow types
This commit is contained in:
parent
f8cebb9d63
commit
7c1205018b
|
|
@ -191,30 +191,6 @@
|
|||
(d/not-empty? position-data)
|
||||
(assoc :position-data position-data))))
|
||||
|
||||
(defn update-grow-type
|
||||
[shape old-shape]
|
||||
(let [auto-width? (= :auto-width (:grow-type shape))
|
||||
auto-height? (= :auto-height (:grow-type shape))
|
||||
|
||||
changed-width? (> (mth/abs (- (:width shape) (:width old-shape))) 0.1)
|
||||
changed-height? (> (mth/abs (- (:height shape) (:height old-shape))) 0.1)
|
||||
|
||||
;; Check if the shape is in a flex layout context that might cause layout-driven changes
|
||||
;; We should be more conservative about converting auto-width to fixed when the shape
|
||||
;; is part of a layout system that could cause automatic resizing
|
||||
has-layout-item-sizing? (or (:layout-item-h-sizing shape) (:layout-item-v-sizing shape))
|
||||
|
||||
;; Only convert auto-width to fixed if:
|
||||
;; 1. For auto-width: both width AND height changed (indicating user manipulation, not layout)
|
||||
;; 2. For auto-height: only height changed
|
||||
;; 3. The shape is not in a layout context where automatic sizing changes are expected
|
||||
change-to-fixed? (and (not has-layout-item-sizing?)
|
||||
(or (and auto-width? changed-width? changed-height?)
|
||||
(and auto-height? changed-height?)))]
|
||||
(cond-> shape
|
||||
change-to-fixed?
|
||||
(assoc :grow-type :fixed))))
|
||||
|
||||
(defn- set-wasm-props!
|
||||
[objects prev-wasm-props wasm-props]
|
||||
(let [;; Set old value for previous properties
|
||||
|
|
@ -810,9 +786,7 @@
|
|||
(-> shape
|
||||
(gsh/transform-shape modifiers)
|
||||
(cond-> (d/not-empty? pos-data)
|
||||
(assoc-position-data pos-data shape))
|
||||
(cond-> text-shape?
|
||||
(update-grow-type shape)))))]
|
||||
(assoc-position-data pos-data shape)))))]
|
||||
|
||||
(rx/of (ptk/event ::dwg/move-frame-guides {:ids ids-with-children :modifiers object-modifiers})
|
||||
(ptk/event ::dwcm/move-frame-comment-threads ids-with-children)
|
||||
|
|
@ -857,23 +831,20 @@
|
|||
(rx/empty))))))))
|
||||
|
||||
;; Pure function to determine next grow-type for text layers
|
||||
(defn next-grow-type [current-grow-type resize-direction]
|
||||
(defn next-grow-type
|
||||
[current-grow-type scalev]
|
||||
(cond
|
||||
(= current-grow-type :fixed)
|
||||
:fixed
|
||||
|
||||
(and (= resize-direction :horizontal)
|
||||
(= current-grow-type :auto-width))
|
||||
:auto-height
|
||||
|
||||
(and (= resize-direction :horizontal)
|
||||
(= current-grow-type :auto-height))
|
||||
:auto-height
|
||||
|
||||
(and (= resize-direction :vertical)
|
||||
(and (not (mth/close? (:y scalev) 1.0))
|
||||
(or (= current-grow-type :auto-width)
|
||||
(= current-grow-type :auto-height)))
|
||||
:fixed
|
||||
|
||||
(and (not (mth/close? (:x scalev) 1.0))
|
||||
(= current-grow-type :auto-width))
|
||||
:auto-height
|
||||
|
||||
:else
|
||||
current-grow-type))
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@
|
|||
[app.common.math :as mth]
|
||||
[app.common.types.fills :as types.fills]
|
||||
[app.common.types.modifiers :as ctm]
|
||||
[app.common.types.shape.layout :as ctl]
|
||||
[app.common.types.text :as txt]
|
||||
[app.common.uuid :as uuid]
|
||||
[app.main.data.event :as ev]
|
||||
|
|
@ -581,12 +582,17 @@
|
|||
|
||||
shape
|
||||
(cond-> shape
|
||||
(and (not-changed? shape-width new-width) (= grow-type :auto-width))
|
||||
(and (or (not (ctl/any-layout-immediate-child? objects shape))
|
||||
(not (ctl/fill-width? shape)))
|
||||
(not-changed? shape-width new-width)
|
||||
(= grow-type :auto-width))
|
||||
(gsh/transform-shape (ctm/change-dimensions-modifiers shape :width new-width {:ignore-lock? true})))
|
||||
|
||||
shape
|
||||
(cond-> shape
|
||||
(and (not-changed? shape-height new-height)
|
||||
(and (or (not (ctl/any-layout-immediate-child? objects shape))
|
||||
(not (ctl/fill-height? shape)))
|
||||
(not-changed? shape-height new-height)
|
||||
(or (= grow-type :auto-height) (= grow-type :auto-width)))
|
||||
(gsh/transform-shape (ctm/change-dimensions-modifiers shape :height new-height {:ignore-lock? true})))]
|
||||
|
||||
|
|
@ -594,7 +600,8 @@
|
|||
|
||||
(let [ids (into #{} (filter changed-text?) (keys props))]
|
||||
(rx/of (dwu/start-undo-transaction undo-id)
|
||||
(dwsh/update-shapes ids update-fn {:reg-objects? true
|
||||
(dwsh/update-shapes ids update-fn {:with-objects? true
|
||||
:reg-objects? true
|
||||
:stack-undo? true
|
||||
:ignore-touched true})
|
||||
(ptk/data-event :layout/update {:ids ids})
|
||||
|
|
|
|||
|
|
@ -218,15 +218,10 @@
|
|||
(gpt/add resize-origin displacement)
|
||||
resize-origin)
|
||||
|
||||
;; Determine resize direction for grow-type logic
|
||||
resize-direction (cond
|
||||
(or (= handler :left) (= handler :right)) :horizontal
|
||||
(or (= handler :top) (= handler :bottom)) :vertical
|
||||
:else nil)
|
||||
|
||||
;; Calculate new grow-type for text layers
|
||||
new-grow-type (when (cfh/text-shape? shape)
|
||||
(dwm/next-grow-type (dm/get-prop shape :grow-type) resize-direction))
|
||||
new-grow-type
|
||||
(when (cfh/text-shape? shape)
|
||||
(dwm/next-grow-type (dm/get-prop shape :grow-type) scalev))
|
||||
|
||||
;; When the horizontal/vertical scale a flex children with auto/fill
|
||||
;; we change it too fixed
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@
|
|||
[app.common.types.modifiers :as ctm]
|
||||
[app.common.types.text :as txt]
|
||||
[app.common.uuid :as uuid]
|
||||
[app.main.data.workspace.modifiers :as mdwm]
|
||||
[app.main.data.workspace.texts :as dwt]
|
||||
[app.main.fonts :as fonts]
|
||||
[app.main.refs :as refs]
|
||||
|
|
@ -44,7 +43,6 @@
|
|||
(gpt/point old-sr))]
|
||||
(-> shape
|
||||
(gsh/transform-shape (ctm/move modifiers deltav))
|
||||
(mdwm/update-grow-type shape)
|
||||
(dissoc :modifiers)))
|
||||
shape))
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue