mirror of
https://github.com/penpot/penpot.git
synced 2025-05-31 14:36:13 +02:00
Make icon rotation behave in the same way as rect.
This commit is contained in:
parent
653e0b5669
commit
8e8f230504
1 changed files with 19 additions and 7 deletions
|
@ -30,19 +30,31 @@
|
||||||
|
|
||||||
;; --- Icon Shape
|
;; --- Icon Shape
|
||||||
|
|
||||||
|
(defn- rotate
|
||||||
|
;; TODO: revisit, i'm not sure if this function is duplicated.
|
||||||
|
[mt {:keys [x1 y1 x2 y2 width height rotation] :as shape}]
|
||||||
|
(let [x-center (+ x1 (/ width 2))
|
||||||
|
y-center (+ y1 (/ height 2))
|
||||||
|
center (gpt/point x-center y-center)]
|
||||||
|
(gmt/rotate* mt rotation center)))
|
||||||
|
|
||||||
|
|
||||||
(mx/defc icon-shape
|
(mx/defc icon-shape
|
||||||
{:mixins [mx/static]}
|
{:mixins [mx/static]}
|
||||||
[{:keys [id content metadata rotation x1 y1 modifiers] :as shape}]
|
[{:keys [id content metadata rotation x1 y1 modifiers] :as shape}]
|
||||||
(let [{:keys [width height]} (geom/size shape)
|
(let [{:keys [resize displacement]} modifiers
|
||||||
{:keys [resize displacement]} modifiers
|
|
||||||
|
|
||||||
view-box (apply str (interpose " " (:view-box metadata)))
|
|
||||||
|
|
||||||
xfmt (cond-> (gmt/matrix)
|
xfmt (cond-> (gmt/matrix)
|
||||||
resize (gmt/multiply resize)
|
|
||||||
displacement (gmt/multiply displacement)
|
displacement (gmt/multiply displacement)
|
||||||
rotation (gmt/rotate* rotation (gpt/point (+ x1 (/ width 2))
|
resize (gmt/multiply resize))
|
||||||
(+ y1 (/ height 2)))))
|
|
||||||
|
{:keys [x1 y1 width height] :as shape} (-> (geom/transform shape xfmt)
|
||||||
|
(geom/size))
|
||||||
|
|
||||||
|
view-box (apply str (interpose " " (:view-box metadata)))
|
||||||
|
xfmt (cond-> (gmt/matrix)
|
||||||
|
(pos? rotation) (rotate shape))
|
||||||
|
|
||||||
props {:id (str id)
|
props {:id (str id)
|
||||||
:x x1
|
:x x1
|
||||||
:y y1
|
:y y1
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue