mirror of
https://github.com/penpot/penpot.git
synced 2026-08-01 19:06:18 +00:00
🐛 Fix problem with text grow types
This commit is contained in:
parent
f8cebb9d63
commit
7c1205018b
@ -191,30 +191,6 @@
|
|||||||
(d/not-empty? position-data)
|
(d/not-empty? position-data)
|
||||||
(assoc :position-data 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!
|
(defn- set-wasm-props!
|
||||||
[objects prev-wasm-props wasm-props]
|
[objects prev-wasm-props wasm-props]
|
||||||
(let [;; Set old value for previous properties
|
(let [;; Set old value for previous properties
|
||||||
@ -810,9 +786,7 @@
|
|||||||
(-> shape
|
(-> shape
|
||||||
(gsh/transform-shape modifiers)
|
(gsh/transform-shape modifiers)
|
||||||
(cond-> (d/not-empty? pos-data)
|
(cond-> (d/not-empty? pos-data)
|
||||||
(assoc-position-data pos-data shape))
|
(assoc-position-data pos-data shape)))))]
|
||||||
(cond-> text-shape?
|
|
||||||
(update-grow-type shape)))))]
|
|
||||||
|
|
||||||
(rx/of (ptk/event ::dwg/move-frame-guides {:ids ids-with-children :modifiers object-modifiers})
|
(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)
|
(ptk/event ::dwcm/move-frame-comment-threads ids-with-children)
|
||||||
@ -857,23 +831,20 @@
|
|||||||
(rx/empty))))))))
|
(rx/empty))))))))
|
||||||
|
|
||||||
;; Pure function to determine next grow-type for text layers
|
;; 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
|
(cond
|
||||||
(= current-grow-type :fixed)
|
(= current-grow-type :fixed)
|
||||||
:fixed
|
:fixed
|
||||||
|
|
||||||
(and (= resize-direction :horizontal)
|
(and (not (mth/close? (:y scalev) 1.0))
|
||||||
(= current-grow-type :auto-width))
|
|
||||||
:auto-height
|
|
||||||
|
|
||||||
(and (= resize-direction :horizontal)
|
|
||||||
(= current-grow-type :auto-height))
|
|
||||||
:auto-height
|
|
||||||
|
|
||||||
(and (= resize-direction :vertical)
|
|
||||||
(or (= current-grow-type :auto-width)
|
(or (= current-grow-type :auto-width)
|
||||||
(= current-grow-type :auto-height)))
|
(= current-grow-type :auto-height)))
|
||||||
:fixed
|
:fixed
|
||||||
|
|
||||||
|
(and (not (mth/close? (:x scalev) 1.0))
|
||||||
|
(= current-grow-type :auto-width))
|
||||||
|
:auto-height
|
||||||
|
|
||||||
:else
|
:else
|
||||||
current-grow-type))
|
current-grow-type))
|
||||||
|
|||||||
@ -17,6 +17,7 @@
|
|||||||
[app.common.math :as mth]
|
[app.common.math :as mth]
|
||||||
[app.common.types.fills :as types.fills]
|
[app.common.types.fills :as types.fills]
|
||||||
[app.common.types.modifiers :as ctm]
|
[app.common.types.modifiers :as ctm]
|
||||||
|
[app.common.types.shape.layout :as ctl]
|
||||||
[app.common.types.text :as txt]
|
[app.common.types.text :as txt]
|
||||||
[app.common.uuid :as uuid]
|
[app.common.uuid :as uuid]
|
||||||
[app.main.data.event :as ev]
|
[app.main.data.event :as ev]
|
||||||
@ -581,12 +582,17 @@
|
|||||||
|
|
||||||
shape
|
shape
|
||||||
(cond-> 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})))
|
(gsh/transform-shape (ctm/change-dimensions-modifiers shape :width new-width {:ignore-lock? true})))
|
||||||
|
|
||||||
shape
|
shape
|
||||||
(cond-> 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)))
|
(or (= grow-type :auto-height) (= grow-type :auto-width)))
|
||||||
(gsh/transform-shape (ctm/change-dimensions-modifiers shape :height new-height {:ignore-lock? true})))]
|
(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))]
|
(let [ids (into #{} (filter changed-text?) (keys props))]
|
||||||
(rx/of (dwu/start-undo-transaction undo-id)
|
(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
|
:stack-undo? true
|
||||||
:ignore-touched true})
|
:ignore-touched true})
|
||||||
(ptk/data-event :layout/update {:ids ids})
|
(ptk/data-event :layout/update {:ids ids})
|
||||||
|
|||||||
@ -218,15 +218,10 @@
|
|||||||
(gpt/add resize-origin displacement)
|
(gpt/add resize-origin displacement)
|
||||||
resize-origin)
|
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
|
;; Calculate new grow-type for text layers
|
||||||
new-grow-type (when (cfh/text-shape? shape)
|
new-grow-type
|
||||||
(dwm/next-grow-type (dm/get-prop shape :grow-type) resize-direction))
|
(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
|
;; When the horizontal/vertical scale a flex children with auto/fill
|
||||||
;; we change it too fixed
|
;; we change it too fixed
|
||||||
|
|||||||
@ -16,7 +16,6 @@
|
|||||||
[app.common.types.modifiers :as ctm]
|
[app.common.types.modifiers :as ctm]
|
||||||
[app.common.types.text :as txt]
|
[app.common.types.text :as txt]
|
||||||
[app.common.uuid :as uuid]
|
[app.common.uuid :as uuid]
|
||||||
[app.main.data.workspace.modifiers :as mdwm]
|
|
||||||
[app.main.data.workspace.texts :as dwt]
|
[app.main.data.workspace.texts :as dwt]
|
||||||
[app.main.fonts :as fonts]
|
[app.main.fonts :as fonts]
|
||||||
[app.main.refs :as refs]
|
[app.main.refs :as refs]
|
||||||
@ -44,7 +43,6 @@
|
|||||||
(gpt/point old-sr))]
|
(gpt/point old-sr))]
|
||||||
(-> shape
|
(-> shape
|
||||||
(gsh/transform-shape (ctm/move modifiers deltav))
|
(gsh/transform-shape (ctm/move modifiers deltav))
|
||||||
(mdwm/update-grow-type shape)
|
|
||||||
(dissoc :modifiers)))
|
(dissoc :modifiers)))
|
||||||
shape))
|
shape))
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user