mirror of
https://github.com/penpot/penpot.git
synced 2026-05-23 17:03:41 +00:00
Merge pull request #6906 from penpot/andy-enhance-text-auto-resize
✨ Switch auto-width to auto-height on horizontal resize on text shapes
This commit is contained in:
commit
8d80eebeb1
@ -24,6 +24,7 @@
|
|||||||
- New typography token type - font size token [Taiga #10938](https://tree.taiga.io/project/penpot/us/10938)
|
- New typography token type - font size token [Taiga #10938](https://tree.taiga.io/project/penpot/us/10938)
|
||||||
- Hide bounding box while editing visual effects [Taiga #11576](https://tree.taiga.io/project/penpot/issue/11576)
|
- Hide bounding box while editing visual effects [Taiga #11576](https://tree.taiga.io/project/penpot/issue/11576)
|
||||||
- Improved text layer resizing: Allow double-click on text bounding box to set auto-width/auto-height [Taiga #11577](https://tree.taiga.io/project/penpot/issue/11577)
|
- Improved text layer resizing: Allow double-click on text bounding box to set auto-width/auto-height [Taiga #11577](https://tree.taiga.io/project/penpot/issue/11577)
|
||||||
|
- Improve text layer auto-resize: auto-width switches to auto-height on horizontal resize, and only switches to fixed on vertical resize [Taiga #11578](https://tree.taiga.io/project/penpot/issue/11578)
|
||||||
|
|
||||||
### :bug: Bugs fixed
|
### :bug: Bugs fixed
|
||||||
|
|
||||||
|
|||||||
@ -847,3 +847,25 @@
|
|||||||
(if undo-transation?
|
(if undo-transation?
|
||||||
(rx/of (dwu/commit-undo-transaction undo-id))
|
(rx/of (dwu/commit-undo-transaction undo-id))
|
||||||
(rx/empty))))))))
|
(rx/empty))))))))
|
||||||
|
|
||||||
|
;; Pure function to determine next grow-type for text layers
|
||||||
|
(defn next-grow-type [current-grow-type resize-direction]
|
||||||
|
(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)
|
||||||
|
(or (= current-grow-type :auto-width)
|
||||||
|
(= current-grow-type :auto-height)))
|
||||||
|
:fixed
|
||||||
|
|
||||||
|
:else
|
||||||
|
current-grow-type))
|
||||||
|
|||||||
@ -218,16 +218,23 @@
|
|||||||
(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
|
||||||
|
new-grow-type (when (cfh/text-shape? shape)
|
||||||
|
(dwm/next-grow-type (dm/get-prop shape :grow-type) resize-direction))
|
||||||
|
|
||||||
;; 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
|
||||||
change-width?
|
change-width?
|
||||||
(not (mth/close? (dm/get-prop scalev :x) 1))
|
(not (mth/close? (dm/get-prop scalev :x) 1))
|
||||||
|
|
||||||
change-height?
|
change-height?
|
||||||
(not (mth/close? (dm/get-prop scalev :y) 1))
|
(not (mth/close? (dm/get-prop scalev :y) 1))]
|
||||||
|
|
||||||
auto-width-text? (and (cfh/text-shape? shape) (= :auto-width (dm/get-prop shape :grow-type)))
|
|
||||||
auto-height-text? (and (cfh/text-shape? shape) (= :auto-height (dm/get-prop shape :grow-type)))]
|
|
||||||
|
|
||||||
(cond-> (ctm/empty)
|
(cond-> (ctm/empty)
|
||||||
(some? displacement)
|
(some? displacement)
|
||||||
@ -242,11 +249,9 @@
|
|||||||
^boolean change-height?
|
^boolean change-height?
|
||||||
(ctm/change-property :layout-item-v-sizing :fix)
|
(ctm/change-property :layout-item-v-sizing :fix)
|
||||||
|
|
||||||
(and auto-width-text? (or change-width? change-height?))
|
;; Set grow-type if it should change
|
||||||
(ctm/change-property :grow-type :fixed)
|
(and new-grow-type (not= new-grow-type (dm/get-prop shape :grow-type)))
|
||||||
|
(ctm/change-property :grow-type new-grow-type)
|
||||||
(and auto-height-text? change-height?)
|
|
||||||
(ctm/change-property :grow-type :fixed)
|
|
||||||
|
|
||||||
^boolean scale-text
|
^boolean scale-text
|
||||||
(ctm/scale-content (dm/get-prop scalev :x)))))
|
(ctm/scale-content (dm/get-prop scalev :x)))))
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user