TestEngine: Added PushID() hooks.

This commit is contained in:
omar 2020-04-16 16:57:17 +02:00
parent b0e9092d6f
commit 9f9ff84ba1
3 changed files with 43 additions and 10 deletions

View File

@ -6597,6 +6597,7 @@ void ImGui::PushFocusScope(ImGuiID id)
ImGuiWindow* window = g.CurrentWindow; ImGuiWindow* window = g.CurrentWindow;
window->IDStack.push_back(window->DC.NavFocusScopeIdCurrent); window->IDStack.push_back(window->DC.NavFocusScopeIdCurrent);
window->DC.NavFocusScopeIdCurrent = id; window->DC.NavFocusScopeIdCurrent = id;
IMGUI_TEST_ENGINE_PUSH_ID(id, ImGuiDataType_ID, NULL);
} }
void ImGui::PopFocusScope() void ImGui::PopFocusScope()
@ -6648,33 +6649,47 @@ ImGuiStorage* ImGui::GetStateStorage()
void ImGui::PushID(const char* str_id) void ImGui::PushID(const char* str_id)
{ {
ImGuiWindow* window = GImGui->CurrentWindow; ImGuiContext& g = *GImGui;
window->IDStack.push_back(window->GetIDNoKeepAlive(str_id)); ImGuiWindow* window = g.CurrentWindow;
ImGuiID id = window->GetIDNoKeepAlive(str_id);
window->IDStack.push_back(id);
IMGUI_TEST_ENGINE_PUSH_ID(id, ImGuiDataType_String, str_id);
} }
void ImGui::PushID(const char* str_id_begin, const char* str_id_end) void ImGui::PushID(const char* str_id_begin, const char* str_id_end)
{ {
ImGuiWindow* window = GImGui->CurrentWindow; ImGuiContext& g = *GImGui;
window->IDStack.push_back(window->GetIDNoKeepAlive(str_id_begin, str_id_end)); ImGuiWindow* window = g.CurrentWindow;
ImGuiID id = window->GetIDNoKeepAlive(str_id_begin, str_id_end);
window->IDStack.push_back(id);
IMGUI_TEST_ENGINE_PUSH_ID2(id, ImGuiDataType_String, str_id_begin, str_id_end);
} }
void ImGui::PushID(const void* ptr_id) void ImGui::PushID(const void* ptr_id)
{ {
ImGuiWindow* window = GImGui->CurrentWindow; ImGuiContext& g = *GImGui;
window->IDStack.push_back(window->GetIDNoKeepAlive(ptr_id)); ImGuiWindow* window = g.CurrentWindow;
ImGuiID id = window->GetIDNoKeepAlive(ptr_id);
window->IDStack.push_back(id);
IMGUI_TEST_ENGINE_PUSH_ID(id, ImGuiDataType_Pointer, ptr_id);
} }
void ImGui::PushID(int int_id) void ImGui::PushID(int int_id)
{ {
ImGuiWindow* window = GImGui->CurrentWindow; ImGuiContext& g = *GImGui;
window->IDStack.push_back(window->GetIDNoKeepAlive(int_id)); ImGuiWindow* window = g.CurrentWindow;
ImGuiID id = window->GetIDNoKeepAlive(int_id);
window->IDStack.push_back(id);
IMGUI_TEST_ENGINE_PUSH_ID(id, ImGuiDataType_S32, (intptr_t)int_id);
} }
// Push a given id value ignoring the ID stack as a seed. // Push a given id value ignoring the ID stack as a seed.
void ImGui::PushOverrideID(ImGuiID id) void ImGui::PushOverrideID(ImGuiID id)
{ {
ImGuiWindow* window = GImGui->CurrentWindow; ImGuiContext& g = *GImGui;
ImGuiWindow* window = g.CurrentWindow;
window->IDStack.push_back(id); window->IDStack.push_back(id);
IMGUI_TEST_ENGINE_PUSH_ID(id, ImGuiDataType_ID, NULL);
} }
void ImGui::PopID() void ImGui::PopID()

View File

@ -723,6 +723,14 @@ struct ImGuiDataTypeInfo
const char* ScanFmt; // Default scanf format for the type const char* ScanFmt; // Default scanf format for the type
}; };
// Extend ImGuiDataType_
enum ImGuiDataTypePrivate_
{
ImGuiDataType_String = ImGuiDataType_COUNT + 1,
ImGuiDataType_Pointer,
ImGuiDataType_ID
};
// Stacked color modifier, backup of modified data so we can restore it // Stacked color modifier, backup of modified data so we can restore it
struct ImGuiColorMod struct ImGuiColorMod
{ {
@ -1035,6 +1043,7 @@ struct ImGuiContext
bool WithinFrameScopeWithImplicitWindow; // Set by NewFrame(), cleared by EndFrame() when the implicit debug window has been pushed bool WithinFrameScopeWithImplicitWindow; // Set by NewFrame(), cleared by EndFrame() when the implicit debug window has been pushed
bool WithinEndChild; // Set within EndChild() bool WithinEndChild; // Set within EndChild()
bool TestEngineHookItems; // Will call test engine hooks ImGuiTestEngineHook_ItemAdd(), ImGuiTestEngineHook_ItemInfo(), ImGuiTestEngineHook_Log() bool TestEngineHookItems; // Will call test engine hooks ImGuiTestEngineHook_ItemAdd(), ImGuiTestEngineHook_ItemInfo(), ImGuiTestEngineHook_Log()
ImGuiID TestEngineHookPushId;
void* TestEngine; // Test engine user data void* TestEngine; // Test engine user data
// Windows state // Windows state
@ -1244,6 +1253,7 @@ struct ImGuiContext
FrameCountEnded = FrameCountRendered = -1; FrameCountEnded = FrameCountRendered = -1;
WithinFrameScope = WithinFrameScopeWithImplicitWindow = WithinEndChild = false; WithinFrameScope = WithinFrameScopeWithImplicitWindow = WithinEndChild = false;
TestEngineHookItems = false; TestEngineHookItems = false;
TestEngineHookPushId = 0;
TestEngine = NULL; TestEngine = NULL;
WindowsActiveCount = 0; WindowsActiveCount = 0;
@ -1941,14 +1951,20 @@ extern void ImGuiTestEngineHook_PreNewFrame(ImGuiContext* ctx);
extern void ImGuiTestEngineHook_PostNewFrame(ImGuiContext* ctx); extern void ImGuiTestEngineHook_PostNewFrame(ImGuiContext* ctx);
extern void ImGuiTestEngineHook_ItemAdd(ImGuiContext* ctx, const ImRect& bb, ImGuiID id); 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_ItemInfo(ImGuiContext* ctx, ImGuiID id, const char* label, ImGuiItemStatusFlags flags);
extern void ImGuiTestEngineHook_PushID(ImGuiContext* ctx, ImGuiDataType data_type, ImGuiID id, const void* data_id);
extern void ImGuiTestEngineHook_PushID(ImGuiContext* ctx, ImGuiDataType data_type, ImGuiID id, const void* data_id, const void* data_id_end);
extern void ImGuiTestEngineHook_Log(ImGuiContext* ctx, const char* fmt, ...); extern void ImGuiTestEngineHook_Log(ImGuiContext* ctx, const char* fmt, ...);
#define IMGUI_TEST_ENGINE_ITEM_ADD(_BB,_ID) if (g.TestEngineHookItems) ImGuiTestEngineHook_ItemAdd(&g, _BB, _ID) // Register item bounding box #define IMGUI_TEST_ENGINE_ITEM_ADD(_BB,_ID) if (g.TestEngineHookItems) ImGuiTestEngineHook_ItemAdd(&g, _BB, _ID) // Register item bounding box
#define IMGUI_TEST_ENGINE_ITEM_INFO(_ID,_LABEL,_FLAGS) if (g.TestEngineHookItems) ImGuiTestEngineHook_ItemInfo(&g, _ID, _LABEL, _FLAGS) // Register item label and status flags (optional) #define IMGUI_TEST_ENGINE_ITEM_INFO(_ID,_LABEL,_FLAGS) if (g.TestEngineHookItems) ImGuiTestEngineHook_ItemInfo(&g, _ID, _LABEL, _FLAGS) // Register item label and status flags (optional)
#define IMGUI_TEST_ENGINE_LOG(_FMT,...) if (g.TestEngineHookItems) ImGuiTestEngineHook_Log(&g, _FMT, __VA_ARGS__) // Custom log entry from user land into test log #define IMGUI_TEST_ENGINE_LOG(_FMT,...) if (g.TestEngineHookItems) ImGuiTestEngineHook_Log(&g, _FMT, __VA_ARGS__) // Custom log entry from user land into test log
#define IMGUI_TEST_ENGINE_PUSH_ID(_ID,_TYPE,_DATA) if (g.TestEngineHookPushId == id) ImGuiTestEngineHook_PushID(&g, _TYPE, _ID, (const void*)(_DATA));
#define IMGUI_TEST_ENGINE_PUSH_ID2(_ID,_TYPE,_DATA,_DATA2) if (g.TestEngineHookPushId == id) ImGuiTestEngineHook_PushID(&g, _TYPE, _ID, (const void*)(_DATA), (const void*)(_DATA2));
#else #else
#define IMGUI_TEST_ENGINE_ITEM_ADD(_BB,_ID) do { } while (0) #define IMGUI_TEST_ENGINE_ITEM_ADD(_BB,_ID) do { } while (0)
#define IMGUI_TEST_ENGINE_ITEM_INFO(_ID,_LABEL,_FLAGS) do { } while (0) #define IMGUI_TEST_ENGINE_ITEM_INFO(_ID,_LABEL,_FLAGS) do { } while (0)
#define IMGUI_TEST_ENGINE_LOG(_FMT,...) do { } while (0) #define IMGUI_TEST_ENGINE_LOG(_FMT,...) do { } while (0)
#define IMGUI_TEST_ENGINE_PUSH_ID(_ID,_TYPE,_DATA) do { } while (0)
#define IMGUI_TEST_ENGINE_PUSH_ID2(_ID,_TYPE,_DATA,_DATA2) do { } while (0)
#endif #endif
#if defined(__clang__) #if defined(__clang__)

View File

@ -5493,10 +5493,12 @@ void ImGui::TreePush(const void* ptr_id)
void ImGui::TreePushOverrideID(ImGuiID id) void ImGui::TreePushOverrideID(ImGuiID id)
{ {
ImGuiWindow* window = GetCurrentWindow(); ImGuiContext& g = *GImGui;
ImGuiWindow* window = g.CurrentWindow;
Indent(); Indent();
window->DC.TreeDepth++; window->DC.TreeDepth++;
window->IDStack.push_back(id); window->IDStack.push_back(id);
IMGUI_TEST_ENGINE_PUSH_ID(id, ImGuiDataType_ID, NULL);
} }
void ImGui::TreePop() void ImGui::TreePop()