mirror of
https://github.com/penpot/penpot.git
synced 2025-08-07 14:38:33 +02:00
Improve icon rendering.
This commit is contained in:
parent
50c0b9420b
commit
517b3f6db3
2 changed files with 34 additions and 10 deletions
|
@ -1,17 +1,35 @@
|
||||||
(ns uxbox.shapes
|
(ns uxbox.shapes
|
||||||
(:require [sablono.core :refer-macros [html]]))
|
(:require [sablono.core :refer-macros [html]]
|
||||||
|
[uxbox.util.data :refer (remove-nil-vals)]))
|
||||||
|
|
||||||
(defmulti render
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
(fn [shape & params]
|
;; Api
|
||||||
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
||||||
|
(defmulti -render
|
||||||
|
(fn [shape attrs]
|
||||||
(:type shape)))
|
(:type shape)))
|
||||||
|
|
||||||
(defmethod render :builtin/icon
|
(defn render
|
||||||
[{:keys [data width height view-box]} & [attrs]]
|
([shape] (-render shape nil))
|
||||||
(let [attrs (merge
|
([shape attrs] (-render shape attrs)))
|
||||||
(when width {:width width})
|
|
||||||
(when height {:height height})
|
|
||||||
(when view-box {:viewBox (apply str (interpose " " view-box))})
|
|
||||||
attrs)]
|
|
||||||
|
|
||||||
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
;; Implementation
|
||||||
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
||||||
|
(defn transform-attrs
|
||||||
|
[{:keys [view-box] :as data}]
|
||||||
|
(if view-box
|
||||||
|
(assoc data :view-box (apply str (interpose " " view-box)))
|
||||||
|
data))
|
||||||
|
|
||||||
|
(defmethod -render :builtin/icon
|
||||||
|
[{:keys [data width height view-box] :as shape} attrs]
|
||||||
|
(let [attrs (as-> shape $
|
||||||
|
(select-keys $ [:width :height :view-box])
|
||||||
|
(remove-nil-vals $)
|
||||||
|
(merge $ attrs)
|
||||||
|
(transform-attrs $))]
|
||||||
(html
|
(html
|
||||||
[:svg attrs data])))
|
[:svg attrs data])))
|
||||||
|
|
|
@ -11,3 +11,9 @@
|
||||||
(persistent! data)))
|
(persistent! data)))
|
||||||
|
|
||||||
(def ^:static index-by-id #(index-by % :id))
|
(def ^:static index-by-id #(index-by % :id))
|
||||||
|
|
||||||
|
(defn remove-nil-vals
|
||||||
|
"Given a map, return a map removing key-value
|
||||||
|
pairs when value is `nil`."
|
||||||
|
[data]
|
||||||
|
(into {} (remove (comp nil? second) data)))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue