DOM elements inside egui and Qt Quick apps
egui (Rust) and Qt Quick (C++) are native UI toolkits. Compiled to WebAssembly they draw every widget themselves into one WebGL canvas,
so the page has no real inputs. Here both apps contain real <input>, <select> and <textarea>
elements. The toolkit lays them out and draws them from a texture filled by texElementSubImage2D(). The browser handles their input.
egui
Loading the egui app (3.3 MB of WebAssembly)…
Rows marked DOM are real elements: the mobile keyboard, autofill, the native date and select pickers, the caret and text selection are the browser's. Rows marked egui are drawn by egui. Drag the egui window over the form, or use its sliders to change how the DOM fields are drawn.
Show the code a DOM element as an egui widget
- Put the elements inside the canvas that egui renders into. Each one has a name in
data-egui. - Style them like any other element. Their layout position isn't used.
- Start the app on that canvas.
- Rust: use a DOM element like a widget.
self.dom.show(ui, "email", width, look)sits between egui's ownTextEditandSlider. - Rust: the widget. Ask the browser for the height, allocate that space in egui, report the final position to the browser, and add a paint callback.
- Rust: the paint callback. It runs inside egui's WebGL pass, uploads the element if the browser repainted it, and draws one quad.
- JavaScript: element to texture.
texElementSubImage2D()writes into the texture Rust has bound. - JavaScript: tell the browser where egui drew it.
updateElementGeometry()moves the element's hit box, caret and accessibility bounds there. - JavaScript: keep egui and the element from both handling one event, and ask egui whether one of its windows is on top before an event reaches an element.
- All of lib.rs.
- All of bridge.js.
Qt Quick
Qt 6.10 for WebAssembly, with Qt Quick Controls. It isn't loaded until you ask.
The email, plan and notes fields are DOM elements shown by a DomItem in the QML scene. The sliders are Qt Quick Controls
that set the items' opacity and rotation, and the rotated field still takes clicks and typing where it is drawn.
Show the code a DOM element as a Qt Quick item
- The elements. Qt's canvas is inside a shadow root, so page stylesheets don't reach it. The page copies each element's computed style inline before Qt takes it.
- QML:
DomItemnext to Qt Quick Controls. Layouts,opacityandrotationapply to it like any item. - C++ with inline JavaScript: move the element into Qt's canvas.
GLctxis Emscripten's WebGL context, the one Qt Quick draws with. - C++: a GL texture that the scene graph draws. The upload runs on
beforeRendering;QSGOpenGLTexture::fromNative()hands the texture to aQSGSimpleTextureNode. - The upload call.
- Tell the browser where the item is.
itemTransform()gives the item's matrix in the window, rotation included. - All of domitem.cpp.
Live checks
The checks load a second copy of the egui app in a small frame, so they don't touch the one above. The Qt app was tested the same way with Playwright before it was published (see Findings).
| Result | Experiment | Detail |
|---|
Findings
- Both toolkits took a DOM element as a widget without changes to the toolkit. egui needs a paint callback (
egui_glow::CallbackFn). Qt Quick needs aQQuickItemwhose node wraps a GL texture (QSGOpenGLTexture::fromNative()). Each bridge is about 200 lines. - The element is drawn by the toolkit, so it is in the toolkit's z-order. An egui window covers the DOM fields, an egui scroll area clips them, and Qt Quick rotates and fades them. Toolkits that put HTML over or under the canvas can't do this.
- Layout goes both ways. The toolkit sets the element's width, the browser lays it out, and the toolkit reads
offsetHeightto size its widget. The paragraph of DOM text wraps to the width egui gives it. - The browser doesn't know what the toolkit draws on top. An element is hit tested wherever its geometry is. The egui bridge asks egui (
Context::layer_id_at()) in a capture-phase listener before an event reaches an element, and moves the element's geometry off the canvas when an egui window is over it at the pointer. The Qt proof doesn't do this yet. - Two things on the page want each event. egui listens on the canvas and Qt on its window element, and an event on a child element bubbles to both. The bridges stop propagation at the element. egui already ignores pointer moves when
elementFromPoint()isn't its canvas, which helped. - Focus is split. Tab moves between the DOM fields in DOM order and between toolkit widgets in the toolkit's order, and the two orders aren't joined. A click hands focus over correctly in both directions.
- The texture must be premultiplied. egui and Qt Quick both blend premultiplied alpha. Without
UNPACK_PREMULTIPLY_ALPHA_WEBGLtext on a transparent background is drawn too heavy. - Qt's canvas is in a shadow root and Qt creates it. The element has to be moved in after Qt has a GL context, and it needs inline styles. Setting
content="drawable"on a canvas that already has a WebGL context works. - Raw GL inside Qt Quick's frame prints warnings. Chromium logs five
texParameter: no texture boundwarnings per item at start-up, from Qt's renderer after the foreign texture is wrapped. The textures are drawn correctly. Not investigated further. - Some of what the browser paints for a field is left out of the texture. The explainer excludes spelling and grammar markers, pending autofill previews, IME pop-ups and IME composition formatting from element images for privacy. The textarea has
spellcheckon and a misspelt word, and no marker is drawn. updateElementGeometry()doesn't drop cached hit-test results. In Chromium 157,elementFromPoint()at a point that was hit tested just before the call keeps returning the old element, while a point two pixels away is correct. Any DOM mutation clears it, so both bridges toggle an attribute on the canvas after each geometry update.- eframe focuses its hidden text input when it starts. The page makes
focus()a no-op while the app starts so that opening the page doesn't move focus. - Not verified on a phone. Both apps were tested in headless Chromium 157 at a 2.625 device scale with touch events. DevTools device emulation gives egui a wrong scale (it reads a canvas size that isn't in device pixels), so use a real phone. Touch-dragging on a DOM field doesn't scroll the egui scroll area under it.
Other frameworks
How Qt, Flutter, Compose Multiplatform, egui, Dear ImGui, Slint, Avalonia, Uno Platform, Unity and Godot render on the web today, what each does about text input, accessibility and embedded HTML, and what HTML-in-canvas would change for each, with sources: docs/native-frameworks.md.
| Framework | Draws into | Text input today | Accessibility today | HTML content today |
|---|---|---|---|---|
| Qt for WebAssembly | One canvas per window. WebGL for Qt Quick, 2D putImageData for raster windows. | A hidden <input> per window. | A parallel tree of hidden ARIA elements, off by default. | Not documented. |
| Flutter web | WebGL canvas (CanvasKit or Skwasm). | A transparent <input> or <textarea> placed over the field. | A parallel flt-semantics tree, off until asked for. | Platform views: elements slotted between extra canvases. |
| Compose Multiplatform | Canvas (Skia). | Open issues are on the roadmap. | Initial support in 1.9. | WebElementView: an element laid over the canvas. |
| egui | WebGL or WebGPU canvas. | A hidden <input> ("text agent"). | None on the web apart from an experimental speech output. | None. |
| Slint | WebGL canvas. | No IME with the Emscripten backend. | Not available. | None. |
| Avalonia | WebGL canvas (Skia through CanvasKit). | Not stated. | Partial, through ARIA attributes. | JavaScript interop only. |
| Uno Platform (Skia) | WebGL canvas. | IME is work in progress. | Work in progress. | Native element hosting, no alpha blending. |
| Unity, Godot | WebGL canvas. | A real text field is needed to raise a mobile keyboard. | None documented for the web. | Page elements over the canvas, by hand. |
Each cell is sourced in the document. "Not stated" and "not documented" mean the framework's own pages didn't say.