Skip to content

Commit 8e0743d

Browse files
committed
feat(frontend): add default scale and offset for canvas
1 parent aad5402 commit 8e0743d

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

frontend/src/composables/store.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@ import { defineStore } from 'pinia';
22
import { ref, watch } from 'vue';
33

44
import type { CanvasColor } from './useApi';
5+
import { getDefaultOffset, getDefaultScale } from '@/utils';
56

67
export 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);
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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+
}

frontend/src/utils/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export * from './api';
22
export * from './Color';
33
export * from './logger';
4+
export * from './defaultCanvasPosition';

0 commit comments

Comments
 (0)