An accessibility tree for a Dear ImGui app

Dear ImGui draws its button, checkbox, slider and text field as pixels, so a browser sees one canvas and nothing inside it. Here every ImGui widget also has a real element inside the canvas: a <button>, an <input type="checkbox">, an <input type="range">, an <input type="text">. The elements are never drawn. updateElementGeometry() puts each one at the rectangle ImGui reports for its widget. Use the app by touch or mouse, or press Tab and use Space, Enter and the arrow keys. Tap the text field to type. Turn on the outlines to see where the browser believes each element is.

Starting the ImGui app (0.4 MB of WebAssembly)…

The app hasn't started.

Show the code one DOM node per ImGui widget
  1. The canvas starts empty. layoutsubtree gives its children layout boxes. The app adds the children.
  2. C++: the app. Each widget is an ImGui call inside a wrapper: AButton() is ImGui::Button() followed by A11y("button", label).
  3. C++: the report. A11y() reads the id and rectangle of the item ImGui has just submitted and the window's clip rectangle. The wrappers apply changes that came from the DOM before they call ImGui.
  4. JavaScript inside the C++ file: one node per widget. Create it if it's new, keep DOM order equal to ImGui order, write the name and state, then place it.
  5. After the last widget. Remove the nodes of widgets that weren't submitted and clear Chromium's hit-test cache.
  6. Events. A node's click, input and focus go to ImGui. Pointer events go to ImGui from the canvas, except a press on the text field.
  7. C++: what the page calls.
  8. C++: the text field. The node holds the text while it has focus. ImGui draws the buffer and the node's caret, or the node's own image.
  9. The focused node as a texture. Used only when the second checkbox is on.
  10. C++: the frame function. It draws only when something asked for frames.
  11. The outlines. getBoundingClientRect() of each node, drawn as a div over the canvas.
  12. Start the module.
  13. CSS for the nodes.
  14. All of main.cpp.

How it works

Live checks

The checks load a second copy of the app in a small frame, so they do not touch or focus the one above.

ResultExperimentDetail

Findings

This page follows DOM elements in a Dear ImGui app, which shows real elements as ImGui images. Here the direction is reversed: ImGui's own widgets get elements. Source: native/toolkit-aria. Dear ImGui is MIT licensed.