Magnified ruler picker and rolling digits

I rebuilt Nitish Khagwal's Ruler Picker inside one ElementGL WebGL 2 canvas. Drag the scale, press the arrow keys, or switch units and presets: a cylindrical glass lens bends and magnifies nearby <datalist> ticks while the <output> digits roll like an odometer drum.

Lens refraction
Ruler scale 0 to 100 cm · step 0.5
42.0 cm

Starting...

Show the code drawable instrument card, cylindrical lens shader, rolling odometer and geometry sync
  1. Live ruler card inside one canvas. Putting unit buttons, rolling <output> drums, <input type="range">, <datalist> and preset buttons in one drawable card keeps them in a single texture upload.
  2. Cylindrical lens and drum fragment shader. Refracts scale UVs around uLensX with barrel arch, Snell rim compression, chromatic RGB fringe, reflection bar and mechanical drum shading over <output>.
  3. Damped velocity spring and rolling digit reels. Tracks the thumb or pointer hover along the scale and rolls each digit wheel continuously across 9 to 0 wraps, snapping under reduced motion.
  4. Hit-box calibration with updateElementGeometry(). Scales the transform by geometryUnit() and flips dataset.hitTick so dragging the slider and tapping buttons keep working.
  5. Five-argument 2D strip fallback. Draws the card once with 5-argument drawElementImage(), copies it into a plain buffer for the lens strips and keeps hit testing at 1:1.

How it works

This builds on Ruler Picker by Nitish Khagwal (listed on Demos elsewhere). Earlier on /elastic-range/, I mocked up a 2D ruler in strips without rolling digits. Here the whole precision instrument sits inside one <canvas content="drawable" layoutsubtree> backed by a single ElementGL WebGL 2 context from /lib/element-gl.js.

One drawable card (#ruler-card) holds the unit switcher buttons, the <output id="ruler-out" for="ruler-range"> odometer window, the real <input id="ruler-range" type="range">, its <datalist id="ruler-ticks"> options, a visual tick strip synced to the thumb inset and four preset buttons. Putting aria-hidden="true" on the visual 14-digit reels while updating a visually hidden text span inside <output> stops a screen reader from reciting every digit on every strip while keeping native live-region announcements intact.

On each paint event, stage.begin() sizes the WebGL buffer first and stage.upload(cardEl) uploads the card with gl.texElementSubImage2D(). Inside RULER_FRAG, fragments inside uRulerRect map lateral distance from uLensX through s / zoom + (1 - 1 / zoom) * s^3.6 so ticks swell up to 2.4x (2.15x at rest) directly under the thumb without moving the thumb centre, bow outward with vertical barrel arch, split subtly into R, G and B near the steep Snell rim and pick up a darkened glass reflection bar. Fragments inside uOdoRect get cylindrical drum shading and top/bottom bezel vignette, while buttons stay untouched at 1:1.

Two damped velocity springs drive the lens focal coordinate and each digit reel, stopping the requestAnimationFrame loop once settled and pausing completely off screen through IntersectionObserver. Under prefers-reduced-motion: reduce, both snap straight to target. Because WebGL uploads don't move hit boxes on their own, syncGeometry() passes a geometryUnit()-scaled matrix to canvas.updateElementGeometry() and toggles dataset.hitTick. Without WebGL 2, draw2DFallback() renders with 5-argument drawElementImage() plus clipped lens strips from a plain copy, and on webglcontextlost the card moves into plain HTML so every control stays usable.

Live checks

Each check builds an isolated fixture on testStage() without scrolling or focusing the demo above. Press Run to test this browser.

Findings