Meters, progress and ranges drawn as readings
Five more controls from ui-feed.dev, rebuilt with HTML-in-canvas. Each one shows a reading:
the phase of the moon on each day of a month, ounces poured into a cup, gigabytes used on a phone, the temperature at a time of
day, and the stops within a walk. Under each drawing are native elements: a <table> of buttons, a
<progress>, six <meter>s and two <input type="range">. I wanted to know
if one draw of a table would place all of its buttons, and if a range could have its handle on a circle.
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.
Lunar month
A month as a <table> with a <button> for each day. The table is drawn once as an
element, which gives the day numbers, the names of the quarters and every button's hit region. The canvas draws a moon in each
cell from the age of the moon on that day, counted from the new moon of 6 January 2000. Change the month and the moons carry
on from where they were and run through their phases to the new dates.
After the lunar month (calendar) on ui-feed.dev.
Show the code the markup, the phase and the control
- The markup.
- The phase of the moon. The age as a fraction of the cycle, which day a quarter falls on, and the shape of the lit part.
- The control. The table of buttons, the arrow keys, and the draw.
put()andhit(). A draw places an element's hit region, with or without alpha.- The base class. The shadow root, the canvas, the paint loop and the plain HTML fallback.
Measured fill
A <progress> and one <button>. Press the knob and a valve opens: the flow builds up,
runs at 1.7 oz a second, and is throttled over the last half ounce, so the count slows into the last tenth. Press again to
stop part way, and press when it's full to empty it. The display is drawn as liquid crystal, with the unlit segments faintly
visible. The text under "Fill" is the element's own.
After measured fill (progress) on ui-feed.dev.
Show the code the markup, the valve and the control
- The markup.
- The valve. The flow, the throttle near full, and the end.
- The whole control. Seven-segment figures, the bar of 32 cells and the knob.
Storage freed
A <meter> for each kind of file and one for the total. The rows are real elements drawn as pictures,
with the meter restyled. The button clears one kind. Each amount is on a spring and the total is their sum, so the figure
counts down and the strip of marks goes out a mark at a time. The kinds are <option> children, and the
one with data-clear gets the button.
After storage freed (meter) on ui-feed.dev.
Show the code the markup and the control
- The markup. One option for each kind of file, in gigabytes.
- The control. A row with a meter for each option, the springs, and the strip of marks.
Forecast
One range over the hours the forecast covers. Each <option> is a time with a temperature, and the big
figure is the temperature between them at the time under the thumb, on a smooth curve through the forecasts. The figure is an
<output> and it's on a spring, so it trails a fast drag. The sky goes dark outside the hours between
sunrise and sunset.
After the forecast slider on ui-feed.dev.
Show the code the markup, the curve and the control
- The markup. The forecasts are options.
- The temperature between two forecasts.
- The whole control.
Walk to a stop
One range, in minutes of walking. Its handle rides on a circle on a street map, and the radius is how far you get in that time at 80 metres a minute. Drag the handle away from the centre or toward it. Stops inside the circle turn solid and are counted along the bottom of the circle. The map is made up: a grid of streets from a fixed seed, drawn twice on two plain canvases, one for outside the circle and one for inside.
After walk to stop (slider) on ui-feed.dev.
Show the code the markup and the control
- The markup.
- The control. The made-up city, the range on the circle, the two maps and the lettering round the edge.
How it works
Each control is a custom element on the same base class as the sliders and number fields. Its
shadow root holds a canvas with content="drawable", and the native elements are children of that canvas. The canvas
draws the reading from their state and calls drawElementImage() for each element: with full alpha where the element
should be seen (the table, the rows of meters, the button, the temperature), and with globalAlpha = 0 where only
its hit region is wanted.
The calendar draws its <table> once. That one draw places 35 buttons, because the hit region of a drawn
element covers its descendants where they were laid out. The moons are drawn by the canvas over the picture of the table, at
positions worked out from the size of a cell.
A <progress> or a <meter> takes no input, so nothing needs to reach it. It's there to
hold the value for assistive technology and for the plain fallback. The small meters in the storage rows are drawn as they are,
restyled with ::-webkit-meter-bar and ::-webkit-meter-optimum-value. The progress bar and the total
are placed with no alpha under a strip the canvas draws.
The range on the map is moved by the pointer's distance from the centre of the circle, with the pointer captured on the range. All five stop asking for frames when nothing moves.
Live checks
Findings
- One draw of a table places every button in it. The month is one
drawElementImage()of a<table>with 42 buttons. The point in each of nine cells I tried answered that cell's button. - A canvas can draw over an element's picture without taking its clicks. The moons are drawn after the table, on top of its picture, and the buttons under them still answer.
- A
<meter>restyled with its pseudo-elements keeps that style in its picture. The rows show a white bar 3 pixels high on a grey track. - A range's hit region can ride a circle. The range is 48 units square and placed over the handle each frame. After a drag outward its hit region was at the new radius.
- A
<progress>with no value keeps the canvas painting. It's indeterminate, and its animation raised 12 paint events in 1.5 seconds even though the element is drawn with no alpha. Settingvalue = 0stopped them. - The mean lunar cycle is a day out for one quarter in four. For November 2026 the control puts the last quarter on the 2nd and an almanac has it on the 1st. The other three match.
- Not verified: everything on a phone. Tapping a day, dragging the thumb and the handle on the map by touch, and what a screen reader says for the progress element, the meters and the table.