diff --git a/qubitverse/visualizer/src/components/QuantumCircuit.jsx b/qubitverse/visualizer/src/components/QuantumCircuit.jsx index 989b981..7ed3892 100644 --- a/qubitverse/visualizer/src/components/QuantumCircuit.jsx +++ b/qubitverse/visualizer/src/components/QuantumCircuit.jsx @@ -16,6 +16,7 @@ const gateSize = 45; // width/height for single-qubit gate squares const canvasMinX = 50; // left bound for gates on the stage const canvasMaxX = window.innerWidth - 300 - gateSize; // right bound so gate stays visible + // ======================= // GATE LIST // ======================= @@ -910,6 +911,33 @@ const QuantumCircuit = ({ numQubits, setNumQubits }) => { setMeasurementHist([]); } +const [Dragging, setDragging] = useState(false); + const [position, setPosition] = useState({ x: 100, y: 100 }); + const [offset, setOffset] = useState({ x: 0, y: 0 }); + const boxRef = useRef(null); + + const startDrag = (e) => { + setDragging(true); + setOffset({ x: e.clientX - position.x, y: e.clientY - position.y }); + }; + + const handleMouseMove = (e) => { + if (!Dragging) return; + setPosition({ x: e.clientX - offset.x, y: e.clientY - offset.y }); + }; + + const handleMouseUp = () => setDragging(false); + + useEffect(() => { + if (Dragging) { + window.addEventListener("mousemove", handleMouseMove); + window.addEventListener("mouseup", handleMouseUp); + } + return () => { + window.removeEventListener("mousemove", handleMouseMove); + window.removeEventListener("mouseup", handleMouseUp); + }; + }, [Dragging, offset]); return ( @@ -935,19 +963,39 @@ const QuantumCircuit = ({ numQubits, setNumQubits }) => { {/* Left Menu: single box with gates on top and 3 buttons below */} -
+

Quantum Gates

+
{/* Gates box */}
{ justifyContent: "space-evenly", marginBottom: "10px", overflowY: "auto", - scrollbarWidth:"none" + scrollbarWidth:"none", }} > {gatesList.map((gate, index) => { @@ -1039,7 +1087,7 @@ const QuantumCircuit = ({ numQubits, setNumQubits }) => { {/* Right Content: depends on active tab */}