0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-22 22:49:01 -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] :height [v/integer]
:lock [v/boolean]}) :lock [v/boolean]})
(def ^:static +shape-update-fill-schema+
{:fill [sc/color]
:opacity [v/number]})
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Events ;; Events
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@ -202,10 +206,13 @@
(update-in state [:shapes-by-id sid] (update-in state [:shapes-by-id sid]
shapes/-resize size))))) shapes/-resize size)))))
(defn update-shape-color (defn update-shape-fill
[sid color] [sid {:keys [fill opacity] :as opts}]
(sc/valid? sc/color color) (sc/validate! +shape-update-fill-schema+ opts)
(reify (reify
rs/UpdateEvent rs/UpdateEvent
(-apply-update [_ state] (-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." "Extract predefinet attrs from shapes."
[shape] [shape]
(select-keys shape [:rotation :lock :width :height (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 (defmethod shapes/-render :builtin/icon
[{:keys [data id] :as shape} attrs] [{:keys [data id] :as shape} attrs]

View file

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