mirror of
https://github.com/penpot/penpot.git
synced 2025-05-07 11:55:53 +02:00
Add better type hierarchy.
This commit is contained in:
parent
c4b7eb0368
commit
b4b98428d4
1 changed files with 14 additions and 17 deletions
|
@ -9,12 +9,13 @@
|
||||||
|
|
||||||
(def ^:static +hierarchy+
|
(def ^:static +hierarchy+
|
||||||
(as-> (make-hierarchy) $
|
(as-> (make-hierarchy) $
|
||||||
(derive $ :builtin/icon ::shape)
|
(derive $ ::rect ::shape)
|
||||||
(derive $ :builtin/rect ::shape)
|
(derive $ :builtin/icon ::rect)
|
||||||
|
(derive $ :builtin/rect ::rect)
|
||||||
(derive $ :builtin/line ::shape)
|
(derive $ :builtin/line ::shape)
|
||||||
(derive $ :builtin/circle ::shape)
|
(derive $ :builtin/circle ::shape)
|
||||||
(derive $ :builtin/text ::shape)
|
(derive $ :builtin/text ::shape)
|
||||||
(derive $ :builtin/group ::shape)))
|
(derive $ :builtin/group ::rect)))
|
||||||
|
|
||||||
(defn shape?
|
(defn shape?
|
||||||
[type]
|
[type]
|
||||||
|
@ -107,13 +108,7 @@
|
||||||
[shape _]
|
[shape _]
|
||||||
(throw (ex-info "Not implemented" (select-keys shape [:type]))))
|
(throw (ex-info "Not implemented" (select-keys shape [:type]))))
|
||||||
|
|
||||||
(defmethod -resize' :builtin/icon
|
(defmethod -resize' ::rect
|
||||||
[shape [width height]]
|
|
||||||
(merge shape
|
|
||||||
(when width {:width width})
|
|
||||||
(when height {:height height})))
|
|
||||||
|
|
||||||
(defmethod -resize' :builtin/group
|
|
||||||
[shape [width height]]
|
[shape [width height]]
|
||||||
(merge shape
|
(merge shape
|
||||||
(when width {:width width})
|
(when width {:width width})
|
||||||
|
@ -125,18 +120,12 @@
|
||||||
|
|
||||||
;; Move
|
;; Move
|
||||||
|
|
||||||
(defmethod -move ::shape
|
(defmethod -move ::rect
|
||||||
[shape {:keys [dx dy] :as opts}]
|
[shape {:keys [dx dy] :as opts}]
|
||||||
(assoc shape
|
(assoc shape
|
||||||
:x (+ (:x shape) dx)
|
:x (+ (:x shape) dx)
|
||||||
:y (+ (:y shape) dy)))
|
:y (+ (:y shape) dy)))
|
||||||
|
|
||||||
(defmethod -move :builtin/group
|
|
||||||
[shape {:keys [dx dy] :as opts}]
|
|
||||||
(assoc shape
|
|
||||||
:dx (+ (:dx shape 0) dx)
|
|
||||||
:dy (+ (:dy shape 0) dy)))
|
|
||||||
|
|
||||||
(defmethod -move :builtin/line
|
(defmethod -move :builtin/line
|
||||||
[shape {:keys [dx dy] :as opts}]
|
[shape {:keys [dx dy] :as opts}]
|
||||||
(assoc shape
|
(assoc shape
|
||||||
|
@ -145,6 +134,10 @@
|
||||||
:x2 (+ (:x2 shape) dx)
|
:x2 (+ (:x2 shape) dx)
|
||||||
:y2 (+ (:y2 shape) dy)))
|
:y2 (+ (:y2 shape) dy)))
|
||||||
|
|
||||||
|
(defmethod -move :default
|
||||||
|
[shape _]
|
||||||
|
(throw (ex-info "Not implemented" (select-keys shape [:type]))))
|
||||||
|
|
||||||
(defmethod -rotate ::shape
|
(defmethod -rotate ::shape
|
||||||
[shape rotation]
|
[shape rotation]
|
||||||
(assoc shape :rotation rotation))
|
(assoc shape :rotation rotation))
|
||||||
|
@ -184,6 +177,10 @@
|
||||||
(merge $ {:width width :height height :x x :y y})
|
(merge $ {:width width :height height :x x :y y})
|
||||||
(container-rect $))))
|
(container-rect $))))
|
||||||
|
|
||||||
|
(defmethod -outer-rect :default
|
||||||
|
[shape _]
|
||||||
|
(throw (ex-info "Not implemented" (select-keys shape [:type]))))
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
;; Helpers
|
;; Helpers
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
Loading…
Add table
Reference in a new issue