Radial pie menu with wedge warp
I wanted to know if one ElementGL WebGL 2 canvas could draw a Blender-style radial pie menu of live HTML <button> items over an interactive workspace card, complete with a frosted glass ring, directional selection beam, spring wedge stretch and accurate clicks at any tap point. Tap a wedge directly, drag-flick from anywhere on the canvas, or tap empty canvas space to move the menu.
Starting...
Show the code drawable workspace and radial ring, spring detent, WebGL 2 wedge warp, geometry sync and 2D fallback
- Two
drawablechildren inside one canvas.#pm-workspaceholds the target card that transforms under commands, while#pm-ringholds six real<button>items spaced at 60° intervals. - Damped spring detent and opening bounce. Drives menu scale, per-wedge radial pull and wedge scale with explicit timestamps so live checks can step the simulation deterministically.
- Glass ring backdrop, selection beam and barrel bulge shader. Pass 0 refracts the workspace under a frosted annulus and draws the directional beam; Pass 1 adds a centre-anchored barrel bulge and specular border glow to the active wedge.
- Hit-box calibration with
updateElementGeometry(). Positions#pm-ringat the tap coordinate withgeometryUnit()and flipsdataset.hitTickso moved and pulled buttons register clicks. - Five-argument
drawElementImage()2D fallback. Draws the workspace and pie ring with 5-argument calls, paints the selection beam with Canvas 2D arcs and updates hit geometry.
How it works
Both the workspace card (#pm-workspace) and the six-button pie ring (#pm-ring) sit inside one <canvas content="drawable" layoutsubtree> backed by one ElementGL WebGL 2 context from /lib/element-gl.js. I set gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, true) on startup and inside onRestored so anti-aliased button edges and rounded borders blend cleanly over the workspace without dark fringes.
Uploading waits until the first paint event sets hasPainted = true, and every frame calls stage.begin() before stage.upload(). Pass 0 draws #pm-workspace 1:1 while sampling nearby texels inside an annular frosted-glass mask centred at uMenuCenter, then overlays sector hairlines, an outer specular arc and the directional selection beam along uPointerAngle. Pass 1 draws #pm-ring with a centre-pinned barrel bulge around the armed wedge and a bright alpha-edge border glow.
Moving a pointer over the ring, dragging outward from any tap point or tabbing onto a button picks the nearest 60° sector and pulls that <button> outward along its polar angle in CSS while scaling it to 1.12×. Because WebGL quads don't move DOM hit regions on their own, syncGeometry() maps #pm-ring to (menuX, menuY) via canvas.updateElementGeometry() scaled by geometryUnit() and toggles dataset.hitTick. Once the springs settle, or when the canvas scrolls off screen or the tab hides, the requestAnimationFrame loop stops. Without WebGL 2, draw2DFallback() renders with 5-argument drawElementImage() calls, and on webglcontextlost both children move into #plain-host as a 3×2 button grid.
Live checks
Each check builds an isolated fixture on testStage() without touching the demo above. Press Run to test this browser.
Findings
- Measured in headless Chrome 160.0.8188.0 canary (2026-11-27, 412×915 viewport at 2.625 DPR, SwiftShader WebGL): all 6 live checks pass, backing store stays at
0.91 MP(994×914,7.3 MB),scrollWidth === innerWidth === 412,0errors,0lost contexts,0open snapshots and0wrong-argumentdrawElementImage()calls. - Pixel readbacks in
readPixels()confirm the directional beam shifts cleanly between quadrants (0°:561/110/108,120°:105/561/108,240°:105/110/561), whileupdateElementGeometry()scaled bygeometryUnit()keeps repositioned and spring-pulled wedge buttons clickable viaelementsFromPoint(). - Toggling
prefers-reduced-motion: reducemounts.motion-warnand snaps springs in 1 step; restoring normal motion removes the notice cleanly. Both 5-argumentdrawElementImage()2D fallback (?route=2d) and plain-HTML fallback (withCanvasDrawElementdisabled) keep all 6 commands working with zero horizontal overflow. position: relative; width: 100%; height: 100%;is needed on#pm-workspace: usingposition: absolute; inset: 0;insidelayoutsubtreecaused Chromium to shrink-wrap the child to its intrinsic content height instead of stretching it to the canvas dimensions.- Chrome 159 on Android (touch drag-flick feel, real GPU frame timing at 412 px) and
npm run check:jank -- /pie-menu/(Playwright isn't installed here) stay not verified.