Controls drawn into pictures over buttons, a file input, a treegrid, switches and ranges

Five more controls from ui-feed.dev, rebuilt with HTML-in-canvas. In each one the control is part of a picture: waypoints on a hand-drawn map, a drop zone on a scrapbook page, a night's backup on a green screen, the switches on a kitchen worktop and a crop box on a cutting mat. I wanted to know how much of each picture the canvas could paint itself, with the native elements only where something is pressed, typed or read out.

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 element 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. The photos and the still life here are painted by the canvas, so no picture is borrowed.

Coast path

The map is painted once by the canvas: the squared paper, the cliffs in hatching, the contours and the path. Each waypoint is a <button> drawn as a ring, and one role="tooltip" card is filled in for the one you point at or move to with Tab. The card springs out of its waypoint on a stem. A tap pins it, a second tap or Escape lets it go.

After the coast path waypoints (tooltip) on ui-feed.dev.

Show the code the markup and the control
  1. The markup. One option for each waypoint, with where it is on the map and what the card says.
  2. The control. The buttons, the card and its spring.
  3. The base class. The shadow root, the canvas, the paint loop and the plain HTML fallback.

Travel journal

A page of a scrapbook. The heading is cut out a letter at a time, the photos are a list, and the drop zone is a <label> round an <input type="file"> that covers it, so a click opens the file picker and a file dropped on it goes straight into the input. Each photo you add is tossed onto the page: it falls in turning and lands on a strip of tape. The form sends the files.

After the travel journal page (file input) on ui-feed.dev.

Show the code the markup and the control
  1. The markup. One option for each photo the page starts with.
  2. The control. The file input, the list and the photos landing.

Photo backup

A <table role="treegrid"> of the night's jobs, with a row for each and a level for its place in the tree. The keys are a treegrid's: Up and Down, Right to open or go in, Left to close or go out. The canvas draws the time axis and a bar for each job, and draws each row as a slice of the table at a place that follows its row on a spring, so when a job closes the rows under it slide up. The line at the bottom is an <output> for the chosen job.

After the overnight photo backup (waterfall) on ui-feed.dev.

Show the code the markup and the control
  1. The markup. One option for each job, with its level, its start and end, and its photos.
  2. The control. The treegrid, its keys and the rows on springs.

Hob child lock

Two <input type="checkbox" role="switch">s on the worktop. The hob's keys above them are in a <fieldset>, and the lock sets disabled on it, so every key goes dead at once and the canvas draws them dim. The lock key is outside the fieldset: hold it, or hold Space on it, for three seconds and the lock comes off, with a ring drawn round it as it counts. The description under the big switch changes with it.

After the hob child lock (switch) on ui-feed.dev.

Show the code the markup and the control
  1. The markup. locked starts it locked.
  2. The control. The switches, the fieldset and the key you hold.

Cutting mat

A crop box over a picture the canvas paints. Four <input type="range">s hold the left, top, width and height, and each one's limits follow the others so the box can't leave the picture. One empty <div> over the picture takes every drag, and where the drag starts says whether it moves an edge, a corner or the whole box. With a range focused, the arrow keys move its edge, which the canvas draws yellow. The size is an <output> on a yellow tag, in inches.

After the cutting mat (image cropper) on ui-feed.dev.

Show the code the markup and the control
  1. The markup. The box to start with: left, top, width and height, in units of the picture.
  2. The control. The ranges, the drag and the box.

How it works

Each control is a custom element on the same base class as the scroll controls. Its shadow root holds a canvas with content="drawable", and the native elements are children of that canvas.

Most of each picture is painted by the canvas, once, into a plain canvas that is kept and drawn every frame. The native elements are drawn where something is pressed or read: a ring over a button, a card that is a tooltip, a drop zone that is a file input, a row of a table. An element that only takes input (the crop area, the waypoints) is drawn with no alpha, which puts its hit region where it is wanted and nothing on the screen.

Two of the controls draw one element in several pieces: the photos are slices of one list, and the backup rows are slices of one table. Each slice is turned or moved on its own, which is how a photo lands at a tilt and a row slides up.

Live checks

Findings