From 5845b610eaae74a57cfd18a6ae24a95d56ee5a2c Mon Sep 17 00:00:00 2001 From: Yeon Vinzenz Varapragasam Date: Fri, 18 Aug 2023 02:55:39 +0200 Subject: [PATCH] 2d --- src/pages/Devices/EditVirtuals/EditMatrix.tsx | 270 +++++++++++++++--- 1 file changed, 232 insertions(+), 38 deletions(-) diff --git a/src/pages/Devices/EditVirtuals/EditMatrix.tsx b/src/pages/Devices/EditVirtuals/EditMatrix.tsx index a3e42376..c7ed9f29 100644 --- a/src/pages/Devices/EditVirtuals/EditMatrix.tsx +++ b/src/pages/Devices/EditVirtuals/EditMatrix.tsx @@ -1,23 +1,56 @@ import { Box, + Button, Dialog, + DialogActions, DialogContent, + DialogTitle, MenuItem, Select, - Slider + Slider, + Switch, + Typography } from '@mui/material' -import { useState } from 'react' +import { useEffect, useRef, useState } from 'react' import { TransformWrapper, TransformComponent } from 'react-zoom-pan-pinch' import useStore from '../../../store/useStore' +import BladeFrame from '../../../components/SchemaForm/components/BladeFrame' const EditMatrix = () => { const devices = useStore((state) => state.devices) const [rowNumber, setRowNumber] = useState(10) const [colNumber, setColNumber] = useState(5) + const [currentCell, setCurrentCell] = useState([-1, -1]) + const [open, setOpen] = useState(false) + const [group, setGroup] = useState(false) + const [selectedPixel, setSelectedPixel] = useState(0) + const [currentDevice, setCurrentDevice] = useState('') + const [matrix, setMatrix] = useState( + Array(rowNumber * colNumber).fill({ + deviceId: '', + pixel: 0 + }) + ) // const [width, setWidth] = useState(500) // const [height, setHeight] = useState(500) - const [open, setOpen] = useState(false) + + const closeClear = () => { + setOpen(false) + setCurrentDevice('') + setSelectedPixel(0) + } + const deviceRef = useRef() + + useEffect(() => { + if (group) { + if (typeof selectedPixel === 'number') { + setSelectedPixel([selectedPixel, selectedPixel + 1]) + } + } else if (typeof selectedPixel !== 'number') { + setSelectedPixel(selectedPixel[0]) + } + }, [group]) return (
{ ? 1 : 0.1 } - minScale={false ? 1 : 0.1} + minScale={ + colNumber * 100 < window.innerWidth || + rowNumber * 100 < window.innerHeight * 0.8 + ? 1 + : 0.1 + } >
{ width: '100%' }} > - {Array(rowNumber * colNumber) - .fill('a') - .map((d, i) => ( - { - e.preventDefault() - setOpen(true) - }} - sx={{ - cursor: 'copy', - border: '1px solid #fff', - background: '#333', - width: 100, - height: 100, - '&:hover': { - background: '#999' - } - // width: `min(${width / colNumber}px, ${ - // height / rowNumber - // }px)`, - // height: `min(${width / colNumber}px, ${ - // height / rowNumber - // }px)` - }} - /> - ))} + {matrix.map((d, i) => ( + { + e.preventDefault() + setCurrentCell([i % colNumber, Math.floor(i / colNumber)]) + setOpen(true) + }} + sx={{ + cursor: 'copy', + border: '1px solid #666', + background: '#111', + width: 100, + height: 100, + '&:hover': { + background: '#999' + } + // width: `min(${width / colNumber}px, ${ + // height / rowNumber + // }px)`, + // height: `min(${width / colNumber}px, ${ + // height / rowNumber + // }px)` + }} + > + {d.deviceId !== '' && ( +
+ + {devices[d.deviceId].config.name} + + {d.pixel} +
+ )} +
+ ))}
- setOpen(false)} open={open}> + closeClear()} + open={open} + PaperProps={{ sx: { width: '100%', maxWidth: 320 } }} + > + +
+ Assign Pixel + + Row: {currentCell[1] + 1} +
+ Column: {currentCell[0] + 1} +
+
+
- + + + + {currentDevice && ( + <> + + setSelectedPixel(newPixel)} + /> + + + Assign multiple + setGroup(!group)} + /> + + {group && ( + <> + + + + + + + + )} + + )} + + +