mirror of
https://github.com/penpot/penpot.git
synced 2026-03-06 02:01:09 +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:
@@ -1,6 +1,7 @@
|
||||
(ns uxbox.shapes
|
||||
(:require [uxbox.util.matrix :as mtx]
|
||||
[uxbox.util.math :as mth]))
|
||||
[uxbox.util.math :as mth]
|
||||
[uxbox.state :as st]))
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; Types
|
||||
@@ -148,3 +149,18 @@
|
||||
y' (:y shape)]
|
||||
(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))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user