0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-02-09 08:38:15 -05:00
penpot/frontend/uxbox/shapes.cljs

53 lines
1.4 KiB
Text
Raw Normal View History

(ns uxbox.shapes)
2015-12-29 23:39:31 +02:00
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Types
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(def ^:static ^:private +hierarchy+
(as-> (make-hierarchy) $
(derive $ :builtin/icon ::shape)
(derive $ :builtin/icon-svg ::shape)
(derive $ :builtin/icon-group ::shape)))
(defn shape?
[type]
{:pre [(keyword? type)]}
(isa? +hierarchy+ type ::shape))
2015-12-26 15:18:36 +02:00
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Api
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2015-12-30 01:25:26 +02:00
(declare -render)
2015-12-26 15:18:36 +02:00
(defn render
([shape] (-render shape nil))
([shape attrs] (-render shape attrs)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Implementation Api
2015-12-26 15:18:36 +02:00
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2015-12-30 01:25:26 +02:00
(defn- dispatch-by-type
[shape & params]
2015-12-30 01:25:26 +02:00
(:type shape))
(defmulti -render
dispatch-by-type
:hierarchy #'+hierarchy+)
(defmulti -move
dispatch-by-type
:hierarchy #'+hierarchy+)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Implementation
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2015-12-30 01:25:26 +02:00
(defmethod -move ::shape
[shape {:keys [dx dy] :as opts}]
(assoc shape
:x (+ (:x shape) dx)
:y (+ (:y shape) dy)))