File tree Expand file tree Collapse file tree 3 files changed +22
-3
lines changed
Expand file tree Collapse file tree 3 files changed +22
-3
lines changed Original file line number Diff line number Diff line change @@ -2,14 +2,16 @@ import { defineStore } from 'pinia';
22import { ref , watch } from 'vue' ;
33
44import type { CanvasColor } from './useApi' ;
5+ import { getDefaultOffset , getDefaultScale } from '@/utils' ;
56
67export const useCanvasStore = defineStore (
78 'canvas' ,
89 ( ) => {
9- const scale = ref ( 1 ) ;
10+ const scale = ref ( getDefaultScale ( 1000 ) ) ;
1011
11- const offsetX = ref ( 0 ) ;
12- const offsetY = ref ( 0 ) ;
12+ const defaultOffset = getDefaultOffset ( 1000 * scale . value , 1000 * scale . value ) ;
13+ const offsetX = ref ( defaultOffset . x ) ;
14+ const offsetY = ref ( defaultOffset . y ) ;
1315
1416 const width = ref ( 0 ) ;
1517 const height = ref ( 0 ) ;
Original file line number Diff line number Diff line change 1+ /**
2+ * Calculates the scale you need to apply to the canvas
3+ * so the canvas takes 90% of the height of the window.
4+ * @param height Height of the canvas in pixels
5+ * @returns The scale value
6+ */
7+ export function getDefaultScale ( height : number ) : number {
8+ return ( 0.9 * globalThis . innerHeight ) / height ;
9+ }
10+
11+ export function getDefaultOffset ( width : number , height : number ) : { x : number ; y : number } {
12+ const x = ( globalThis . innerWidth - width ) / 2 ;
13+ const y = ( globalThis . innerHeight - height ) / 2 ;
14+
15+ return { x, y } ;
16+ }
Original file line number Diff line number Diff line change 11export * from './api' ;
22export * from './Color' ;
33export * from './logger' ;
4+ export * from './defaultCanvasPosition' ;
You can’t perform that action at this time.
0 commit comments