penpot/src/uxbox/ui/workspace/toolboxes/drawtools.cljs
2016-01-24 01:08:09 +02:00

63 lines
2 KiB
Clojure

(ns uxbox.ui.workspace.toolboxes.drawtools
(:require [sablono.core :as html :refer-macros [html]]
[rum.core :as rum]
[cats.labs.lens :as l]
[uxbox.router :as r]
[uxbox.rstore :as rs]
[uxbox.state :as st]
[uxbox.shapes :as shapes]
[uxbox.library :as library]
[uxbox.util.data :refer (read-string)]
[uxbox.data.workspace :as dw]
[uxbox.ui.workspace.base :as wb]
[uxbox.ui.icons :as i]
[uxbox.ui.mixins :as mx]
[uxbox.ui.dom :as dom]))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Draw Tools
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(def ^:staric +draw-tools+
{:rect
{:icon i/box
:help "Box (Ctrl + B)"
:priority 10}
:circle
{:icon i/circle
:help "Circle (Ctrl + E)"
:priority 20}
:line
{:icon i/line
:help "Line (Ctrl + L)"
:priority 30}})
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Draw Tool Box
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defn draw-tools-render
[open-toolboxes]
(let [workspace (rum/react wb/workspace-l)
close #(rs/emit! (dw/toggle-toolbox :draw))
tools (->> (into [] +draw-tools+)
(sort-by (comp :priority second)))]
(html
[:div#form-tools.tool-window
[:div.tool-window-bar
[:div.tool-window-icon i/window]
[:span "Tools"]
[:div.tool-window-close {:on-click close} i/close]]
[:div.tool-window-content
(for [[key props] tools]
[:div.tool-btn.tooltip.tooltip-hover
{:alt (:help props)
:key (name key)
:on-click (constantly nil)}
(:icon props)])]])))
(def ^:static draw-toolbox
(mx/component
{:render draw-tools-render
:name "draw-tools"
:mixins [mx/static rum/reactive]}))