Internals: Added support for context hooks (for test engine or other extensions)

This commit is contained in:
ocornut
2020-10-09 17:13:03 +02:00
parent e5cb04b132
commit a38c6dfcc8
3 changed files with 60 additions and 18 deletions

View File

@ -19,16 +19,17 @@ Index of this file:
// [SECTION] ImDrawList support
// [SECTION] Widgets support: flags, enums, data structures
// [SECTION] Columns support
// [SECTION] Settings support
// [SECTION] Multi-select support
// [SECTION] Docking support
// [SECTION] Viewport support
// [SECTION] Settings support
// [SECTION] Generic context hooks
// [SECTION] ImGuiContext (main imgui context)
// [SECTION] ImGuiWindowTempData, ImGuiWindow
// [SECTION] Tab bar, Tab item support
// [SECTION] Table support
// [SECTION] Internal API
// [SECTION] Test Engine Hooks (imgui_test_engine)
// [SECTION] Test Engine specific hooks (imgui_test_engine)
*/
@ -93,6 +94,7 @@ struct ImGuiColorMod; // Stacked color modifier, backup of modifie
struct ImGuiColumnData; // Storage data for a single column
struct ImGuiColumns; // Storage data for a columns set
struct ImGuiContext; // Main Dear ImGui context
struct ImGuiContextHook; // Hook for extensions like ImGuiTestEngine
struct ImGuiDataTypeInfo; // Type information associated to a ImGuiDataType enum
struct ImGuiGroupData; // Stacked storage data for BeginGroup()/EndGroup()
struct ImGuiInputTextState; // Internal state of the currently focused/edited text input box
@ -1099,6 +1101,23 @@ struct ImGuiSettingsHandler
ImGuiSettingsHandler() { memset(this, 0, sizeof(*this)); }
};
//-----------------------------------------------------------------------------
// [SECTION] Generic context hooks
//-----------------------------------------------------------------------------
typedef void (*ImGuiContextHookCallback)(ImGuiContext* ctx, ImGuiContextHook* hook);
enum ImGuiContextHookType { ImGuiContextHookType_NewFramePre, ImGuiContextHookType_NewFramePost, ImGuiContextHookType_EndFramePre, ImGuiContextHookType_EndFramePost, ImGuiContextHookType_RenderPre, ImGuiContextHookType_RenderPost, ImGuiContextHookType_Shutdown };
struct ImGuiContextHook
{
ImGuiContextHookType Type;
ImGuiID Owner;
ImGuiContextHookCallback Callback;
void* UserData;
ImGuiContextHook() { memset(this, 0, sizeof(*this)); }
};
//-----------------------------------------------------------------------------
// [SECTION] ImGuiContext (main imgui context)
//-----------------------------------------------------------------------------
@ -1301,6 +1320,7 @@ struct ImGuiContext
ImGuiTextBuffer SettingsIniData; // In memory .ini settings
ImVector<ImGuiSettingsHandler> SettingsHandlers; // List of .ini settings handlers
ImChunkStream<ImGuiWindowSettings> SettingsWindows; // ImGuiWindow .ini settings entries
ImVector<ImGuiContextHook> Hooks; // Hooks for extensions (e.g. test engine)
// Capture/Logging
bool LogEnabled; // Currently capturing
@ -1819,6 +1839,10 @@ namespace ImGui
IMGUI_API void UpdateMouseMovingWindowNewFrame();
IMGUI_API void UpdateMouseMovingWindowEndFrame();
// Generic context hooks
IMGUI_API void AddContextHook(ImGuiContext* context, const ImGuiContextHook* hook);
IMGUI_API void CallContextHooks(ImGuiContext* context, ImGuiContextHookType type);
// Settings
IMGUI_API void MarkIniSettingsDirty();
IMGUI_API void MarkIniSettingsDirty(ImGuiWindow* window);
@ -2055,13 +2079,10 @@ IMGUI_API void ImFontAtlasBuildMultiplyCalcLookupTable(unsigned cha
IMGUI_API void ImFontAtlasBuildMultiplyRectAlpha8(const unsigned char table[256], unsigned char* pixels, int x, int y, int w, int h, int stride);
//-----------------------------------------------------------------------------
// [SECTION] Test Engine Hooks (imgui_test_engine)
// [SECTION] Test Engine specific hooks (imgui_test_engine)
//-----------------------------------------------------------------------------
#ifdef IMGUI_ENABLE_TEST_ENGINE
extern void ImGuiTestEngineHook_Shutdown(ImGuiContext* ctx);
extern void ImGuiTestEngineHook_PreNewFrame(ImGuiContext* ctx);
extern void ImGuiTestEngineHook_PostNewFrame(ImGuiContext* ctx);
extern void ImGuiTestEngineHook_ItemAdd(ImGuiContext* ctx, const ImRect& bb, ImGuiID id);
extern void ImGuiTestEngineHook_ItemInfo(ImGuiContext* ctx, ImGuiID id, const char* label, ImGuiItemStatusFlags flags);
extern void ImGuiTestEngineHook_IdInfo(ImGuiContext* ctx, ImGuiDataType data_type, ImGuiID id, const void* data_id);
@ -2080,6 +2101,8 @@ extern void ImGuiTestEngineHook_Log(ImGuiContext* ctx, const cha
#define IMGUI_TEST_ENGINE_ID_INFO2(_ID,_TYPE,_DATA,_DATA2) do { } while (0)
#endif
//-----------------------------------------------------------------------------
#if defined(__clang__)
#pragma clang diagnostic pop
#elif defined(__GNUC__)