Skip to main content

Dear ImGui in an RPS UI panel

RPS UI draws every panel with Dear ImGui. The host owns each panel's ImGui context: the DX11 renderer, the font atlas, the input it feeds and the frame. Your mod only issues ImGui calls.

Building Dear ImGui​

Compile your own copy of Dear ImGui from the same revision as the host, 1.93.0 WIP (IMGUI_VERSION_NUM 19294, upstream commit f562ab8e), with RPS_UI_Framework/ImGuiBuild.h as its user configuration:

add_library(my_imgui STATIC "${IMGUI_DIR}/imgui.cpp" "${IMGUI_DIR}/imgui_draw.cpp"
"${IMGUI_DIR}/imgui_tables.cpp" "${IMGUI_DIR}/imgui_widgets.cpp")
target_include_directories(my_imgui PUBLIC "${IMGUI_DIR}" "${RPSUI_INCLUDE_DIR}")
target_compile_definitions(my_imgui PUBLIC IMGUI_USER_CONFIG="RPS_UI_Framework/ImGuiBuild.h")

Leave out the DX11 backend: the host renders. If you need more configuration, include RPS_UI_Framework/ImGuiBuild.h first from your own user configuration file. Nothing that changes ImGui's data layout may differ.

registerPanel compares PanelRegistration::imgui with the host's build and refuses another one with ImGuiBuildMismatch. The refusal is logged with your DLL, like an outdated consumer.

Callbacks​

Both callbacks run on the render thread. Start each with RPSUI_IMGUI_BIND(setup->imgui) or RPSUI_IMGUI_BIND(frame->imgui): it makes the host's context current in your copy of ImGui and switches your copy to the host's allocator, so memory crosses the DLL boundary safely. Include <imgui_internal.h> beside <imgui.h> where you expand RPSUI_IMGUI_BUILD().

void RPSUI_CALL draw(const rpsui::api::framework::PanelDrawFrame* frame, void* userData) noexcept
{
RPSUI_IMGUI_BIND(frame->imgui);
ImGui::SetNextWindowPos({ 0, 0 });
ImGui::SetNextWindowSize({ frame->layoutWidth, frame->layoutHeight });
ImGui::Begin("Example", nullptr, ImGuiWindowFlags_NoDecoration);
ImGui::TextUnformatted("Hello");
ImGui::End();
}

setupCallback receives a PanelSetup once per context, before its first frame: on the panel's first draw, after a device change, after a theme change, and after the host rebuilt a context whose draw failed. The theme's style and faces are already in place; add your own fonts, adjust the style and create textures there. Fonts and textures you add belong to that context; contextGeneration changes when it is replaced, and anything made for the old one must be made again.

drawCallback receives a PanelDrawFrame between the host's NewFrame and Render. Before calling it, the host has set the display size, fed the pointer position, the primary button and the scroll axes, and turned the software cursor on while the pointer is valid. The frame's coordinates (pointerX, pointerY) are in layout units, the same as ImGui's DisplaySize and MousePos. backPressed is 1 on exactly one frame after each Back press on a ConfigNavigation panel; enqueue a bounded UI action from it, and leave game or settings writes to the game thread.

d3dDevice is the ID3D11Device for your own textures (ImTextureID is an ID3D11ShaderResourceView*). There is no render target or device context: the host renders the frame into the panel's own texture. Rebuild device textures when deviceGeneration changes.

An ImGui context lives until the panel is unregistered or the device changes, so ImGui state such as scroll positions survives closing and reopening the panel. Unbalanced Begin/End calls are recovered without asserts.

Themes​

Players choose how every panel looks: Theme in RPS_UI.toml names a theme file in the Themes folder beside it. The built-in themes are Pip-Boy (the default), New Vegas and Vault-Tec; a name with no file starts as a copy of Pip-Boy. Before your setup callback, the host sets the context's ImGui style from the theme, so plain ImGui widgets follow it without any code of yours.

PanelSetup::theme and PanelDrawFrame::theme point at the Theme record for the callback. Draw your own shapes with its colour roles (background, surface, hover, pressed, selected, border, divider, text, textMuted, textDisabled, accent, onAccent, focus, pending, invalid, success, scrim) instead of fixed colours. Sizes are in layout units: fontSize, titleFontSize, smallFontSize, targetHeight, padding, spacing, rounding and borderWidth. fonts holds the theme's four faces by FontRole: Interface (also io.FontDefault), Strong, Mono and Prose. A theme change rebuilds every panel's context, so your setup callback runs again; keep the theme pointer only for the callback that received it.

Panel shapes​

Set the ConfigNavigation panel flag only on panels that want raw stick and grip-back routing. For a radial wheel, combine Transparent, FixedSize, and CircularInput, draw the circle yourself, and omit ConfigNavigation; the opening hold and release-to-select gesture remain the consumer's policy. Text entry uses the Input interface's captureKeyboard.

Desktop previews and tests​

support/RPS_UI_Framework/ImGuiPanelHost.h in RPS UI Framework's repository is the code the host runs each panel frame with. Its LocalPanelHost runs your setup and draw callbacks in a desktop preview or test exactly as the game does, with its own context and DX11 renderer. It includes Dear ImGui and its DX11 backend, so only previews and tests use it; in the game, RPS UI Framework is the only host.