Native controls on dot and tube displays
Six controls from ui-feed.dev, rebuilt with HTML-in-canvas. The originals are React components. Here
each one is a custom element with a drawable canvas in its shadow root, and inside the canvas are ordinary radio inputs, a
<textarea>, a <table>, date and time inputs. The canvas draws those elements at one pixel for each
dot of the display, copies that small picture with drawImage() and enlarges it through a mask of dots. I wanted to know if
a control could keep its own CSS and its own behaviour and still end up as an LED board, with no getImageData(). Tap, type
and use the arrow keys on any of them.
Credit: every control on this page is a rebuild of a demo on ui-feed.dev, and each section links to the original it came from. The originals are far higher fidelity than these, so go and look at them. These are examples of what HTML-in-canvas makes possible with a native form control underneath, not replacements. I worked from the published demos rather than their source: I looked at what each one does, worked out the mechanism and built it again. The designs and the ideas are theirs.
Cinema showings
A native <select size="5">, which is the listbox the platform already has, drawn as an LED board. The rows, the
selection highlight, the arrow keys, type-ahead and the scrolling are the browser's. The rows are built from the element's
<option> children, and the sold-out showing is a disabled option.
After cinema showings (listbox) on ui-feed.dev.
Show the code the markup, the element and the dot board
- The options are the data. The element reads its
<option>children and watches them for changes. - The element. One
<select size>styled with CSS, onedotBoard()call, then an invisible draw that puts the list's hit region over the board. - The dot board. A reduced draw, a copy to a plain canvas, and an enlarged draw through a mask.
- The base class. The shadow root, the canvas, the paint loop, the form value and the plain HTML fallback.
Station departures
Pagination over a table that stays in the page. The <table> is slotted into a drawable <div> in the
canvas, and a page of the board is five clipped draws of that one picture. No row is hidden or moved. The page buttons are
<button>s in a <nav>, and each line of the board changes a little after the one above it.
After station departures (pagination) on ui-feed.dev.
Show the code a slotted table paged by clipping
- The table is light DOM. It is the author's markup and it keeps the author's CSS.
- The page styles the cells. A shadow tree can't.
- The element. Each visible line is a clip and a draw of the slot's wrapper, moved up by the row's
offsetTop.
LED message counter
A <textarea maxlength="40"> typed into through the board, and a <meter> that the canvas draws as
one lamp for each character. Select some text: the ::selection colours are on the board too.
After led message counter (meter) on ui-feed.dev.
Show the code a textarea on the board and a meter drawn from its value
- One element, with no children. The textarea and the meter are internal, and the value reaches the form through
ElementInternals. - The element.
Flip-dot stars
A rating made of five radio inputs with one name. The canvas puts each radio's hit region over a star and draws every cell of the panel as a disc that turns over when its state changes. Left and right arrows move the rating, which is the radio group's own behaviour.
After flip-dot stars (rating) on ui-feed.dev.
Show the code radio inputs under drawn stars
- The markup.
- The element. The stars are worked out on a grid. Nothing is drawn of the radios:
hit()places them. put()andhit(). A draw withglobalAlpha = 0still moves the hit region.
VCR timer
An <input type="date">, two <input type="time"> and an <input type="number"> in
a form, drawn as a video recorder's on-screen display. Tap a field and type, or use the up and down arrows. The picture is redrawn in
bands that drift sideways, with a red and a blue copy either side.
After vcr timer recording (date input) on ui-feed.dev.
Show the code date and time inputs behind a tube effect
- The markup.
- The element.
dotBoard()with square cells returns the enlarged picture, and the element draws it in bands.
Teletext
A command list: an <input role="combobox"> over a list built from <option> children. Type to filter,
move with the arrow keys, choose with Enter or a tap. The four coloured words at the bottom are buttons that filter by group.
After teletext (command) on ui-feed.dev.
Show the code a filtered list in teletext colours
- The pages are
<option>children.data-groupgives the colour and the button at the bottom. - The element.
How it works
Every control here extends one base class, FeedControl in /lib/ui-feed/kit.js. Its shadow root holds a canvas with
content="drawable", and the canvas holds the native elements. The control's own CSS is nested under canvas, so
when the API is missing or the context is lost the same elements are shown outside the canvas as unstyled HTML and still work.
Drawing is in design units: a control is designed 360 wide, and the context is scaled so that the same numbers work at any width.
The elements inside the canvas are laid out at the design size, and drawElementImage() is given that size, so a narrower
canvas draws them smaller and their hit regions follow.
The dot board has three steps. The paint handler sets a transform that makes one cell of the design one device pixel, and draws the
elements with it, so the browser rasterises the text at one pixel a dot. That corner of the canvas is copied to a small plain canvas
with drawImage(). The copy is enlarged with smoothing off into a second plain canvas, a pattern of discs is applied with
destination-in, and the result is drawn back. Nothing is read with getImageData(). The reduced draw leaves each
element's hit region in that corner, so the last step is a draw with globalAlpha = 0 at the place the board shows it.
Data that an author supplies is light DOM. Four of the controls read <option> children or attributes and build
their own inputs. The departures board is different: its table is slotted, drawn as it is, and styled by the page. A control's value
reaches its form through ElementInternals.setFormValue(). The line under each demo is the FormData of the form around it.
Live checks
Findings
- A reduced
drawElementImage()is a usable per-dot picture. Text drawn at one device pixel for each dot, copied out and enlarged with smoothing off, read as a dot display from about 7 dots of cap height. Below that the letters ran together. - The control's CSS states show on the board with no extra code. The inverted row is
label:has(:checked), the dimmed row is:has(:disabled), the yellow frame is:focus-visible, and a text selection in the textarea is drawn in its::selectioncolours. - The hit region follows the last draw, at any alpha. The list is drawn reduced in a corner first, then once more with
globalAlpha = 0at the board's place. The taps in the checks below land on the right row. - A slotted table can be paged without touching it. Twelve rows, five to a page: each line is a clipped draw of the slot's
wrapper. The rows keep their layout, so
offsetTopof a row is where to clip. - A shadow tree can't style slotted cells.
::slotted(table)reaches the table and inherited properties reach the cells. Column widths and the header alignment had to come from the page's stylesheet. - Radio inputs in a shadow root with one name and no form are one group. The arrow keys moved the rating from 4 to 3 in the test browser with no key handler in the element.
- Date and time fields are edited where they are drawn. A click on the drawn minutes field focused that field and typed digits went into it, through the pixelated picture.
- The text caret wasn't in the picture of the textarea in the test browser, with
caret-shape: blockor without. The message counter draws its own block cursor. It finds the place with a hidden copy of the text up to the caret, laid out in the same font and width. - A
<form>in a shadow root's HTML is dropped when the host is inside a form. The parser doesn't nest forms, andinnerHTMLon the shadow root counts the host's form. My first version of four of these controls had an inner<form>and worked until I put one in a form. They use a<div>now. - Not verified: everything on a phone. The native date and time pickers that Android opens for these inputs, the on-screen keyboard over the teletext input, and the frame rate of the VCR picture, which redraws every frame while it is on screen.