Fix panel resizing

This commit is contained in:
chris (daiyi) 2017-08-09 16:16:07 +02:00
parent e70c86cbe7
commit bec8b73789
1 changed files with 40 additions and 38 deletions

View File

@ -244,11 +244,12 @@
;; Add clear button ;; Add clear button
;; Filter out different trace types ;; Filter out different trace types
(let [position (r/atom :right) (let [position (r/atom :right)
size (r/atom 0.35) panel-width-ratio (r/atom 0.35)
showing? (r/atom false) showing? (r/atom false)
dragging? (r/atom false) dragging? (r/atom false)
pin-to-bottom? (r/atom true) pin-to-bottom? (r/atom true)
selected-tab (r/atom :traces) selected-tab (r/atom :traces)
window-width js/window.innerWidth
handle-keys (fn [e] handle-keys (fn [e]
(let [combo-key? (or (.-ctrlKey e) (.-metaKey e) (.-altKey e)) (let [combo-key? (or (.-ctrlKey e) (.-metaKey e) (.-altKey e))
tag-name (.-tagName (.-target e)) tag-name (.-tagName (.-target e))
@ -261,36 +262,37 @@
(if @showing? (if @showing?
(enable-tracing!) (enable-tracing!)
(disable-tracing!)) (disable-tracing!))
(.preventDefault e))))))] (.preventDefault e))))))
(r/create-class handle-mousemove (fn [e]
{:component-will-mount #(js/window.addEventListener "keydown" handle-keys)
:component-will-unmount #(js/window.removeEventListener "keydown" handle-keys)
:display-name "devtools outer"
:reagent-render (fn []
(let [draggable-area 10
full-width js/window.innerWidth
full-height js/window.innerHeight
left (if @showing? (str (* 100 (- 1 @size)) "%")
(str full-width "px"))
transition (if @showing?
ease-transition
(str ease-transition ", opacity 0.01s linear 0.2s"))]
[:div.panel-wrapper
{:style {:position "fixed" :width "0px" :height "0px" :top "0px" :left "0px" :z-index 99999999}}
[:div.panel
{:style {:position "fixed" :z-index 1 :box-shadow "rgba(0, 0, 0, 0.298039) 0px 0px 4px" :background "white"
:left left :top "0px" :width (str (* 100 @size) "%") :height "100%"
:transition transition}}
[:div.panel-resizer {:style (resizer-style draggable-area)
:on-mouse-down #(reset! dragging? true)
:on-mouse-up #(reset! dragging? false)
:on-mouse-move (fn [e]
(when @dragging? (when @dragging?
(let [x (.-clientX e) (let [x (.-clientX e)
y (.-clientY e)] y (.-clientY e)]
(.preventDefault e) (.preventDefault e)
(reset! size (/ (- full-width x) (reset! panel-width-ratio (/ (- window-width x) window-width)))))]
full-width)))))}] (r/create-class
{:component-will-mount (fn []
(js/window.addEventListener "keydown" handle-keys)
(js/window.addEventListener "mousemove" handle-mousemove))
:component-will-unmount (fn []
(js/window.removeEventListener "keydown" handle-keys)
(js/window.removeEventListener "mousemove" handle-mousemove))
:display-name "devtools outer"
:reagent-render (fn []
(let [draggable-area 10
left (if @showing? (str (* 100 (- 1 @panel-width-ratio)) "%")
(str window-width "px"))
transition (if @dragging?
""
ease-transition)]
[:div.panel-wrapper
{:style {:position "fixed" :width "0px" :height "0px" :top "0px" :left "0px" :z-index 99999999}}
[:div.panel
{:style {:position "fixed" :z-index 1 :box-shadow "rgba(0, 0, 0, 0.3) 0px 0px 4px" :background "white"
:left left :top "0px" :width (str (inc (int (* 100 @panel-width-ratio))) "%") :height "100%"
:transition transition}}
[:div.panel-resizer {:style (resizer-style draggable-area)
:on-mouse-down #(reset! dragging? true)
:on-mouse-up #(reset! dragging? false)}]
[:div.panel-content [:div.panel-content
{:style {:width "100%" :height "100%" :display "flex" :flex-direction "column"}} {:style {:width "100%" :height "100%" :display "flex" :flex-direction "column"}}
[:div.panel-content-top [:div.panel-content-top