0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-02-13 18:48:37 -05:00

Split constants to specific namespace.

This commit is contained in:
Andrey Antukh 2016-04-10 18:19:24 +03:00
parent e791f49921
commit d69be9a378
No known key found for this signature in database
GPG key ID: 4DFEBCB8316A8B95
9 changed files with 71 additions and 46 deletions

22
src/uxbox/constants.cljs Normal file
View file

@ -0,0 +1,22 @@
;; This Source Code Form is subject to the terms of the Mozilla Public
;; License, v. 2.0. If a copy of the MPL was not distributed with this
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
;;
;; Copyright (c) 2015-2016 Andrey Antukh <niwi@niwi.nz>
;; Copyright (c) 2015-2016 Juan de la Cruz <delacruzgarciajuan@gmail.com>
(ns uxbox.constants)
(def ^:const grid-x-axis 10)
(def ^:const grid-y-axis 10)
(def ^:const viewport-width 4000)
(def ^:const viewport-height 4000)
(def ^:const canvas-start-x 1200)
(def ^:const canvas-start-y 1200)
(def ^:const canvas-scroll-padding 50)
(def ^:const canvas-start-scroll-x (- canvas-start-x canvas-scroll-padding))
(def ^:const canvas-start-scroll-y (- canvas-start-y canvas-scroll-padding))

View file

@ -1,7 +1,15 @@
;; This Source Code Form is subject to the terms of the Mozilla Public
;; License, v. 2.0. If a copy of the MPL was not distributed with this
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
;;
;; Copyright (c) 2015-2016 Andrey Antukh <niwi@niwi.nz>
;; Copyright (c) 2015-2016 Juan de la Cruz <delacruzgarciajuan@gmail.com>
(ns uxbox.ui.workspace
(:require [sablono.core :as html :refer-macros [html]]
[rum.core :as rum]
[beicon.core :as rx]
[uxbox.constants :as c]
[uxbox.rstore :as rs]
[uxbox.data.workspace :as dw]
[uxbox.data.pages :as udp]
@ -42,8 +50,8 @@
dom (mx/get-ref-dom own "workspace-canvas")]
;; Set initial scroll position
(set! (.-scrollLeft dom) (* wb/canvas-start-scroll-x @wb/zoom-l))
(set! (.-scrollTop dom) (* wb/canvas-start-scroll-y @wb/zoom-l))
(set! (.-scrollLeft dom) (* c/canvas-start-scroll-x @wb/zoom-l))
(set! (.-scrollTop dom) (* c/canvas-start-scroll-y @wb/zoom-l))
(assoc own ::sub1 sub1 ::sub2 sub2)))
@ -89,8 +97,8 @@
(rs/emit! (dw/decrease-zoom)))
(let [dom (mx/get-ref-dom own "workspace-canvas")]
(set! (.-scrollLeft dom) (* wb/canvas-start-scroll-x @wb/zoom-l))
(set! (.-scrollTop dom) (* wb/canvas-start-scroll-y @wb/zoom-l)))))
(set! (.-scrollLeft dom) (* c/canvas-start-scroll-x @wb/zoom-l))
(set! (.-scrollTop dom) (* c/canvas-start-scroll-y @wb/zoom-l)))))
(defn- workspace-render
[own projectid]

View file

@ -113,14 +113,3 @@
(rx/buffer 2 1)
(rx/map coords-delta)
(rx/share)))
;; --- Constants
(def ^:const viewport-width 4000)
(def ^:const viewport-height 4000)
(def ^:const canvas-start-x 1200)
(def ^:const canvas-start-y 1200)
(def ^:const canvas-scroll-padding 50)
(def ^:const canvas-start-scroll-x (- canvas-start-x canvas-scroll-padding))
(def ^:const canvas-start-scroll-y (- canvas-start-y canvas-scroll-padding))

View file

@ -11,6 +11,7 @@
[beicon.core :as rx]
[lentes.core :as l]
[goog.events :as events]
[uxbox.constants :as c]
[uxbox.rstore :as rs]
[uxbox.shapes :as sh]
[uxbox.data.projects :as dp]
@ -58,8 +59,8 @@
(let [workspace (rum/react uuwb/workspace-l)
flags (:flags workspace)]
(html
[:svg.page-canvas {:x uuwb/canvas-start-x
:y uuwb/canvas-start-y
[:svg.page-canvas {:x c/canvas-start-x
:y c/canvas-start-y
:ref (str "canvas" id)
:width width
:height height}
@ -101,8 +102,8 @@
(uuc/release-action! "ui.shape"
"ui.selrect"))]
(html
[:svg.viewport {:width (* uuwb/viewport-width zoom)
:height (* uuwb/viewport-height zoom)
[:svg.viewport {:width (* c/viewport-width zoom)
:height (* c/viewport-height zoom)
:ref "viewport"
:class (when drawing? "drawing")
:on-mouse-down on-mouse-down

View file

@ -9,6 +9,7 @@
(:require [sablono.core :as html :refer-macros [html]]
[rum.core :as rum]
[cuerdas.core :as str]
[uxbox.constants :as c]
[uxbox.ui.mixins :as mx]
[uxbox.ui.workspace.base :as wb]))
@ -21,14 +22,14 @@
[own]
(let [options (:options @wb/page-l)
color (:grid/color options "#cccccc")
width wb/viewport-width
height wb/viewport-height
x-ticks (range (- 0 wb/canvas-start-x)
(- width wb/canvas-start-x)
width c/viewport-width
height c/viewport-height
x-ticks (range (- 0 c/canvas-start-x)
(- width c/canvas-start-x)
(:grid/x-axis options 10))
y-ticks (range (- 0 wb/canvas-start-x)
(- height wb/canvas-start-x)
y-ticks (range (- 0 c/canvas-start-x)
(- height c/canvas-start-x)
(:grid/y-axis options 10))
path (as-> [] $
@ -48,10 +49,10 @@
(defn- horizontal-line
[width acc value]
(let [pos (+ value wb/canvas-start-y)]
(let [pos (+ value c/canvas-start-y)]
(conj acc (str/format "M %s %s L %s %s" 0 pos width pos))))
(defn- vertical-line
[height acc value]
(let [pos (+ value wb/canvas-start-y)]
(let [pos (+ value c/canvas-start-y)]
(conj acc (str/format "M %s %s L %s %s" pos 0 pos height))))

View file

@ -9,6 +9,7 @@
(:require [sablono.core :as html :refer-macros [html]]
[rum.core :as rum]
[beicon.core :as rx]
[uxbox.constants :as c]
[uxbox.rstore :as rs]
[uxbox.util.math :as mth]
[uxbox.ui.workspace.base :as wb]
@ -104,8 +105,8 @@
[:rect {:style {:fill "transparent"
:stroke "transparent"
:cursor "cell"}
:width wb/viewport-width
:height wb/viewport-height}]
:width c/viewport-width
:height c/viewport-height}]
(if (and p1 p2)
(overlay-line-render own p1 p2))])))

View file

@ -10,6 +10,7 @@
[rum.core :as rum]
[cuerdas.core :as str]
[beicon.core :as rx]
[uxbox.constants :as c]
[uxbox.state :as s]
[uxbox.util.dom :as dom]
[uxbox.ui.workspace.base :as wb]
@ -24,8 +25,8 @@
(defn mid-ticks-mod [zoom] (/ 50 zoom))
(def ^:const +ticks+
(concat (range (- (/ wb/viewport-width 1)) 0 step-size)
(range 0 (/ wb/viewport-width 1) step-size)))
(concat (range (- (/ c/viewport-width 1)) 0 step-size)
(range 0 (/ c/viewport-width 1) step-size)))
(def ^:const rule-padding 20)
@ -35,8 +36,8 @@
mid-ticks-mod (mid-ticks-mod zoom)
pos (+ (* value zoom)
rule-padding
(* wb/canvas-start-x zoom)
wb/canvas-scroll-padding)]
(* c/canvas-start-x zoom)
c/canvas-scroll-padding)]
(cond
(< (mod value big-ticks-mod) step-size)
(conj acc (str/format "M %s %s L %s %s" pos 5 pos step-padding))
@ -52,8 +53,8 @@
(let [big-ticks-mod (big-ticks-mod zoom)
mid-ticks-mod (mid-ticks-mod zoom)
pos (+ (* value zoom)
(* wb/canvas-start-x zoom)
wb/canvas-scroll-padding)]
(* c/canvas-start-x zoom)
c/canvas-scroll-padding)]
(cond
(< (mod value big-ticks-mod) step-size)
(conj acc (str/format "M %s %s L %s %s" 5 pos step-padding pos))
@ -71,8 +72,8 @@
(let [big-ticks-mod (big-ticks-mod zoom)
pos (+ (* value zoom)
rule-padding
(* wb/canvas-start-x zoom)
wb/canvas-scroll-padding)]
(* c/canvas-start-x zoom)
c/canvas-scroll-padding)]
(when (< (mod value big-ticks-mod) step-size)
(html
[:text {:x (+ pos 2)
@ -88,9 +89,9 @@
[zoom value]
(let [big-ticks-mod (big-ticks-mod zoom)
pos (+ (* value zoom)
(* wb/canvas-start-x zoom)
;; wb/canvas-start-x
wb/canvas-scroll-padding)]
(* c/canvas-start-x zoom)
;; c/canvas-start-x
c/canvas-scroll-padding)]
(when (< (mod value big-ticks-mod) step-size)
(html
[:text {:y (- pos 3)
@ -145,10 +146,10 @@
[own zoom]
(let [scroll (rum/react wb/scroll-a)
scroll-x (:x scroll)
translate-x (- (- wb/canvas-scroll-padding) (:x scroll))]
translate-x (- (- c/canvas-scroll-padding) (:x scroll))]
(html
[:svg.horizontal-rule
{:width wb/viewport-width
{:width c/viewport-width
:height 20}
[:g {:transform (str "translate(" translate-x ", 0)")}
(horizontal-rule-ticks zoom)]])))
@ -165,11 +166,11 @@
[own zoom]
(let [scroll (rum/react wb/scroll-a)
scroll-y (:y scroll)
translate-y (- (- wb/canvas-scroll-padding) (:y scroll))]
translate-y (- (- c/canvas-scroll-padding) (:y scroll))]
(html
[:svg.vertical-rule
{:width 20
:height wb/viewport-height}
:height c/viewport-height}
[:g {:transform (str "translate(0, " translate-y ")")}
(vertical-rule-ticks zoom)]

View file

@ -9,6 +9,7 @@
(:require-macros [uxbox.util.syntax :refer [define-once]])
(:require [beicon.core :as rx]
[lentes.core :as l]
[uxbox.constants :as c]
[uxbox.rstore :as rs]
[uxbox.state :as ust]
[uxbox.data.shapes :as uds]

View file

@ -10,6 +10,7 @@
(:require [sablono.core :as html :refer-macros [html]]
[rum.core :as rum]
[beicon.core :as rx]
[uxbox.constants :as c]
[uxbox.rstore :as rs]
[uxbox.shapes :as sh]
[uxbox.data.workspace :as dw]
@ -79,8 +80,8 @@
"Translate the given rect to the canvas coordinates system."
[rect]
(let [zoom @wb/zoom-l
startx (* wb/canvas-start-x zoom)
starty (* wb/canvas-start-y zoom)]
startx (* c/canvas-start-x zoom)
starty (* c/canvas-start-y zoom)]
(assoc rect
:x (- (:x rect) startx)
:y (- (:y rect) starty)