docs / webview
gru · 0.8.0 · main
WebView
Optional Windows WebView2 host for embedding HTML inside a Gru window. Native widgets still draw through Raylib; the web view is a child HWND.
When to use it
Use WebView when part of the UI is best done in HTML (docs pane, map, rich editor)
and the rest should stay native Gru widgets and chrome.
Start from cmd/webviewhello or gru new myapp --webview.
Build tags
go run -tags webview2 ./cmd/webviewhello
go run -tags "grudemo,webview2" .
go run ./cmd/gru build webviewhello -webview2
Requires the Microsoft Edge WebView2 Runtime.
Rules
- FillClient · the web view fills the client area below the title bar and resizes with the window.
- Two surfaces · GL draws the Gru tree; WebView is a separate HWND. Hide the HWND when a modal needs hits over that area.
- Focus · hand focus between native widgets and the web view explicitly (see Focus Handoff demo).
Modals and overlays (occlusion)
The live WebView2 HWND sits above the OpenGL blit. A native modal drawn in Raylib cannot paint on top of that HWND, so Gru hides live hosts while a blocking overlay is open.
| Overlay | Occludes WebView? |
|---|---|
Modal (ShowModal) | Yes |
| Drawer / bottom sheet | Yes |
| Context menu, toast, title bar | No |
- Use
ui.ShowModal(...)(or drawer APIs); engine setsWebViewHostOccludedfor you. - Keep the modal body flat flex — no
Viewportas modal root. - Verify in WebView Focus Handoff with
-tags webview2. - Do not invent click-through / passthrough so GL “shows through” the web.
Debug
Set GRU_WEBVIEW_DEBUG=1 and use Shift+F11 for stderr traces.
F12 is still the widget inspector.
Demos
- WebView Module Demo
- WebView Focus Handoff
Run with -tags "grudemo,webview2", then Tab to those scenes.
Full guide: WEBVIEW.md · chapter: architecture/webview.md.
Next: Architecture · Layout · Start