mirror of
https://github.com/cimgui/cimgui.git
synced 2025-08-13 21:28:30 +01:00
Merge pull request #120 from mellinoe/docking_template_additions
Add CimguiStorage and ImGuiPlatformIO redirect functions to the master branch.
This commit is contained in:
@@ -35,6 +35,7 @@ Notes:
|
|||||||
* edit config_generator.lua for adding includes needed by your chosen implementations.
|
* edit config_generator.lua for adding includes needed by your chosen implementations.
|
||||||
* Run generator.bat or generator.sh with gcc, clang or cl and LuaJIT on your PATH.
|
* Run generator.bat or generator.sh with gcc, clang or cl and LuaJIT on your PATH.
|
||||||
* as a result some files are generated: `cimgui.cpp` and `cimgui.h` for compiling and some lua/json files with information about the binding: `definitions.json` with function info, `structs_and_enums.json` with struct and enum info, `impl_definitions.json` with functions from the implementations info.
|
* as a result some files are generated: `cimgui.cpp` and `cimgui.h` for compiling and some lua/json files with information about the binding: `definitions.json` with function info, `structs_and_enums.json` with struct and enum info, `impl_definitions.json` with functions from the implementations info.
|
||||||
|
* If you are generating bindings for the [docking](https://github.com/ocornut/imgui/tree/docking) branch of imgui, you must define the `IMGUI_DOCKING` constant in CMakeLists.txt. This includes extra custom definitions that are needed for some functionality on the docking branch.
|
||||||
|
|
||||||
# generate binding
|
# generate binding
|
||||||
* C interface is exposed by cimgui.h when you define CIMGUI_DEFINE_ENUMS_AND_STRUCTS
|
* C interface is exposed by cimgui.h when you define CIMGUI_DEFINE_ENUMS_AND_STRUCTS
|
||||||
|
@@ -59,3 +59,62 @@ CIMGUI_API void ImVector_ImWchar_UnInit(ImVector_ImWchar* p)
|
|||||||
p->~ImVector<ImWchar>();
|
p->~ImVector<ImWchar>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef IMGUI_DOCKING
|
||||||
|
|
||||||
|
// NOTE: Some function pointers in the ImGuiPlatformIO structure are not C-compatible because of their
|
||||||
|
// use of a complex return type. To work around this, we store a custom CimguiStorage object inside
|
||||||
|
// ImGuiIO::BackendLanguageUserData, which contains C-compatible function pointer variants for these
|
||||||
|
// functions. When a user function pointer is provided, we hook up the underlying ImGuiPlatformIO
|
||||||
|
// function pointer to a thunk which accesses the user function pointer through CimguiStorage.
|
||||||
|
|
||||||
|
struct CimguiStorage
|
||||||
|
{
|
||||||
|
void(*Platform_GetWindowPos)(ImGuiViewport* vp, ImVec2* out_pos);
|
||||||
|
void(*Platform_GetWindowSize)(ImGuiViewport* vp, ImVec2* out_pos);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Gets a reference to the CimguiStorage object stored in the current ImGui context's BackendLanguageUserData.
|
||||||
|
CimguiStorage& GetCimguiStorage()
|
||||||
|
{
|
||||||
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
if (io.BackendLanguageUserData == NULL)
|
||||||
|
{
|
||||||
|
io.BackendLanguageUserData = new CimguiStorage();
|
||||||
|
}
|
||||||
|
|
||||||
|
return *(CimguiStorage*)io.BackendLanguageUserData;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Thunk satisfying the signature of ImGuiPlatformIO::Platform_GetWindowPos.
|
||||||
|
ImVec2 Platform_GetWindowPos_hook(ImGuiViewport* vp)
|
||||||
|
{
|
||||||
|
ImVec2 pos;
|
||||||
|
GetCimguiStorage().Platform_GetWindowPos(vp, &pos);
|
||||||
|
return pos;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Fully C-compatible function pointer setter for ImGuiPlatformIO::Platform_GetWindowPos.
|
||||||
|
CIMGUI_API void ImGuiPlatformIO_Set_Platform_GetWindowPos(ImGuiPlatformIO* platform_io, void(*user_callback)(ImGuiViewport* vp, ImVec2* out_pos))
|
||||||
|
{
|
||||||
|
CimguiStorage& storage = GetCimguiStorage();
|
||||||
|
storage.Platform_GetWindowPos = user_callback;
|
||||||
|
platform_io->Platform_GetWindowPos = &Platform_GetWindowPos_hook;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Thunk satisfying the signature of ImGuiPlatformIO::Platform_GetWindowSize.
|
||||||
|
ImVec2 Platform_GetWindowSize_hook(ImGuiViewport* vp)
|
||||||
|
{
|
||||||
|
ImVec2 size;
|
||||||
|
GetCimguiStorage().Platform_GetWindowSize(vp, &size);
|
||||||
|
return size;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Fully C-compatible function pointer setter for ImGuiPlatformIO::Platform_GetWindowSize.
|
||||||
|
CIMGUI_API void ImGuiPlatformIO_Set_Platform_GetWindowSize(ImGuiPlatformIO* platform_io, void(*user_callback)(ImGuiViewport* vp, ImVec2* out_size))
|
||||||
|
{
|
||||||
|
CimguiStorage& storage = GetCimguiStorage();
|
||||||
|
storage.Platform_GetWindowSize = user_callback;
|
||||||
|
platform_io->Platform_GetWindowSize = &Platform_GetWindowSize_hook;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
Reference in New Issue
Block a user