Added PushId() GetId() variants that takes string range to avoid user making unnecessary copies

docking
ocornut 10 years ago
parent 750b6c9224
commit a143e2e772

@ -1275,7 +1275,7 @@ public:
ImGuiWindow(const char* name);
~ImGuiWindow();
ImGuiID GetID(const char* str);
ImGuiID GetID(const char* str, const char* str_end = NULL);
ImGuiID GetID(const void* ptr);
bool FocusItemRegister(bool is_active, bool tab_stop = true); // Return true if focus is requested
@ -1621,10 +1621,10 @@ ImGuiWindow::~ImGuiWindow()
Name = NULL;
}
ImGuiID ImGuiWindow::GetID(const char* str)
ImGuiID ImGuiWindow::GetID(const char* str, const char* str_end)
{
ImGuiID seed = IDStack.back();
const ImGuiID id = ImHash(str, 0, seed);
const ImGuiID id = ImHash(str, str_end ? str_end - str : 0, seed);
RegisterAliveId(id);
return id;
}
@ -4948,6 +4948,12 @@ void ImGui::PushID(const char* str_id)
window->IDStack.push_back(window->GetID(str_id));
}
void ImGui::PushID(const char* str_id_begin, const char* str_id_end)
{
ImGuiWindow* window = GetCurrentWindow();
window->IDStack.push_back(window->GetID(str_id_begin, str_id_end));
}
void ImGui::PushID(const void* ptr_id)
{
ImGuiWindow* window = GetCurrentWindow();
@ -4973,6 +4979,12 @@ ImGuiID ImGui::GetID(const char* str_id)
return window->GetID(str_id);
}
ImGuiID ImGui::GetID(const char* str_id_begin, const char* str_id_end)
{
ImGuiWindow* window = GetCurrentWindow();
return window->GetID(str_id_begin, str_id_end);
}
ImGuiID ImGui::GetID(const void* ptr_id)
{
ImGuiWindow* window = GetCurrentWindow();

@ -260,10 +260,12 @@ namespace ImGui
// If you are creating widgets in a loop you most likely want to push a unique identifier so ImGui can differentiate them
// You can also use "##extra" within your widget name to distinguish them from each others (see 'Programmer Guide')
IMGUI_API void PushID(const char* str_id); // push identifier into the ID stack. IDs are hash of the *entire* stack!
IMGUI_API void PushID(const char* str_id_begin, const char* str_id_end);
IMGUI_API void PushID(const void* ptr_id);
IMGUI_API void PushID(const int int_id);
IMGUI_API void PopID();
IMGUI_API ImGuiID GetID(const char* str_id); // calculate unique ID (hash of whole ID stack + given parameter). useful if you want to query into ImGuiStorage yourself. otherwise rarely needed
IMGUI_API ImGuiID GetID(const char* str_id_begin, const char* str_id_end);
IMGUI_API ImGuiID GetID(const void* ptr_id);
// Widgets

Loading…
Cancel
Save