diff --git a/components/system/Window/RndWindow/useResizable.ts b/components/system/Window/RndWindow/useResizable.ts index 6788d9f3..2fd70a05 100644 --- a/components/system/Window/RndWindow/useResizable.ts +++ b/components/system/Window/RndWindow/useResizable.ts @@ -1,10 +1,10 @@ +import { maxSize } from "components/system/Window/functions"; import useDefaultSize from "components/system/Window/RndWindow/useDefaultSize"; import useMinMaxRef from "components/system/Window/RndWindow/useMinMaxRef"; import { useProcesses } from "contexts/process"; import { useSession } from "contexts/session"; import { useLayoutEffect, useState } from "react"; import type { Props } from "react-rnd"; -import { maxSize } from "utils/functions"; export type Size = NonNullable; diff --git a/components/system/Window/functions.ts b/components/system/Window/functions.ts index 19d05664..f9c52b5f 100644 --- a/components/system/Window/functions.ts +++ b/components/system/Window/functions.ts @@ -74,3 +74,47 @@ export const isWindowOutsideBounds = ( y + pxToNum(height) > bounds.y ); }; + +export const maxSize = (size: Size, lockAspectRatio: boolean): Size => { + const desiredHeight = Number(size.height); + const desiredWidth = Number(size.width); + const [vh, vw] = [viewHeight(), viewWidth()]; + const vhWithoutTaskbar = vh - TASKBAR_HEIGHT; + const height = Math.min(desiredHeight, vhWithoutTaskbar); + const width = Math.min(desiredWidth, vw); + + if (!lockAspectRatio) return { height, width }; + + const isDesiredHeight = desiredHeight === height; + const isDesiredWidth = desiredWidth === width; + + if (!isDesiredHeight && !isDesiredWidth) { + if (desiredHeight > desiredWidth) { + return { + height, + width: Math.round(width / (vhWithoutTaskbar / height)), + }; + } + + return { + height: Math.round(height / (vw / width)), + width, + }; + } + + if (!isDesiredHeight) { + return { + height, + width: Math.round(width / (desiredHeight / height)), + }; + } + + if (!isDesiredWidth) { + return { + height: Math.round(height / (desiredWidth / width)), + width, + }; + } + + return { height, width }; +}; diff --git a/components/system/Window/useWindowSize.ts b/components/system/Window/useWindowSize.ts index 61f682fc..9a56535f 100644 --- a/components/system/Window/useWindowSize.ts +++ b/components/system/Window/useWindowSize.ts @@ -1,8 +1,8 @@ +import { maxSize } from "components/system/Window/functions"; import { useProcesses } from "contexts/process"; import { useSession } from "contexts/session"; import { useCallback } from "react"; import { useTheme } from "styled-components"; -import { maxSize } from "utils/functions"; type WindowSize = { updateWindowSize: (height: number, width: number) => void; diff --git a/utils/functions.ts b/utils/functions.ts index ed96e79d..97e8e1f9 100644 --- a/utils/functions.ts +++ b/utils/functions.ts @@ -425,50 +425,6 @@ export const isCanvasDrawn = (canvas?: HTMLCanvasElement | null): boolean => .data.some((channel) => channel !== 0) ); -export const maxSize = (size: Size, lockAspectRatio: boolean): Size => { - const desiredHeight = Number(size.height); - const desiredWidth = Number(size.width); - const [vh, vw] = [viewHeight(), viewWidth()]; - const vhWithoutTaskbar = vh - TASKBAR_HEIGHT; - const height = Math.min(desiredHeight, vhWithoutTaskbar); - const width = Math.min(desiredWidth, vw); - - if (!lockAspectRatio) return { height, width }; - - const isDesiredHeight = desiredHeight === height; - const isDesiredWidth = desiredWidth === width; - - if (!isDesiredHeight && !isDesiredWidth) { - if (desiredHeight > desiredWidth) { - return { - height, - width: Math.round(width / (vhWithoutTaskbar / height)), - }; - } - - return { - height: Math.round(height / (vw / width)), - width, - }; - } - - if (!isDesiredHeight) { - return { - height, - width: Math.round(width / (desiredHeight / height)), - }; - } - - if (!isDesiredWidth) { - return { - height: Math.round(height / (desiredWidth / width)), - width, - }; - } - - return { height, width }; -}; - const bytesInKB = 1024; const bytesInMB = 1022976; // 1024 * 999; const bytesInGB = 1047527424; // 1024 * 1024 * 999;