Native popovers anchored to controls on a tilted panel
The panel is HTML that a canvas draws on a quad in perspective. Its buttons open browser-native top-layer UI with no script: Scenes opens a popover through
commandfor, ? shows a popover="hint" through interestfor (hover, keyboard focus, or a long press on touch), and Turn off opens a modal
<dialog>. The popovers are placed with CSS anchor positioning against buttons that are only pictures on a texture. Move the two sliders on the panel, or switch on the swing,
and an open popover follows its button.
The results are in the Live checks table below.
Show the code buttons in the canvas, popovers outside it, anchors
- The markup.
commandfor,commandandinterestforon buttons inside the canvas, pointing at elements outside it. - The anchors.
anchor-nameon a button in the canvas,position-anchoron its popover. - The panel's matrix. One matrix draws the quad and, through
updateElementGeometry(), tells the browser where the panel is. Anchors and hit tests use that place. - On
paint. Upload the panel when it changed, draw its shadow and the panel. - The fragment shader. A highlight that depends on the tilt, and a ring around the button whose popover is open.
How it works
The panel is one drawable child of the canvas, uploaded as a texture and drawn on a quad through a matrix with perspective. The same matrix goes to updateElementGeometry() in each paint event. From then on the browser's hit tests, focus rings and anchor rectangles for the panel's buttons use the drawn place. The popovers and the dialog are ordinary elements outside the canvas; commandfor and interestfor open them and CSS anchor positioning places them. The canvas repaints every frame only while the panel swings or a popover is open.
Live checks
The button under the demo runs these. They use the demo itself, so it has to be on screen: a point outside the window can't be hit tested.
| Check | Result | Detail |
|---|---|---|
| A point on the drawn Scenes button hit tests to the button | not run | |
| The button's rectangle is the bounding box of its drawn quad | not run | |
| The popover opens next to the drawn button | not run | |
| The open popover follows the button when the panel turns | not run |
Findings
- In Chromium 157 the anchor rectangle of an element inside a drawn canvas child is the bounding box of its drawn quad. With a 50 degree turn and perspective, a 60 by 30 pixel button gave an
anchor of 34 by 29 pixels at the projected place, and a popover with
position-area: bottomsat under it. - An open popover moves with its button when the panel's matrix changes. The page calls
updateElementGeometry()in eachpaintevent and does nothing else for the popover. commandforwithtoggle-popover,hide-popoverandshow-modalworks from a button drawn in perspective, by mouse, touch and keyboard. The target doesn't have to be in the canvas.- The range inputs on the panel can be dragged while the panel turns under the pointer, because each new matrix moves the hit box as well.
- The popover's arrow flips with an
anchored(fallback: flip-block)container query whenposition-try-fallbacksmoves the popover above the button. - Chromium 153 keeps the anchor at the element's layout box, so there the popovers open at the panel's untransformed place. Chrome 159 on the phone isn't verified.
- The popovers and the dialog are drawn by the browser above the canvas. The canvas can't draw over them or bend them.