Occlusion without a guard in a Dear ImGui app

A DOM field in a Dear ImGui window still takes the pointer when a second ImGui window is drawn over it. The first ImGui page asks ImGui what is on top at every pointer event. I tried nine ways to say it in advance. Drag Window A or B over a field, pick a route, and read the table.

A paragraph with a link to the first ImGui page in it.

Starting the ImGui app (0.4 MB of WebAssembly)…

With the outline on, each dot is a sample point. the browser's hit test answers the field and the field is visible there. it answers the field under a window (a wrong hit). a wrong hit that the guard stops in script. the field is visible there and doesn't take the pointer (a lost hit).

FieldPoints under a windowWrong hitsLost hitsVisible points that hit
input…………
textarea…………
select…………
p + link…………
All four…………

The app hasn't started.

Show the code nine ways to say "this window covers that field"
  1. The fields, two blocker elements and two overlay elements.
  2. C++: which windows cover the form, and where. The rectangle is the one in which ImGui gives the pointer to the window, which is 4 px larger on each side than the window it draws.
  3. JavaScript inside the C++ file: the report. The app only records the rectangles. The route decides what to do with them.
  4. The routes. Each one changes what a field asks for: a clip rectangle, a CSS value, or nothing.
  5. Applying a route after each ImGui frame. A field's geometry is sent only when it changed. The blockers are placed again after any field, because the last call wins.
  6. Route 3: the largest visible rectangle.
  7. Routes 5a and 5b: the visible part as rectangles.
  8. The pointer. One listener sends ImGui every event that the browser didn't give to a field. The guard's question to ImGui is the only part that depends on the route.
  9. C++: the guard's answer.
  10. The measurement.
  11. Route 4: what canvasClip accepts. Run by the live checks.
  12. C++: a DOM element as an ImGui image.
  13. C++: the three windows.
  14. C++: the frame function. It draws only when something asked for frames.
  15. The table.
  16. Start the module.
  17. CSS for the fields and the blockers.

How it works

Live checks

The checks load a second copy of the app in a small frame, so they do not touch the one above. A route that does not work is a check that is expected to fail.

ResultExperimentDetail

Findings

Measured in headless Chromium 157 on 2026-11-21, at a device scale of 2.625 with touch input. The numbers are from the live checks: 96 sample points on the textarea, window A in four positions (over all of it, over its right side, across its middle, over one corner).

This page follows DOM elements in a Dear ImGui app. Source: native/toolkit-occlusion. Dear ImGui is MIT licensed.