0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-22 14:39:45 -05:00

Add shape handling and rendering.

And improve fill rendering.
This commit is contained in:
Andrey Antukh 2016-01-07 01:36:36 +02:00
parent d71bb9d22d
commit 7d8960a1ed
3 changed files with 20 additions and 9 deletions

View file

@ -29,6 +29,10 @@
:height [v/integer]
:lock [v/boolean]})
(def ^:static +shape-update-fill-schema+
{:fill [sc/color]
:opacity [v/number]})
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Events
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@ -202,10 +206,13 @@
(update-in state [:shapes-by-id sid]
shapes/-resize size)))))
(defn update-shape-color
[sid color]
(sc/valid? sc/color color)
(defn update-shape-fill
[sid {:keys [fill opacity] :as opts}]
(sc/validate! +shape-update-fill-schema+ opts)
(reify
rs/UpdateEvent
(-apply-update [_ state]
(assoc-in state [:shapes-by-id sid :fill] color))))
(update-in state [:shapes-by-id sid]
merge
(when fill {:fill fill})
(when opacity {:opacity opacity})))))

View file

@ -33,7 +33,8 @@
"Extract predefinet attrs from shapes."
[shape]
(select-keys shape [:rotation :lock :width :height
:view-box :x :y :cx :cy :fill]))
:view-box :x :y :cx :cy :fill
:opacity]))
(defmethod shapes/-render :builtin/icon
[{:keys [data id] :as shape} attrs]

View file

@ -47,12 +47,14 @@
(letfn [(on-color-change [event]
(let [value (dom/event->value event)
sid (:id shape)]
(-> (dw/update-shape-color sid value)
(-> (dw/update-shape-fill sid {:fill value})
(rs/emit!))))
(on-opacity-change [event]
(let [value (dom/event->value event)
value (parse-float value 1)]
(println "opacity:" value)))]
value (parse-float value 1)
sid (:id shape)]
(-> (dw/update-shape-fill sid {:opacity value})
(rs/emit!))))]
(html
[:div.element-set {:key (str (:id menu))}
[:div.element-set-title (:name menu)]
@ -83,7 +85,8 @@
{:type "range"
:min "0"
:max "1"
:step "0.02"
:value (:opacity shape "1")
:step "0.0001"
:on-change on-opacity-change}]]]])))
(defmethod -render-menu :menu/measures