mirror of
https://github.com/DustinBrett/daedalOS.git
synced 2026-01-15 12:15:02 +00:00
Move maxSize to window functions
This commit is contained in:
@@ -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<Props["size"]>;
|
||||
|
||||
|
||||
@@ -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 };
|
||||
};
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user