diff --git a/imgui.cpp b/imgui.cpp index 721fbe118..0be695469 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -2624,6 +2624,14 @@ ImGuiID ImGuiWindow::GetID(const void* ptr) return id; } +ImGuiID ImGuiWindow::GetID(int n) +{ + ImGuiID seed = IDStack.back(); + ImGuiID id = ImHashData(&n, sizeof(n), seed); + ImGui::KeepAliveID(id); + return id; +} + ImGuiID ImGuiWindow::GetIDNoKeepAlive(const char* str, const char* str_end) { ImGuiID seed = IDStack.back(); @@ -2636,6 +2644,12 @@ ImGuiID ImGuiWindow::GetIDNoKeepAlive(const void* ptr) return ImHashData(&ptr, sizeof(void*), seed); } +ImGuiID ImGuiWindow::GetIDNoKeepAlive(int n) +{ + ImGuiID seed = IDStack.back(); + return ImHashData(&n, sizeof(n), seed); +} + // This is only used in rare/specific situations to manufacture an ID out of nowhere. ImGuiID ImGuiWindow::GetIDFromRectangle(const ImRect& r_abs) { @@ -6836,9 +6850,8 @@ void ImGui::PushID(const void* ptr_id) void ImGui::PushID(int int_id) { - const void* ptr_id = (void*)(intptr_t)int_id; ImGuiWindow* window = GImGui->CurrentWindow; - window->IDStack.push_back(window->GetIDNoKeepAlive(ptr_id)); + window->IDStack.push_back(window->GetIDNoKeepAlive(int_id)); } // Push a given id value ignoring the ID stack as a seed. diff --git a/imgui_internal.h b/imgui_internal.h index 1760bbb2d..ab14d9f36 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -1330,8 +1330,10 @@ public: ImGuiID GetID(const char* str, const char* str_end = NULL); ImGuiID GetID(const void* ptr); + ImGuiID GetID(int n); ImGuiID GetIDNoKeepAlive(const char* str, const char* str_end = NULL); ImGuiID GetIDNoKeepAlive(const void* ptr); + ImGuiID GetIDNoKeepAlive(int n); ImGuiID GetIDFromRectangle(const ImRect& r_abs); // We don't use g.FontSize because the window may be != g.CurrentWidow.