0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-23 23:18:48 -05:00

Fix mouse mixin.

This commit is contained in:
Andrey Antukh 2015-12-22 20:25:38 +02:00
parent 3748d3c7b4
commit 3e336112ca
3 changed files with 34 additions and 32 deletions

View file

@ -18,7 +18,7 @@
;; Workspace
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defn workspace-render
(defn- workspace-render
[own projectid]
(let [workspace (rum/react wb/workspace-state )]
(html
@ -43,13 +43,13 @@
(when-not (empty? (:toolboxes workspace))
(aside))]])))
(defn workspace-will-mount
(defn- workspace-will-mount
[own]
(let [[projectid pageid] (:rum/props own)]
(rs/emit! (dw/initialize projectid pageid))
own))
(defn workspace-transfer-state
(defn- workspace-transfer-state
[old-state state]
(let [[projectid pageid] (:rum/props state)]
(rs/emit! (dw/initialize projectid pageid))

View file

@ -74,26 +74,33 @@
(defonce mouse-s (rx/dedupe mouse-bus))
(defonce mouse-position (rx/to-atom (rx/throttle 50 mouse-s)))
(def mouse-mixin
{:did-mount
(fn [own]
(defn- mouse-mixin-did-mount
[own]
(println "mouse-mixin-did-mount")
(let [canvas (util/get-ref-dom own "canvas")
key (events/listen js/document EventType.MOUSEMOVE
(fn [event]
on-mousemove (fn [event]
(let [brect (.getBoundingClientRect canvas)
offset-x (.-left brect)
offset-y (.-top brect)
x (.-clientX event)
y (.-clientY event)]
(rx/push! mouse-bus [(- x offset-x)
(- y offset-y)]))))]
(- y offset-y)])))
key (events/listen js/document
EventType.MOUSEMOVE
on-mousemove)]
(assoc own ::eventkey key)))
:did-unmount
(fn [own]
(defn- mouse-mixin-will-unmount
[own]
(println "mouse-mixin-will-unmount")
(let [key (::eventkey own)]
(events/unlistenByKey key)
(dissoc own ::eventkey)))})
(dissoc own ::eventkey)))
(def ^:static mouse-mixin
{:did-mount mouse-mixin-did-mount
:will-unmount mouse-mixin-will-unmount})
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Constants

View file

@ -15,20 +15,15 @@
;; Coordinates Debug
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defn coordenates-render
[]
(defn- coordenates-render
[own]
(let [[x y] (rum/react wb/mouse-position)]
(html
[:div
{:style {:position "absolute" :left "80px" :top "20px"}}
[:div {:style {:position "absolute" :left "80px" :top "20px"}}
[:table
[:tbody
[:tr
[:td "X:"]
[:td x]]
[:tr
[:td "Y:"]
[:td y]]]]])))
[:tr [:td "X:"] [:td x]]
[:tr [:td "Y:"] [:td y]]]]])))
(def coordinates
(util/component