Add resize handlers to element options.

This commit is contained in:
Andrey Antukh 2016-01-06 21:05:36 +02:00
parent da5d9c2422
commit ca2c76325d

View file

@ -1,11 +1,15 @@
(ns uxbox.ui.workspace.options (ns uxbox.ui.workspace.options
(:require [sablono.core :as html :refer-macros [html]] (:require [sablono.core :as html :refer-macros [html]]
[rum.core :as rum] [rum.core :as rum]
[uxbox.rstore :as rs]
[uxbox.shapes :as shapes] [uxbox.shapes :as shapes]
[uxbox.data.workspace :as dw]
[uxbox.ui.icons :as i] [uxbox.ui.icons :as i]
[uxbox.ui.util :as util] [uxbox.ui.util :as util]
[uxbox.ui.mixins :as mx] [uxbox.ui.mixins :as mx]
[uxbox.ui.workspace.base :as wb])) [uxbox.ui.dom :as dom]
[uxbox.ui.workspace.base :as wb]
[uxbox.util.data :refer (parse-int)]))
(def +menus-map+ (def +menus-map+
{:builtin/icon [:menu/measures :menu/fill] {:builtin/icon [:menu/measures :menu/fill]
@ -70,6 +74,19 @@
(defmethod -render-menu :menu/measures (defmethod -render-menu :menu/measures
[menu own shape] [menu own shape]
(letfn [(on-width-change [event]
(let [value (dom/event->value event)
value (parse-int value 0)
sid (:id shape)]
(-> (dw/update-shape-size sid {:width value})
(rs/emit!))))
(on-height-change [event]
(let [value (dom/event->value event)
value (parse-int value 0)
sid (:id shape)]
(println value)
(-> (dw/update-shape-size sid {:height 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)]
@ -80,14 +97,16 @@
[:input#width.input-text [:input#width.input-text
{:placeholder "Width" {:placeholder "Width"
:type "number" :type "number"
:min "0"
:value (:width shape) :value (:width shape)
:on-change (constantly nil)}] :on-change on-width-change}]
[:div.lock-size i/lock] [:div.lock-size i/lock]
[:input#width.input-text [:input#width.input-text
{:placeholder "Height" {:placeholder "Height"
:type "number" :type "number"
:min "0"
:value (:height shape) :value (:height shape)
:on-change (constantly nil)}]] :on-change on-height-change}]]
[:span "Position"] [:span "Position"]
[:div.row-flex [:div.row-flex
@ -104,7 +123,7 @@
[:span "Rotation"] [:span "Rotation"]
[:div.row-flex [:div.row-flex
[:input.slidebar {:type "range"}]]]])) [:input.slidebar {:type "range"}]]]])))
(defn element-opts-render (defn element-opts-render
[own shape] [own shape]