0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-10 08:50:57 -05:00

Add basic impl for change the stroke type.

This commit is contained in:
Andrey Antukh 2016-01-28 23:28:37 +02:00
parent c2724bca5d
commit af8873470c
3 changed files with 43 additions and 15 deletions

View file

@ -227,13 +227,14 @@
(when opacity {:opacity opacity}))))) (when opacity {:opacity opacity})))))
(defn update-shape-stroke (defn update-shape-stroke
[sid {:keys [color opacity width] :as opts}] [sid {:keys [color opacity width type] :as opts}]
(sc/validate! +shape-update-stroke-schema+ opts) (sc/validate! +shape-update-stroke-schema+ opts)
(reify (reify
rs/UpdateEvent rs/UpdateEvent
(-apply-update [_ state] (-apply-update [_ state]
(update-in state [:shapes-by-id sid] (update-in state [:shapes-by-id sid]
merge merge
{:stroke-type type}
(when width {:stroke-width width}) (when width {:stroke-width width})
(when color {:stroke color}) (when color {:stroke color})
(when opacity {:stroke-opacity opacity}))))) (when opacity {:stroke-opacity opacity})))))

View file

@ -18,7 +18,24 @@
(defn- extract-style-attrs (defn- extract-style-attrs
"Extract predefinet attrs from shapes." "Extract predefinet attrs from shapes."
[shape] [shape]
(select-keys shape [:fill :opacity :stroke :stroke-opacity :stroke-width])) (select-keys shape [:fill :opacity :stroke :stroke-opacity :stroke-width
:stroke-type]))
(defn- transform-stroke-type
[attrs]
(if-let [type (:stroke-type attrs)]
(let [value (case type
:dotted "1,1"
:dashed "10,10")]
(-> attrs
(assoc :stroke-dasharray value)
(dissoc :stroke-type)))
attrs))
(defn- transform-attrs
[attrs]
(-> attrs
(transform-stroke-type)))
(defn- make-debug-attrs (defn- make-debug-attrs
[shape] [shape]
@ -35,19 +52,25 @@
[{:keys [data id] :as shape} _] [{:keys [data id] :as shape} _]
(let [key (str id) (let [key (str id)
rfm (svg/calculate-transform shape) rfm (svg/calculate-transform shape)
attrs (-> (extract-style-attrs shape)
(transform-attrs))
attrs (merge {:id key :key key :transform rfm} attrs (merge {:id key :key key :transform rfm}
;; (select-keys shape [:x :y :width :height]) ;; (select-keys shape [:x :y :width :height])
(make-debug-attrs shape) (make-debug-attrs shape)
(extract-style-attrs shape))] attrs)]
(html (html
[:g attrs data]))) [:g attrs data])))
(defmethod sh/-render :builtin/line (defmethod sh/-render :builtin/line
[{:keys [id x1 y1 x2 y2]}] [{:keys [id x1 y1 x2 y2] :as shape}]
(html (let [key (str id)
[:line {:x1 x1 :y1 y1 :x2 x2 :y2 y2 props (select-keys shape [:x1 :x2 :y2 :y1])
:stroke "black" attrs (-> (extract-style-attrs shape)
:stroke-width "1"}])) (transform-attrs)
(merge {:id key :key key})
(merge props))]
(html
[:line attrs])))
;; FIXME: the impl should be more clear. ;; FIXME: the impl should be more clear.

View file

@ -11,7 +11,7 @@
[uxbox.ui.colorpicker :refer (colorpicker)] [uxbox.ui.colorpicker :refer (colorpicker)]
[uxbox.ui.workspace.recent-colors :refer (recent-colors)] [uxbox.ui.workspace.recent-colors :refer (recent-colors)]
[uxbox.ui.workspace.base :as wb] [uxbox.ui.workspace.base :as wb]
[uxbox.util.data :refer (parse-int parse-float)])) [uxbox.util.data :refer (parse-int parse-float read-string)]))
(def +menus-map+ (def +menus-map+
{:builtin/icon [:menu/icon-measures :menu/fill :menu/stroke] {:builtin/icon [:menu/icon-measures :menu/fill :menu/stroke]
@ -66,7 +66,11 @@
(change-stroke {:opacity value}))) (change-stroke {:opacity value})))
(on-color-change [event] (on-color-change [event]
(let [value (dom/event->value event)] (let [value (dom/event->value event)]
(change-stroke {:color value})))] (change-stroke {:color value})))
(on-stroke-style-change [event]
(let [value (dom/event->value event)
value (read-string value)]
(change-stroke {:type value})))]
(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)]
@ -79,11 +83,11 @@
:min "0" :min "0"
:value (:stroke-width shape "") :value (:stroke-width shape "")
:on-change on-width-change}] :on-change on-width-change}]
[:select#style {:placeholder "Style"} [:select#style {:placeholder "Style"
[:option {:value "none"} "None"] :on-change on-stroke-style-change}
[:option {:value "none"} "Solid"] [:option {:value "nil"} "Solid"]
[:option {:value "none"} "Dotted"] [:option {:value ":dotted"} "Dotted"]
[:option {:value "none"} "Dashed"]]] [:option {:value ":dashed"} "Dashed"]]]
;; SLIDEBAR FOR ROTATION AND OPACITY ;; SLIDEBAR FOR ROTATION AND OPACITY
[:span "Color"] [:span "Color"]