diff --git a/js/controlStyles.ts b/js/controlStyles.ts index 284a7592..bc9c913a 100644 --- a/js/controlStyles.ts +++ b/js/controlStyles.ts @@ -101,5 +101,10 @@ export const sliderStyles = { "& .MuiSlider-rail": { height: 2, borderRadius: 0 }, "& .MuiSlider-track": { height: 2, borderRadius: 0 }, "& .MuiSlider-valueLabel": { borderRadius: 0 }, + // A finger needs a taller strip and a larger thumb than a mouse; desktop layout keeps the compact rows. + "@media (pointer: coarse)": { + py: "14px", + "& .MuiSlider-thumb": { width: 18, height: 18 }, + }, }, }; diff --git a/js/show2d/index.tsx b/js/show2d/index.tsx index 695a796d..1c2b77e1 100644 --- a/js/show2d/index.tsx +++ b/js/show2d/index.tsx @@ -940,6 +940,8 @@ function Show2D() { touchAction: "none", zIndex: 5, "&:hover": { opacity: 1 }, + // A finger needs about 44 px: the grip stays 16 px drawn, its hit area grows on touch screens. + "@media (pointer: coarse)": { opacity: 0.9, "&::before": { content: '""', position: "absolute", inset: -14 } }, }), [themeColors.accent]); const [showStats] = useModelState("show_stats"); const [statsMean] = useModelState("stats_mean"); @@ -7018,7 +7020,9 @@ function Show2D() { // Resize Handlers // ------------------------------------------------------------------------- - const handleCanvasResizeStart = (e: React.MouseEvent) => { + // Pointer events, so a finger or a pen drags the grip as a mouse does (mouse events never arrive for a touch drag). + const handleCanvasResizeStart = (e: React.PointerEvent) => { + if (e.pointerType === "mouse" && e.button !== 0) return; e.stopPropagation(); e.preventDefault(); canvasResizeCleanupRef.current?.(); @@ -7033,7 +7037,7 @@ function Show2D() { let rafId = 0; let latestSize = start.size; - const handleMouseMove = (event: MouseEvent) => { + const handleMouseMove = (event: PointerEvent) => { const delta = Math.max(event.clientX - start.x, event.clientY - start.y); latestSize = Math.max(200, start.size + delta); if (!rafId) { @@ -7050,15 +7054,17 @@ function Show2D() { applyResizeViewAnchor(latestSize); setCanvasSize(latestSize); setPanelWidthPxTrait(Math.round(latestSize)); - document.removeEventListener("mousemove", handleMouseMove); - document.removeEventListener("mouseup", finishResize); + document.removeEventListener("pointermove", handleMouseMove); + document.removeEventListener("pointerup", finishResize); + document.removeEventListener("pointercancel", finishResize); window.removeEventListener("blur", finishResize); canvasResizeCleanupRef.current = null; window.setTimeout(() => { canvasResizeViewAnchorRef.current = null; }, 0); }; - document.addEventListener("mousemove", handleMouseMove); - document.addEventListener("mouseup", finishResize); + document.addEventListener("pointermove", handleMouseMove); + document.addEventListener("pointerup", finishResize); + document.addEventListener("pointercancel", finishResize); window.addEventListener("blur", finishResize); canvasResizeCleanupRef.current = finishResize; }; @@ -8629,7 +8635,7 @@ function Show2D() { )} {showResizeControls && ( @@ -8798,7 +8804,7 @@ function Show2D() { )} {showResizeControls && ( { + onPointerDown={(e: React.PointerEvent) => { e.stopPropagation(); handleCanvasResizeStart(e); }} @@ -8904,7 +8910,7 @@ function Show2D() { {renderPanelAnnotations(0)} {renderPanelFrameControls(0)} {showResizeControls && ( - + )} )} @@ -9458,7 +9464,7 @@ function Show2D() { )} {showResizeControls && ( - + )} {/* FFT Stats Bar */} diff --git a/js/show3d/index.tsx b/js/show3d/index.tsx index 2e8816c9..1e727386 100644 --- a/js/show3d/index.tsx +++ b/js/show3d/index.tsx @@ -1497,6 +1497,8 @@ function Show3D() { touchAction: "none", zIndex: 5, "&:hover": { opacity: 1 }, + // A finger needs about 44 px: the grip stays 16 px drawn, its hit area grows on touch screens. + "@media (pointer: coarse)": { opacity: 0.9, "&::before": { content: '""', position: "absolute", inset: -14 } }, }), [themeColors.accent]); const [statsMean] = useModelState("stats_mean"); const [statsMin] = useModelState("stats_min"); @@ -4153,9 +4155,11 @@ function Show3D() { setLogScale(nextLogScale); }, [logScale, setLogScale, setVmaxPerPanel, setVminPerPanel]); + // Frame labels for the per-panel titles, written straight to the page while playing (set beside frameLabelForIndex). + const frameLabelForIndexRef = React.useRef<((idx: number) => string) | undefined>(undefined); const updatePlaybackLiveControls = React.useCallback((idx: number) => { const settings = playRef.current; - writeLiveFrameControls(rootRef.current, playbackSliderRef.current, playbackLiveCountRef.current, idx, Math.max(1, settings.nSlices || nSlices || 1), settings.loop); + writeLiveFrameControls(rootRef.current, playbackSliderRef.current, playbackLiveCountRef.current, idx, Math.max(1, settings.nSlices || nSlices || 1), settings.loop, frameLabelForIndexRef.current); }, [nSlices]); const viewportTransformActive = React.useCallback(() => { @@ -4973,7 +4977,11 @@ function Show3D() { const settings = playRef.current; const effectiveFps = clampPlaybackFps(settings.fps); const intervalMs = playbackIntervalMs(effectiveFps); - const uiUpdateIntervalMs = effectiveFps >= 60 ? 250 : 100; + // React commits (stats, histogram, star state) once a second while playing: each commit renders the whole + // viewer, and at 10 per second they were most of the main-thread time a frame cost (18.5 of 18.5 ms vs 3.5 ms + // under a 4x CPU throttle, three 512 px panels). The slider, counters and frame labels are written straight + // to the page every frame by updatePlaybackLiveControls. + const uiUpdateIntervalMs = 1000; // First tick paints immediately; otherwise every playback start drops // one frame before the cadence timer is even allowed to run. @@ -6956,7 +6964,7 @@ function Show3D() { // Profile height resize React.useEffect(() => { if (!isResizingProfile) return; - const handleMouseMove = (e: MouseEvent) => { + const handleMouseMove = (e: PointerEvent) => { if (!profileResizeStart) return; const delta = e.clientY - profileResizeStart.y; setProfileHeight(Math.max(40, Math.min(300, profileResizeStart.height + delta))); @@ -6965,11 +6973,13 @@ function Show3D() { setIsResizingProfile(false); setProfileResizeStart(null); }; - document.addEventListener("mousemove", handleMouseMove); - document.addEventListener("mouseup", handleMouseUp); + document.addEventListener("pointermove", handleMouseMove); + document.addEventListener("pointerup", handleMouseUp); + document.addEventListener("pointercancel", handleMouseUp); return () => { - document.removeEventListener("mousemove", handleMouseMove); - document.removeEventListener("mouseup", handleMouseUp); + document.removeEventListener("pointermove", handleMouseMove); + document.removeEventListener("pointerup", handleMouseUp); + document.removeEventListener("pointercancel", handleMouseUp); }; }, [isResizingProfile, profileResizeStart]); @@ -8586,8 +8596,40 @@ function Show3D() { beginPan(e); }; + // One finger drives the active tool (profile line, ROI, lens) through the same handlers as the mouse: a touch drag + // sends no mouse events, so these tools did nothing on a phone. Two fingers still pinch and pan the view. + const toolTouchRef = React.useRef(false); + const touchAsMouse = (touch: React.Touch, e: React.TouchEvent) => ({ + clientX: touch.clientX, + clientY: touch.clientY, + button: 0, + buttons: 1, + shiftKey: false, + altKey: false, + ctrlKey: false, + metaKey: false, + detail: 1, + currentTarget: e.currentTarget, + target: e.target, + nativeEvent: e.nativeEvent, + preventDefault: () => e.preventDefault(), + stopPropagation: () => e.stopPropagation(), + }) as unknown as React.MouseEvent; const handleCanvasTouchStart = (e: React.TouchEvent) => { - if (profileActive || effectiveRoiActive) return; + const toolActive = profileActive || effectiveRoiActive || showLens; + if (toolActive && e.touches.length === 1) { + e.preventDefault(); + toolTouchRef.current = true; + handleCanvasMouseMove(touchAsMouse(e.touches[0], e)); + handleCanvasMouseDown(touchAsMouse(e.touches[0], e)); + return; + } + if (toolTouchRef.current && e.touches.length >= 2) { + // a second finger turns the tool gesture into a pinch: end the tool drag where the first finger is + handleCanvasMouseUp(touchAsMouse(e.touches[0], e)); + toolTouchRef.current = false; + } + if ((profileActive || effectiveRoiActive) && e.touches.length < 2) return; if (e.touches.length === 1) { const touch = e.touches[0]; const panelIdx = panelIdxFromClient(touch.clientX, touch.clientY); @@ -8619,6 +8661,11 @@ function Show3D() { }; const handleCanvasTouchMove = (e: React.TouchEvent) => { + if (toolTouchRef.current && e.touches.length === 1) { + e.preventDefault(); + handleCanvasMouseMove(touchAsMouse(e.touches[0], e)); + return; + } const start = touchTransformRef.current; if (!start) return; const canvas = canvasRef.current; @@ -8658,6 +8705,13 @@ function Show3D() { }; const handleCanvasTouchEnd = (e: React.TouchEvent) => { + if (toolTouchRef.current) { + if (e.touches.length > 0) return; + const last = e.changedTouches[0]; + if (last) handleCanvasMouseUp(touchAsMouse(last, e)); + toolTouchRef.current = false; + return; + } if (e.touches.length > 0 || !touchTransformRef.current) return; commitLivePanelTransforms(); touchTransformRef.current = null; @@ -9717,9 +9771,15 @@ function Show3D() { }; // Resize handlers - const handleMainResizeStart = (e: React.MouseEvent) => { + // Pointer events with capture, so a mouse, a finger (Galaxy Fold, touch laptops) and a pen all drag the grip: + // mouse events alone never arrive for a touch drag. + const handleMainResizeStart = (e: React.PointerEvent) => { + if (e.pointerType === "mouse" && e.button !== 0) return; e.stopPropagation(); e.preventDefault(); + const grip = e.currentTarget; + const pointerId = e.pointerId; + try { grip.setPointerCapture(pointerId); } catch { /* capture is best effort */ } const rect = canvasContainerRef.current?.getBoundingClientRect(); const startSize = rect && rect.width > 0 ? rect.width : mainCanvasSize; const startX = e.clientX; @@ -9727,7 +9787,8 @@ function Show3D() { const visiblePanels = Math.max(1, visiblePanelCount || 1); let rafId = 0; let latestSize = startSize; - const handleMouseMove = (e: MouseEvent) => { + const handleMouseMove = (e: PointerEvent) => { + if (e.pointerId !== pointerId) return; const delta = Math.max(e.clientX - startX, e.clientY - startY); const nextSize = startSize + delta; // Absolute minimum: 200 px per panel column. Lets reader shrink BELOW @@ -9743,16 +9804,20 @@ function Show3D() { }); } }; - const handleMouseUp = () => { + const handleMouseUp = (e: PointerEvent) => { + if (e.pointerId !== pointerId) return; cancelAnimationFrame(rafId); setMainCanvasSize(latestSize); const colsLocal = panelColsForCount(visiblePanels); setCanvasSizeTrait(Math.round(latestSize / colsLocal)); - document.removeEventListener("mousemove", handleMouseMove); - document.removeEventListener("mouseup", handleMouseUp); + document.removeEventListener("pointermove", handleMouseMove); + document.removeEventListener("pointerup", handleMouseUp); + document.removeEventListener("pointercancel", handleMouseUp); + try { grip.releasePointerCapture(pointerId); } catch { /* already released */ } }; - document.addEventListener("mousemove", handleMouseMove); - document.addEventListener("mouseup", handleMouseUp); + document.addEventListener("pointermove", handleMouseMove); + document.addEventListener("pointerup", handleMouseUp); + document.addEventListener("pointercancel", handleMouseUp); }; const clampSlice = (idx: number) => Math.max(0, Math.min(nSlices - 1, Math.round(idx))); @@ -9763,6 +9828,7 @@ function Show3D() { if (!text || text === String(idx) || text === String(idx + 1)) return ""; return text; }, [labels]); + frameLabelForIndexRef.current = frameLabelForIndex; const formatFrameValueLabel = React.useCallback((idx: number) => { const rounded = clampSlice(idx); const label = frameLabelForIndex(rounded); @@ -11446,7 +11512,7 @@ function Show3D() { overflowWrap: "anywhere", }} > - {panelTitleContent(panel)}{frameLabel ? ` · ${frameLabel}` : ""}{" "} + {panelTitleContent(panel)}{frameLabel ? ` · ${frameLabel}` : ""}{" "} {`${shown}/${total}`} @@ -11722,7 +11788,7 @@ function Show3D() { {panelChromeVisible && effectiveRoiActive && roiItems.length > 0 && showRoiResizeHint && ( - Hover ROI edge to resize + Drag an ROI edge to resize )} @@ -11740,7 +11806,7 @@ function Show3D() { return ( {showResizeControls && (
{ e.preventDefault(); setIsResizingProfile(true); setProfileResizeStart({ y: e.clientY, height: profileHeight }); }} - style={{ width: "100%", height: 4, cursor: "ns-resize", borderLeft: `1px solid ${themeColors.border}`, borderRight: `1px solid ${themeColors.border}`, borderBottom: `1px solid ${themeColors.border}`, background: `linear-gradient(to bottom, ${themeColors.border}, transparent)` }} + onPointerDown={(e) => { e.preventDefault(); setIsResizingProfile(true); setProfileResizeStart({ y: e.clientY, height: profileHeight }); }} + style={{ width: "100%", height: 4, cursor: "ns-resize", touchAction: "none", borderLeft: `1px solid ${themeColors.border}`, borderRight: `1px solid ${themeColors.border}`, borderBottom: `1px solid ${themeColors.border}`, background: `linear-gradient(to bottom, ${themeColors.border}, transparent)` }} /> )} @@ -12132,7 +12198,7 @@ function Show3D() { fps - setPlaybackFps(v as number)} size="small" sx={{ ...sliderStyles.small, width: isMobileViewport ? 40 : 44, mx: isMobileViewport ? "3px" : 0, flexShrink: 0 }} aria-label="Playback frames per second" valueLabelDisplay="auto" /> + setPlaybackFps(v as number)} size="small" sx={{ ...sliderStyles.small, width: isMobileViewport ? 72 : 44, mx: isMobileViewport ? "6px" : 0, flexShrink: 0 }} aria-label="Playback frames per second" valueLabelDisplay="auto" /> {Math.round(playbackFps)}