mirror of
https://github.com/penpot/penpot.git
synced 2025-06-16 07:21:39 +02:00
🐛 Fix problem with auto-height text resize
This commit is contained in:
parent
ff9b2090cf
commit
ade13d3bca
4 changed files with 82 additions and 43 deletions
|
@ -317,33 +317,47 @@
|
||||||
modif-tree)))
|
modif-tree)))
|
||||||
|
|
||||||
(defn set-objects-modifiers
|
(defn set-objects-modifiers
|
||||||
[modif-tree objects ignore-constraints snap-pixel?]
|
([modif-tree objects ignore-constraints snap-pixel?]
|
||||||
|
(set-objects-modifiers nil modif-tree objects ignore-constraints snap-pixel?))
|
||||||
|
|
||||||
(let [objects (apply-structure-modifiers objects modif-tree)
|
([old-modif-tree modif-tree objects ignore-constraints snap-pixel?]
|
||||||
|
(let [objects (-> objects
|
||||||
|
(cond-> (some? old-modif-tree)
|
||||||
|
(apply-structure-modifiers old-modif-tree))
|
||||||
|
(apply-structure-modifiers modif-tree))
|
||||||
|
|
||||||
bounds (d/lazy-map (keys objects) #(dm/get-in objects [% :points]))
|
bounds (d/lazy-map (keys objects) #(dm/get-in objects [% :points]))
|
||||||
shapes-tree (resolve-tree-sequence (-> modif-tree keys set) objects)
|
bounds (cond-> bounds
|
||||||
|
(some? old-modif-tree)
|
||||||
|
(transform-bounds objects old-modif-tree))
|
||||||
|
|
||||||
;; Calculate the input transformation and constraints
|
shapes-tree (resolve-tree-sequence (-> modif-tree keys set) objects)
|
||||||
modif-tree (reduce #(propagate-modifiers-constraints objects bounds ignore-constraints %1 %2) modif-tree shapes-tree)
|
|
||||||
bounds (transform-bounds bounds objects modif-tree shapes-tree)
|
|
||||||
|
|
||||||
[modif-tree-layout sizing-auto-layouts]
|
;; Calculate the input transformation and constraints
|
||||||
(reduce #(propagate-modifiers-layout objects bounds ignore-constraints %1 %2) [{} #{}] shapes-tree)
|
modif-tree (reduce #(propagate-modifiers-constraints objects bounds ignore-constraints %1 %2) modif-tree shapes-tree)
|
||||||
|
bounds (transform-bounds bounds objects modif-tree shapes-tree)
|
||||||
|
|
||||||
modif-tree (merge-modif-tree modif-tree modif-tree-layout)
|
[modif-tree-layout sizing-auto-layouts]
|
||||||
|
(reduce #(propagate-modifiers-layout objects bounds ignore-constraints %1 %2) [{} #{}] shapes-tree)
|
||||||
|
|
||||||
;; Calculate hug layouts positions
|
modif-tree (merge-modif-tree modif-tree modif-tree-layout)
|
||||||
bounds (transform-bounds bounds objects modif-tree-layout shapes-tree)
|
|
||||||
|
|
||||||
modif-tree
|
;; Calculate hug layouts positions
|
||||||
(-> modif-tree
|
bounds (transform-bounds bounds objects modif-tree-layout shapes-tree)
|
||||||
(sizing-auto-modifiers sizing-auto-layouts objects bounds ignore-constraints))
|
|
||||||
|
|
||||||
modif-tree
|
modif-tree
|
||||||
(cond-> modif-tree
|
(-> modif-tree
|
||||||
snap-pixel? (gpp/adjust-pixel-precision objects))]
|
(sizing-auto-modifiers sizing-auto-layouts objects bounds ignore-constraints))
|
||||||
|
|
||||||
;;#?(:cljs
|
modif-tree
|
||||||
;; (.log js/console ">result" (modif->js modif-tree objects)))
|
(if old-modif-tree
|
||||||
modif-tree))
|
(merge-modif-tree old-modif-tree modif-tree)
|
||||||
|
modif-tree)
|
||||||
|
|
||||||
|
modif-tree
|
||||||
|
(cond-> modif-tree
|
||||||
|
snap-pixel? (gpp/adjust-pixel-precision objects))]
|
||||||
|
|
||||||
|
;;#?(:cljs
|
||||||
|
;; (.log js/console ">result" (modif->js modif-tree objects)))
|
||||||
|
modif-tree)))
|
||||||
|
|
|
@ -190,26 +190,27 @@
|
||||||
[(get-in objects [k :name]) v]))
|
[(get-in objects [k :name]) v]))
|
||||||
modif-tree)))
|
modif-tree)))
|
||||||
|
|
||||||
|
(defn apply-text-modifier
|
||||||
|
[shape {:keys [width height]}]
|
||||||
|
(cond-> shape
|
||||||
|
(some? width)
|
||||||
|
(assoc :width width)
|
||||||
|
|
||||||
|
(some? height)
|
||||||
|
(assoc :height height)
|
||||||
|
|
||||||
|
(or (some? width) (some? height))
|
||||||
|
(cts/setup-rect-selrect)))
|
||||||
|
|
||||||
(defn apply-text-modifiers
|
(defn apply-text-modifiers
|
||||||
[objects text-modifiers]
|
[objects text-modifiers]
|
||||||
(letfn [(apply-text-modifier
|
(loop [modifiers (seq text-modifiers)
|
||||||
[shape {:keys [width height]}]
|
result objects]
|
||||||
(cond-> shape
|
(if (empty? modifiers)
|
||||||
(some? width)
|
result
|
||||||
(assoc :width width)
|
(let [[id text-modifier] (first modifiers)]
|
||||||
|
(recur (rest modifiers)
|
||||||
(some? height)
|
(update objects id apply-text-modifier text-modifier))))))
|
||||||
(assoc :height height)
|
|
||||||
|
|
||||||
(or (some? width) (some? height))
|
|
||||||
(cts/setup-rect-selrect)))]
|
|
||||||
(loop [modifiers (seq text-modifiers)
|
|
||||||
result objects]
|
|
||||||
(if (empty? modifiers)
|
|
||||||
result
|
|
||||||
(let [[id text-modifier] (first modifiers)]
|
|
||||||
(recur (rest modifiers)
|
|
||||||
(update objects id apply-text-modifier text-modifier)))))))
|
|
||||||
|
|
||||||
#_(defn apply-path-modifiers
|
#_(defn apply-path-modifiers
|
||||||
[objects path-modifiers]
|
[objects path-modifiers]
|
||||||
|
@ -242,6 +243,33 @@
|
||||||
;;(apply-path-modifiers $ (get-in state [:workspace-local :edit-path]))
|
;;(apply-path-modifiers $ (get-in state [:workspace-local :edit-path]))
|
||||||
(gsh/set-objects-modifiers modif-tree $ ignore-constraints snap-pixel?)))))
|
(gsh/set-objects-modifiers modif-tree $ ignore-constraints snap-pixel?)))))
|
||||||
|
|
||||||
|
(defn- calculate-update-modifiers
|
||||||
|
[old-modif-tree state ignore-constraints ignore-snap-pixel modif-tree]
|
||||||
|
(let [objects
|
||||||
|
(wsh/lookup-page-objects state)
|
||||||
|
|
||||||
|
snap-pixel?
|
||||||
|
(and (not ignore-snap-pixel) (contains? (:workspace-layout state) :snap-pixel-grid))
|
||||||
|
|
||||||
|
objects
|
||||||
|
(-> objects
|
||||||
|
(apply-text-modifiers (get state :workspace-text-modifier)))]
|
||||||
|
|
||||||
|
(gsh/set-objects-modifiers old-modif-tree modif-tree objects ignore-constraints snap-pixel?)))
|
||||||
|
|
||||||
|
(defn update-modifiers
|
||||||
|
([modif-tree]
|
||||||
|
(update-modifiers modif-tree false))
|
||||||
|
|
||||||
|
([modif-tree ignore-constraints]
|
||||||
|
(update-modifiers modif-tree ignore-constraints false))
|
||||||
|
|
||||||
|
([modif-tree ignore-constraints ignore-snap-pixel]
|
||||||
|
(ptk/reify ::update-modifiers
|
||||||
|
ptk/UpdateEvent
|
||||||
|
(update [_ state]
|
||||||
|
(update state :workspace-modifiers calculate-update-modifiers state ignore-constraints ignore-snap-pixel modif-tree)))))
|
||||||
|
|
||||||
(defn set-modifiers
|
(defn set-modifiers
|
||||||
([modif-tree]
|
([modif-tree]
|
||||||
(set-modifiers modif-tree false))
|
(set-modifiers modif-tree false))
|
||||||
|
|
|
@ -408,8 +408,7 @@
|
||||||
(not (mth/close? (:height props) current-height))))
|
(not (mth/close? (:height props) current-height))))
|
||||||
|
|
||||||
(let [modif-tree (dwm/create-modif-tree [id] (ctm/reflow-modifiers))]
|
(let [modif-tree (dwm/create-modif-tree [id] (ctm/reflow-modifiers))]
|
||||||
(->> (rx/of (dwm/set-modifiers modif-tree))
|
(rx/of (dwm/update-modifiers modif-tree)))
|
||||||
(rx/observe-on :async)))
|
|
||||||
(rx/empty)))))))
|
(rx/empty)))))))
|
||||||
|
|
||||||
(defn clean-text-modifier
|
(defn clean-text-modifier
|
||||||
|
|
|
@ -8,8 +8,6 @@
|
||||||
(:require
|
(:require
|
||||||
[app.common.data :as d]
|
[app.common.data :as d]
|
||||||
[app.common.data.macros :as dm]
|
[app.common.data.macros :as dm]
|
||||||
[app.common.geom.matrix :as gmt]
|
|
||||||
[app.common.geom.point :as gpt]
|
|
||||||
[app.common.geom.shapes :as gsh]
|
[app.common.geom.shapes :as gsh]
|
||||||
[app.config :as cf]
|
[app.config :as cf]
|
||||||
[app.main.ui.context :as muc]
|
[app.main.ui.context :as muc]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue