mirror of
https://github.com/penpot/penpot.git
synced 2026-08-06 21:08:34 +00:00
Add helper for resolve/translate shape position into real canvas coords.
This is necesary to know the real shape position in a canves when shape is part of group or subgroup and each group has its own coordinate system.
This commit is contained in:
parent
b65e0d754a
commit
e353d67b02
@ -1,6 +1,7 @@
|
|||||||
(ns uxbox.shapes
|
(ns uxbox.shapes
|
||||||
(:require [uxbox.util.matrix :as mtx]
|
(:require [uxbox.util.matrix :as mtx]
|
||||||
[uxbox.util.math :as mth]))
|
[uxbox.util.math :as mth]
|
||||||
|
[uxbox.state :as st]))
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
;; Types
|
;; Types
|
||||||
@ -148,3 +149,18 @@
|
|||||||
y' (:y shape)]
|
y' (:y shape)]
|
||||||
(assoc shape :x (- x' x) :y (- y' y))))
|
(assoc shape :x (- x' x) :y (- y' y))))
|
||||||
|
|
||||||
|
(defn resolve-position
|
||||||
|
"Recursively resolve the real shape position in
|
||||||
|
the canvas."
|
||||||
|
[{:keys [width height x y group] :as shape}]
|
||||||
|
(if group
|
||||||
|
(let [group (get-in @st/state [:shapes-by-id group])
|
||||||
|
result (resolve-position
|
||||||
|
(assoc group
|
||||||
|
:x (+ (:x group) x)
|
||||||
|
:y (+ (:y group) y)))]
|
||||||
|
(assoc shape
|
||||||
|
:x (:x result)
|
||||||
|
:y (:y result)))
|
||||||
|
shape))
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user