From 20baf0272620c437442eacbbaee1b6606236f890 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Moya?= Date: Mon, 24 Jan 2022 12:00:55 +0100 Subject: [PATCH] :bug: Normalize zoom levels in workspace and viewer --- CHANGES.md | 1 + frontend/src/app/main/constants.cljs | 7 --- frontend/src/app/main/data/viewer.cljs | 15 ++--- frontend/src/app/main/data/workspace.cljs | 75 +++++++++++------------ 4 files changed, 42 insertions(+), 56 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index e783fd565..6f8c4e8b5 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -73,6 +73,7 @@ - Fix edit blur attributes for multiselection [Taiga #2625](https://tree.taiga.io/project/penpot/issue/2625) - Fix auto hide header in viewer full screen [Taiga #2632](https://tree.taiga.io/project/penpot/issue/2632) - Fix zoom in/out after fit or fill [Taiga #2630](https://tree.taiga.io/project/penpot/issue/2630) +- Normalize zoom levels in workspace and viewer [Taiga #2631](https://tree.taiga.io/project/penpot/issue/2631) ### :arrow_up: Deps updates diff --git a/frontend/src/app/main/constants.cljs b/frontend/src/app/main/constants.cljs index 84393c171..8247b9296 100644 --- a/frontend/src/app/main/constants.cljs +++ b/frontend/src/app/main/constants.cljs @@ -23,10 +23,3 @@ :grid-alignment true :background "var(--color-white)"}) -(def zoom-levels - [0.01 0.03 0.05 0.07 0.09 0.10 0.11 0.13 0.15 0.18 - 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.50 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.00 2.16 2.27 2.38 2.50 2.62 2.75 2.88 3.00]) diff --git a/frontend/src/app/main/data/viewer.cljs b/frontend/src/app/main/data/viewer.cljs index 1adedc3ff..6ff221239 100644 --- a/frontend/src/app/main/data/viewer.cljs +++ b/frontend/src/app/main/data/viewer.cljs @@ -11,7 +11,6 @@ [app.common.spec :as us] [app.common.types.interactions :as cti] [app.common.uuid :as uuid] - [app.main.constants :as c] [app.main.data.comments :as dcm] [app.main.data.fonts :as df] [app.main.repo :as rp] @@ -190,21 +189,15 @@ (ptk/reify ::increase-zoom ptk/UpdateEvent (update [_ state] - (let [increase (fn [zoom] - (d/seek #(> % zoom) - c/zoom-levels - zoom))] - (update-in state [:viewer-local :zoom] increase))))) + (let [increase #(min (* % 1.3) 200)] + (update-in state [:viewer-local :zoom] (fnil increase 1)))))) (def decrease-zoom (ptk/reify ::decrease-zoom ptk/UpdateEvent (update [_ state] - (let [decrease (fn [zoom] - (d/seek #(< % zoom) - (reverse c/zoom-levels) - zoom))] - (update-in state [:viewer-local :zoom] decrease))))) + (let [decrease #(max (/ % 1.3) 0.01)] + (update-in state [:viewer-local :zoom] (fnil decrease 1)))))) (def reset-zoom (ptk/reify ::reset-zoom diff --git a/frontend/src/app/main/data/workspace.cljs b/frontend/src/app/main/data/workspace.cljs index d11e75f37..292693c6a 100644 --- a/frontend/src/app/main/data/workspace.cljs +++ b/frontend/src/app/main/data/workspace.cljs @@ -413,6 +413,43 @@ ;; Workspace State Manipulation ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; --- Toggle layout flag + +(defn toggle-layout-flags + [& flags] + (ptk/reify ::toggle-layout-flags + ptk/UpdateEvent + (update [_ state] + (update state :workspace-layout + (fn [stored] + (reduce (fn [flags flag] + (if (contains? flags flag) + (disj flags flag) + (conj flags flag))) + stored + (d/concat-set flags))))))) + +;; --- Set element options mode + +(defn set-options-mode + [mode] + (us/assert ::options-mode mode) + (ptk/reify ::set-options-mode + ptk/UpdateEvent + (update [_ state] + (assoc-in state [:workspace-local :options-mode] mode)))) + +;; --- Tooltip + +(defn assign-cursor-tooltip + [content] + (ptk/reify ::assign-cursor-tooltip + ptk/UpdateEvent + (update [_ state] + (if (string? content) + (assoc-in state [:workspace-local :tooltip] content) + (assoc-in state [:workspace-local :tooltip] nil))))) + ;; --- Viewport Sizing (declare increase-zoom) @@ -552,44 +589,6 @@ (-> state (update :workspace-local dissoc :zooming))))) - -;; --- Toggle layout flag - -(defn toggle-layout-flags - [& flags] - (ptk/reify ::toggle-layout-flags - ptk/UpdateEvent - (update [_ state] - (update state :workspace-layout - (fn [stored] - (reduce (fn [flags flag] - (if (contains? flags flag) - (disj flags flag) - (conj flags flag))) - stored - (d/concat-set flags))))))) - -;; --- Set element options mode - -(defn set-options-mode - [mode] - (us/assert ::options-mode mode) - (ptk/reify ::set-options-mode - ptk/UpdateEvent - (update [_ state] - (assoc-in state [:workspace-local :options-mode] mode)))) - -;; --- Tooltip - -(defn assign-cursor-tooltip - [content] - (ptk/reify ::assign-cursor-tooltip - ptk/UpdateEvent - (update [_ state] - (if (string? content) - (assoc-in state [:workspace-local :tooltip] content) - (assoc-in state [:workspace-local :tooltip] nil))))) - ;; --- Zoom Management (defn- impl-update-zoom