DOM elements in a Dear ImGui app

Dear ImGui is an immediate-mode C++ toolkit used in game engines and tools. It draws everything itself and shows whatever texture the application gives it. This app is Dear ImGui 1.92.5 compiled with Emscripten (0.4 MB). The email, country, date and notes fields and the line of text are real elements, each shown with one ImGui::Image() call on a texture filled by texElementSubImage2D(). Tap a field to type. Scroll the window, drag the small window over a field, or open the ImGui combo above the fields.

DOM text with a link: مرحبا, 你好, 👋🏽.

Starting the ImGui app (0.4 MB of WebAssembly)…

The app hasn't started.

Show the code a DOM element as an ImGui image
  1. Put the elements inside the canvas that ImGui renders into. Each has a name in data-imgui.
  2. C++: the app. DomImage("email", width) sits between ImGui::SliderFloat() and ImGui::BulletText().
  3. C++: the widget. Ask the browser for the height, upload if the browser repainted the element, call ImGui::ImageWithBg(), then report the rectangle and the window's clip rectangle.
  4. JavaScript inside the C++ file: element to texture. GLctx is Emscripten's WebGL2 context.
  5. Tell the browser where ImGui drew it.
  6. Events. ImGui has no platform backend here. The page sends it the pointer, and asks ImGui which window is on top before an event reaches an element.
  7. C++: the frame function. It draws only when an event or a paint asked for frames.
  8. Start the module.
  9. CSS for the elements.
  10. All of main.cpp.

Live checks

The checks load a second copy of the app in a small frame, so they don't touch the one above.

ResultExperimentDetail

Findings

This page follows DOM elements inside egui and Qt Quick apps. Source: native/imgui-dom. Dear ImGui is MIT licensed.