caliper.ui.v1¶
Service id caliper.ui.v1 gives an applet the ImGui, ImPlot and ImPlot3D contexts and the host allocator handoff.
Calls¶
| Call | Signature | Description |
|---|---|---|
imgui_context |
struct ImGuiContext* (void) |
Return the shared ImGuiContext of the host. The pointer stays valid from initialize() through cleanup(). |
implot_context |
struct ImPlotContext* (void) |
Return the shared ImPlotContext of the host. The pointer stays valid from initialize() through cleanup(). |
implot3d_context |
struct ImPlot3DContext* (void) |
Return the shared ImPlot3DContext of the host. The pointer stays valid from initialize() through cleanup(). |
imgui_allocators |
void (CaliperImGuiAllocFn* out_alloc, CaliperImGuiFreeFn* out_free, void** out_user_data) |
Write the allocator pair of the host to out_alloc, out_free, and out_user_data. The applet must install the pair into its copy of the ImGui globals before it makes any allocation, so that every allocation lands on the host heap. |
Types¶
CaliperImGuiAllocFn¶
The type of an allocation function. It takes a size in bytes and the user_data pointer and returns the new memory.
typedef void* (*CaliperImGuiAllocFn)(size_t sz, void* user_data);
CaliperImGuiFreeFn¶
The type of a free function. It takes a pointer from the matching allocation function and the user_data pointer.
typedef void (*CaliperImGuiFreeFn)(void* ptr, void* user_data);
CaliperUiV1¶
The function table of caliper.ui.v1. Call every entry from the UI thread.
| Field | Type | Description |
|---|---|---|
struct_size |
uint32_t |
sizeof(CaliperUiV1) as the host built it. |
imgui_context |
struct ImGuiContext* (*)(void) |
Return the shared ImGuiContext of the host. The pointer stays valid from initialize() through cleanup(). |
implot_context |
struct ImPlotContext* (*)(void) |
Return the shared ImPlotContext of the host. The pointer stays valid from initialize() through cleanup(). |
implot3d_context |
struct ImPlot3DContext* (*)(void) |
Return the shared ImPlot3DContext of the host. The pointer stays valid from initialize() through cleanup(). |
imgui_allocators |
void (*)(CaliperImGuiAllocFn* out_alloc, CaliperImGuiFreeFn* out_free, void** out_user_data) |
Write the allocator pair of the host to out_alloc, out_free, and out_user_data. The applet must install the pair into its copy of the ImGui globals before it makes any allocation, so that every allocation lands on the host heap. |
Ids¶
| Name | Value | Description |
|---|---|---|
CALIPER_UI_V1 |
"caliper.ui.v1" |
The id of this service, which get_service takes. |
Semantics¶
- Context lifetime. The host owns the three context pointers (
imgui_context,implot_contextandimplot3d_context). They stay valid frominitialize()throughcleanup(). They never change while the applet runs, so an applet may cache them. - Allocator handoff is mandatory. An applet links its own copy of Dear ImGui, and that copy has its own allocator globals. Before the applet makes any ImGui, ImPlot or ImPlot3D allocation, it MUST call
imgui_allocators(...). It then installs the returned(alloc, free, user_data)triple into its copy withImGui::SetAllocatorFunctionsand sets the current context to the host context. If the applet skips this, it allocates on its own heap while the host frees on another heap. This is the cross-DLL heap mismatch. The SDK functionui::connectdoes the whole handoff duringinitialize(). A hand-written C applet must do the handoff itself. - UI thread only. Every function in this header and every ImGui call on the shared context must run on the host UI thread. This is the same thread that calls the
frame()function of the applet. The context has no locking, and a call from a worker thread is undefined behavior. Put long or blocking work in background jobs.