Context: Renamed SetMemoryAllocators() to SetAllocatorFunctions(). Tweaked comments. (#1565, #586, #992, #1007, #1558)

This commit is contained in:
omar 2018-01-21 19:44:48 +01:00
parent e45d7a7060
commit 7e4d28a49d
2 changed files with 13 additions and 13 deletions

View File

@ -213,7 +213,7 @@
Here is a change-log of API breaking changes, if you are using one of the functions listed, expect to have to fix some code. Here is a change-log of API breaking changes, if you are using one of the functions listed, expect to have to fix some code.
Also read releases logs https://github.com/ocornut/imgui/releases for more details. Also read releases logs https://github.com/ocornut/imgui/releases for more details.
- 2018/01/20 (1.XX) - removed allocator parameters from CreateContext(), they are now setup with SetMemoryAllocators() and shared by all contexts. - 2018/01/20 (1.XX) - removed allocator parameters from CreateContext(), they are now setup with SetAllocatorFunctions() and shared by all contexts.
- 2018/01/11 (1.54) - obsoleted IsAnyWindowHovered() in favor of IsWindowHovered(ImGuiHoveredFlags_AnyWindow). Kept redirection function (will obsolete). - 2018/01/11 (1.54) - obsoleted IsAnyWindowHovered() in favor of IsWindowHovered(ImGuiHoveredFlags_AnyWindow). Kept redirection function (will obsolete).
- 2018/01/11 (1.54) - obsoleted IsAnyWindowFocused() in favor of IsWindowFocused(ImGuiFocusedFlags_AnyWindow). Kept redirection function (will obsolete). - 2018/01/11 (1.54) - obsoleted IsAnyWindowFocused() in favor of IsWindowFocused(ImGuiFocusedFlags_AnyWindow). Kept redirection function (will obsolete).
- 2018/01/03 (1.54) - renamed ImGuiSizeConstraintCallback to ImGuiSizeCallback, ImGuiSizeConstraintCallbackData to ImGuiSizeCallbackData. - 2018/01/03 (1.54) - renamed ImGuiSizeConstraintCallback to ImGuiSizeCallback, ImGuiSizeConstraintCallbackData to ImGuiSizeCallbackData.
@ -710,8 +710,8 @@ static ImGuiContext GImDefaultContext;
ImGuiContext* GImGui = &GImDefaultContext; ImGuiContext* GImGui = &GImDefaultContext;
#endif #endif
// Memory Allocator Functions. Use SetMemoryAllocators() to change them. // Memory Allocator functions. Use SetAllocatorFunctions() to change them.
// If you use DLL hotreloading you might need to call SetMemoryAllocators() after reloading code from this file. // If you use DLL hotreloading you might need to call SetAllocatorFunctions() after reloading code from this file.
// Otherwise, you probably don't want to modify them mid-program, and if you use global/static e.g. ImVector<> instances you may need to keep them accessible during program destruction. // Otherwise, you probably don't want to modify them mid-program, and if you use global/static e.g. ImVector<> instances you may need to keep them accessible during program destruction.
#ifndef IMGUI_DISABLE_DEFAULT_ALLOCATORS #ifndef IMGUI_DISABLE_DEFAULT_ALLOCATORS
static void* MallocWrapper(size_t size, void* user_data) { (void)user_data; return malloc(size); } static void* MallocWrapper(size_t size, void* user_data) { (void)user_data; return malloc(size); }
@ -724,7 +724,7 @@ static void FreeWrapper(void* ptr, void* user_data) { (void)user_data;
static void* (*GImAllocatorAllocFunc)(size_t size, void* user_data) = MallocWrapper; static void* (*GImAllocatorAllocFunc)(size_t size, void* user_data) = MallocWrapper;
static void (*GImAllocatorFreeFunc)(void* ptr, void* user_data) = FreeWrapper; static void (*GImAllocatorFreeFunc)(void* ptr, void* user_data) = FreeWrapper;
static void* GImAllocatorUserData = NULL; static void* GImAllocatorUserData = NULL;
static size_t GImAllocatorActiveCount = 0; static size_t GImAllocatorActiveAllocationsCount = 0;
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// User facing structures // User facing structures
@ -2188,13 +2188,13 @@ float ImGui::CalcWrapWidthForPos(const ImVec2& pos, float wrap_pos_x)
void* ImGui::MemAlloc(size_t sz) void* ImGui::MemAlloc(size_t sz)
{ {
GImAllocatorActiveCount++; GImAllocatorActiveAllocationsCount++;
return GImAllocatorAllocFunc(sz, GImAllocatorUserData); return GImAllocatorAllocFunc(sz, GImAllocatorUserData);
} }
void ImGui::MemFree(void* ptr) void ImGui::MemFree(void* ptr)
{ {
if (ptr) GImAllocatorActiveCount--; if (ptr) GImAllocatorActiveAllocationsCount--;
return GImAllocatorFreeFunc(ptr, GImAllocatorUserData); return GImAllocatorFreeFunc(ptr, GImAllocatorUserData);
} }
@ -2230,10 +2230,10 @@ void ImGui::SetCurrentContext(ImGuiContext* ctx)
#endif #endif
} }
void ImGui::SetMemoryAllocators(void* (*alloc_fn)(size_t sz, void* user_data), void(*free_fn)(void* ptr, void* user_data), void* user_data) void ImGui::SetAllocatorFunctions(void* (*alloc_func)(size_t sz, void* user_data), void(*free_func)(void* ptr, void* user_data), void* user_data)
{ {
GImAllocatorAllocFunc = alloc_fn; GImAllocatorAllocFunc = alloc_func;
GImAllocatorFreeFunc = free_fn; GImAllocatorFreeFunc = free_func;
GImAllocatorUserData = user_data; GImAllocatorUserData = user_data;
} }
@ -11684,7 +11684,7 @@ void ImGui::ShowMetricsWindow(bool* p_open)
ImGui::Text("Dear ImGui %s", ImGui::GetVersion()); ImGui::Text("Dear ImGui %s", ImGui::GetVersion());
ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate); ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate);
ImGui::Text("%d vertices, %d indices (%d triangles)", ImGui::GetIO().MetricsRenderVertices, ImGui::GetIO().MetricsRenderIndices, ImGui::GetIO().MetricsRenderIndices / 3); ImGui::Text("%d vertices, %d indices (%d triangles)", ImGui::GetIO().MetricsRenderVertices, ImGui::GetIO().MetricsRenderIndices, ImGui::GetIO().MetricsRenderIndices / 3);
ImGui::Text("%d allocations", GImAllocatorActiveCount); ImGui::Text("%d allocations", GImAllocatorActiveAllocationsCount);
static bool show_clip_rects = true; static bool show_clip_rects = true;
ImGui::Checkbox("Show clipping rectangles when hovering an ImDrawCmd", &show_clip_rects); ImGui::Checkbox("Show clipping rectangles when hovering an ImDrawCmd", &show_clip_rects);
ImGui::Separator(); ImGui::Separator();

View File

@ -503,8 +503,9 @@ namespace ImGui
IMGUI_API void CaptureKeyboardFromApp(bool capture = true); // manually override io.WantCaptureKeyboard flag next frame (said flag is entirely left for your application handle). e.g. force capture keyboard when your widget is being hovered. IMGUI_API void CaptureKeyboardFromApp(bool capture = true); // manually override io.WantCaptureKeyboard flag next frame (said flag is entirely left for your application handle). e.g. force capture keyboard when your widget is being hovered.
IMGUI_API void CaptureMouseFromApp(bool capture = true); // manually override io.WantCaptureMouse flag next frame (said flag is entirely left for your application handle). IMGUI_API void CaptureMouseFromApp(bool capture = true); // manually override io.WantCaptureMouse flag next frame (said flag is entirely left for your application handle).
// Helpers functions to access functions pointers in ImGui::GetIO() // Helpers functions to access memory allocators and clipboard functions.
IMGUI_API void* MemAlloc(size_t sz); IMGUI_API void SetAllocatorFunctions(void* (*alloc_func)(size_t sz, void* user_data), void(*free_func)(void* ptr, void* user_data), void* user_data = NULL);
IMGUI_API void* MemAlloc(size_t size);
IMGUI_API void MemFree(void* ptr); IMGUI_API void MemFree(void* ptr);
IMGUI_API const char* GetClipboardText(); IMGUI_API const char* GetClipboardText();
IMGUI_API void SetClipboardText(const char* text); IMGUI_API void SetClipboardText(const char* text);
@ -513,7 +514,6 @@ namespace ImGui
// All contexts share a same ImFontAtlas by default. If you want different font atlas, you can new() them and overwrite the GetIO().Fonts variable of an ImGui context. // All contexts share a same ImFontAtlas by default. If you want different font atlas, you can new() them and overwrite the GetIO().Fonts variable of an ImGui context.
// All those functions are not reliant on the current context. // All those functions are not reliant on the current context.
IMGUI_API const char* GetVersion(); IMGUI_API const char* GetVersion();
IMGUI_API void SetMemoryAllocators(void* (*alloc_fn)(size_t sz, void* user_data), void(*free_fn)(void* ptr, void* user_data), void* user_data = NULL);
IMGUI_API ImGuiContext* CreateContext(); IMGUI_API ImGuiContext* CreateContext();
IMGUI_API void DestroyContext(ImGuiContext* ctx); IMGUI_API void DestroyContext(ImGuiContext* ctx);
IMGUI_API ImGuiContext* GetCurrentContext(); IMGUI_API ImGuiContext* GetCurrentContext();