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
  1. The options are the data. The element reads its <option> children and watches them for changes.
  2. The element. One <select size> styled with CSS, one dotBoard() call, then an invisible draw that puts the list's hit region over the board.
  3. The dot board. A reduced draw, a copy to a plain canvas, and an enlarged draw through a mask.
  4. 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.

TimeDestinationPlExpected
14:29Bray6Due
14:33Howth5On time
14:35Maynooth7On time
14:40Longford3On time
14:44Bray614:47
14:50Malahide5On time
14:52Sligo4On time
14:58Greystones615:03
15:02Howth5On time
15:05Drogheda2On time
15:10Bray6On time
15:14Maynooth7Delayed

After station departures (pagination) on ui-feed.dev.

Show the code a slotted table paged by clipping
  1. The table is light DOM. It is the author's markup and it keeps the author's CSS.
  2. The page styles the cells. A shadow tree can't.
  3. 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
  1. One element, with no children. The textarea and the meter are internal, and the value reaches the form through ElementInternals.
  2. 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
  1. The markup.
  2. The element. The stars are worked out on a grid. Nothing is drawn of the radios: hit() places them.
  3. put() and hit(). A draw with globalAlpha = 0 still 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
  1. The markup.
  2. 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
  1. The pages are <option> children. data-group gives the colour and the button at the bottom.
  2. 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