mirror of
https://github.com/penpot/penpot.git
synced 2025-05-07 06:25:53 +02:00
🐛 Fixed problem with zoom and with value = 0
This commit is contained in:
parent
d17c6d8fce
commit
cd151db5ee
5 changed files with 28 additions and 15 deletions
|
@ -660,17 +660,18 @@
|
||||||
;; Normalize x/y vector coordinates because scale by 0 is infinite
|
;; Normalize x/y vector coordinates because scale by 0 is infinite
|
||||||
res-x (cond
|
res-x (cond
|
||||||
(and (< res-x 0) (> res-x -0.01)) -0.01
|
(and (< res-x 0) (> res-x -0.01)) -0.01
|
||||||
(and (> res-x 0) (< res-x 0.01)) 0.01
|
(and (>= res-x 0) (< res-x 0.01)) 0.01
|
||||||
:else res-x)
|
:else res-x)
|
||||||
|
|
||||||
res-y (cond
|
res-y (cond
|
||||||
(and (< res-y 0) (> res-y -0.01)) -0.01
|
(and (< res-y 0) (> res-y -0.01)) -0.01
|
||||||
(and (> res-y 0) (< res-y 0.01)) 0.01
|
(and (>= res-y 0) (< res-y 0.01)) 0.01
|
||||||
:else res-y)
|
:else res-y)
|
||||||
|
|
||||||
resize (gpt/point res-x res-y)
|
resize (gpt/point res-x res-y)
|
||||||
|
|
||||||
origin (:resize-origin modifiers (gpt/point 0 0))
|
origin (:resize-origin modifiers (gpt/point 0 0))
|
||||||
|
|
||||||
resize-transform (:resize-transform modifiers (gmt/matrix))
|
resize-transform (:resize-transform modifiers (gmt/matrix))
|
||||||
resize-transform-inverse (:resize-transform-inverse modifiers (gmt/matrix))
|
resize-transform-inverse (:resize-transform-inverse modifiers (gmt/matrix))
|
||||||
rt-modif (:rotation modifiers 0)
|
rt-modif (:rotation modifiers 0)
|
||||||
|
|
|
@ -1289,7 +1289,7 @@
|
||||||
(watch [_ state stream]
|
(watch [_ state stream]
|
||||||
(let [id (uuid/next)
|
(let [id (uuid/next)
|
||||||
{:keys [x y]} @ms/mouse-position
|
{:keys [x y]} @ms/mouse-position
|
||||||
width (* 7 (count text))
|
width (min (* 7 (count text)) 700)
|
||||||
height 16
|
height 16
|
||||||
shape {:id id
|
shape {:id id
|
||||||
:type :text
|
:type :text
|
||||||
|
@ -1304,7 +1304,7 @@
|
||||||
:height height}
|
:height height}
|
||||||
:width width
|
:width width
|
||||||
:height height
|
:height height
|
||||||
:grow-type :auto-width
|
:grow-type (if (> (count text) 100) :auto-height :auto-width)
|
||||||
:content (as-content text)}]
|
:content (as-content text)}]
|
||||||
(rx/of dwc/start-undo-transaction
|
(rx/of dwc/start-undo-transaction
|
||||||
dws/deselect-all
|
dws/deselect-all
|
||||||
|
|
|
@ -302,10 +302,11 @@
|
||||||
ptk/UpdateEvent
|
ptk/UpdateEvent
|
||||||
(update [_ state]
|
(update [_ state]
|
||||||
;; We commit the old transaction before starting the new one
|
;; We commit the old transaction before starting the new one
|
||||||
(-> state
|
(let [empty-tx {:undo-changes [] :redo-changes []}
|
||||||
(add-undo-entry (get-in state [:workspace-undo :transaction]))
|
current-tx (get-in state [:workspace-undo :transaction])]
|
||||||
(assoc-in [:workspace-undo :transaction] {:undo-changes []
|
(cond-> state
|
||||||
:redo-changes []})))))
|
(nil? current-tx) (assoc-in [:workspace-undo :transaction] empty-tx))))))
|
||||||
|
|
||||||
(def discard-undo-transaction
|
(def discard-undo-transaction
|
||||||
(ptk/reify ::discard-undo-transaction
|
(ptk/reify ::discard-undo-transaction
|
||||||
ptk/UpdateEvent
|
ptk/UpdateEvent
|
||||||
|
|
|
@ -294,8 +294,13 @@
|
||||||
geom/transform-shape
|
geom/transform-shape
|
||||||
(dissoc ::initialized? ::click-draw?))]
|
(dissoc ::initialized? ::click-draw?))]
|
||||||
;; Add & select the created shape to the workspace
|
;; Add & select the created shape to the workspace
|
||||||
(rx/of dw/deselect-all
|
(rx/concat
|
||||||
(dw/add-shape shape)))))))))
|
(if (= :text (:type shape))
|
||||||
|
(rx/of dwc/start-undo-transaction)
|
||||||
|
(rx/empty))
|
||||||
|
|
||||||
|
(rx/of dw/deselect-all
|
||||||
|
(dw/add-shape shape))))))))))
|
||||||
|
|
||||||
(def close-drawing-path
|
(def close-drawing-path
|
||||||
(ptk/reify ::close-drawing-path
|
(ptk/reify ::close-drawing-path
|
||||||
|
|
|
@ -57,6 +57,7 @@
|
||||||
|
|
||||||
selected (mf/deref refs/selected-shapes)
|
selected (mf/deref refs/selected-shapes)
|
||||||
edition (mf/deref refs/selected-edition)
|
edition (mf/deref refs/selected-edition)
|
||||||
|
zoom (mf/deref refs/selected-zoom)
|
||||||
edition? (= edition id)
|
edition? (= edition id)
|
||||||
selected? (and (contains? selected id)
|
selected? (and (contains? selected id)
|
||||||
(= (count selected) 1))
|
(= (count selected) 1))
|
||||||
|
@ -80,10 +81,12 @@
|
||||||
:style {:pointer-events "none"}}
|
:style {:pointer-events "none"}}
|
||||||
;; We only render the component for its side-effect
|
;; We only render the component for its side-effect
|
||||||
[:& text-shape-edit {:shape shape
|
[:& text-shape-edit {:shape shape
|
||||||
|
:zoom zoom
|
||||||
:read-only? true}]])
|
:read-only? true}]])
|
||||||
|
|
||||||
(if edition?
|
(if edition?
|
||||||
[:& text-shape-edit {:shape shape}]
|
[:& text-shape-edit {:shape shape
|
||||||
|
:zoom zoom}]
|
||||||
[:& text/text-shape {:shape shape
|
[:& text/text-shape {:shape shape
|
||||||
:selected? selected?}])]]))
|
:selected? selected?}])]]))
|
||||||
|
|
||||||
|
@ -258,7 +261,7 @@
|
||||||
|
|
||||||
(mf/defc text-shape-edit
|
(mf/defc text-shape-edit
|
||||||
{::mf/wrap [mf/memo]}
|
{::mf/wrap [mf/memo]}
|
||||||
[{:keys [shape read-only?] :or {read-only? false} :as props}]
|
[{:keys [shape zoom read-only?] :or {read-only? false} :as props}]
|
||||||
(let [{:keys [id x y width height content grow-type]} shape
|
(let [{:keys [id x y width height content grow-type]} shape
|
||||||
|
|
||||||
state (mf/use-state #(parse-content content))
|
state (mf/use-state #(parse-content content))
|
||||||
|
@ -349,15 +352,18 @@
|
||||||
|
|
||||||
;; Checks the size of the wrapper to update if it were necesary
|
;; Checks the size of the wrapper to update if it were necesary
|
||||||
(mf/use-effect
|
(mf/use-effect
|
||||||
(mf/deps props @loaded-fonts)
|
(mf/deps shape @loaded-fonts)
|
||||||
(fn []
|
(fn []
|
||||||
(timers/schedule
|
(timers/schedule
|
||||||
250 ;; We need to wait to the text to be rendered. Is there a better alternative?
|
250 ;; We need to wait to the text to be rendered. Is there a better alternative?
|
||||||
#(let [self-node (mf/ref-val self-ref)
|
#(let [self-node (mf/ref-val self-ref)
|
||||||
paragraph-node (when self-node (dom/query self-node ".paragraph-set"))]
|
paragraph-node (when self-node (dom/query self-node ".paragraph-set"))]
|
||||||
(when paragraph-node
|
(when paragraph-node
|
||||||
(let [{:keys [width height]} (dom/get-bounding-rect paragraph-node)
|
(let [
|
||||||
undo-transaction (get-in @st/state [:workspaceundo :transaction])]
|
{bb-w :width bb-h :height} (dom/get-bounding-rect paragraph-node)
|
||||||
|
width (max (/ bb-w zoom) 7)
|
||||||
|
height (max (/ bb-h zoom) 16)
|
||||||
|
undo-transaction (get-in @st/state [:workspace-undo :transaction])]
|
||||||
(when (not undo-transaction) (st/emit! dwc/start-undo-transaction))
|
(when (not undo-transaction) (st/emit! dwc/start-undo-transaction))
|
||||||
(when (or (not= (:width shape) width)
|
(when (or (not= (:width shape) width)
|
||||||
(not= (:height shape) height))
|
(not= (:height shape) height))
|
||||||
|
|
Loading…
Add table
Reference in a new issue