Toob Player UI

This commit is contained in:
Robin E. R. Davies
2025-06-07 21:52:23 -04:00
parent 82f94cb152
commit 6ea45f46df
29 changed files with 1860 additions and 319 deletions
+17
View File
@@ -35,6 +35,17 @@ export interface DraggableButtonBaseProps extends ButtonBaseProps {
interface Point {
x: number;
y: number;
};
function isValidPointer(e: React.PointerEvent): boolean {
if (e.pointerType === "mouse") {
return e.button === 0;
} else if (e.pointerType === "pen") {
return true;
} else if (e.pointerType === "touch") {
return true;
}
return false;
}
function screenToClient(element: HTMLElement, point: Point): Point {
@@ -81,6 +92,12 @@ export default function DraggableButtonBase(props: DraggableButtonBaseProps) {
<ButtonBase
{...rest}
onPointerDown={(e) => {
if (!isValidPointer(e)) {
return;
}
if (pointerId !== null) {
return; //tracking another pointer already.
}
e.currentTarget.setPointerCapture(e.pointerId);
setPointerId(e.pointerId);
setPointerDownPoint(screenToClient(e.currentTarget,{ x: e.screenX, y: e.screenY }));