Skip to content
Snippets Groups Projects
Verified Commit c139047e authored by João Magalhães's avatar João Magalhães :rocket:
Browse files

feat: added display resize support

parent c7854f30
No related branches found
No related tags found
1 merge request!9Version 0.4.0 🍾
Pipeline #1364 passed
......@@ -59,6 +59,11 @@ export const Display: FC<DisplayProps> = ({
const [width, setWidth] = useState<number | undefined>(undefined);
const [height, setHeight] = useState<number | undefined>(undefined);
const canvasRef = useRef<HTMLCanvasElement>(null);
const resizeRef = useRef(() => {
const [fullWidth, fullHeight] = crop(options.width / options.height);
setWidth(fullWidth);
setHeight(fullHeight);
});
useEffect(() => {
if (canvasRef.current && !canvasContents) {
......@@ -69,16 +74,14 @@ export const Display: FC<DisplayProps> = ({
);
}
if (fullscreen) {
const [fullWidth, fullHeight] = crop(
options.width / options.height
);
setWidth(fullWidth);
setHeight(fullHeight);
resizeRef.current();
window.addEventListener("resize", resizeRef.current);
} else {
setWidth(undefined);
setHeight(undefined);
window.removeEventListener("resize", resizeRef.current);
}
});
}, [canvasRef, fullscreen]);
if (onDrawHandler) {
onDrawHandler((pixels: Uint8Array, format: PixelFormat) => {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment