From cb3a099fef3e3a16e38c7000348f5b2e90592cbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Espino?= Date: Mon, 11 Apr 2016 22:09:46 +0200 Subject: [PATCH] Step based zoom (#12) --- src/uxbox/data/workspace.cljs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/uxbox/data/workspace.cljs b/src/uxbox/data/workspace.cljs index 9855ffc88..b4ed05720 100644 --- a/src/uxbox/data/workspace.cljs +++ b/src/uxbox/data/workspace.cljs @@ -18,6 +18,7 @@ [uxbox.data.shapes :as uds] [uxbox.util.datetime :as dt] [uxbox.util.math :as mth] + [uxbox.util.data :refer (index-of)] [uxbox.util.geom.point :as gpt] [uxbox.util.workers :as uw])) @@ -25,6 +26,12 @@ (declare initialize-alignment-index) +(defonce zoom-levels [0.20 0.21 0.22 0.23 0.24 0.25 0.27 0.28 0.30 0.32 0.34 + 0.36 0.38 0.40 0.42 0.44 0.46 0.48 0.51 0.54 0.57 0.60 + 0.63 0.66 0.69 0.73 0.77 0.81 0.85 0.90 0.95 1.00 1.05 + 1.10 1.15 1.21 1.27 1.33 1.40 1.47 1.54 1.62 1.70 1.78 + 1.87 1.96 2.06 2.16 2.27 2.38 2.50 2.62 2.75 2.88 3.00]) + (defrecord InitializeWorkspace [project page] rs/UpdateEvent (-apply-update [_ state] @@ -120,7 +127,7 @@ (defrecord IncreaseZoom [] rs/UpdateEvent (-apply-update [_ state] - (let [increase #(min (mth/precision (* % 1.05) 2) 3)] + (let [increase #(nth zoom-levels (+ (index-of zoom-levels %) 1) (last zoom-levels))] (update-in state [:workspace :zoom] (fnil increase 1))))) (defn increase-zoom @@ -132,7 +139,7 @@ (defrecord DecreaseZoom [] rs/UpdateEvent (-apply-update [_ state] - (let [decrease #(max (mth/precision (* % 0.95) 2) 0.15)] + (let [decrease #(nth zoom-levels (- (index-of zoom-levels %) 1) (first zoom-levels))] (update-in state [:workspace :zoom] (fnil decrease 1))))) (defn decrease-zoom