Browse Source

ImGuiStorage: tweak impl for BuildSortByKey().

pull/7752/head
ocornut 4 months ago
parent
commit
dbffb702f8
  1. 20
      imgui.cpp

20
imgui.cpp

@ -2542,20 +2542,18 @@ ImGuiStoragePair* ImLowerBound(ImGuiStoragePair* in_begin, ImGuiStoragePair* in_
return in_p; return in_p;
} }
static int IMGUI_CDECL PairComparerByID(const void* lhs, const void* rhs)
{
// We can't just do a subtraction because qsort uses signed integers and subtracting our ID doesn't play well with that.
ImGuiID lhs_v = ((const ImGuiStoragePair*)lhs)->key;
ImGuiID rhs_v = ((const ImGuiStoragePair*)rhs)->key;
return (lhs_v > rhs_v ? +1 : lhs_v < rhs_v ? -1 : 0);
}
// For quicker full rebuild of a storage (instead of an incremental one), you may add all your contents and then sort once. // For quicker full rebuild of a storage (instead of an incremental one), you may add all your contents and then sort once.
void ImGuiStorage::BuildSortByKey() void ImGuiStorage::BuildSortByKey()
{ {
struct StaticFunc ImQsort(Data.Data, (size_t)Data.Size, sizeof(ImGuiStoragePair), PairComparerByID);
{
static int IMGUI_CDECL PairComparerByID(const void* lhs, const void* rhs)
{
// We can't just do a subtraction because qsort uses signed integers and subtracting our ID doesn't play well with that.
if (((const ImGuiStoragePair*)lhs)->key > ((const ImGuiStoragePair*)rhs)->key) return +1;
if (((const ImGuiStoragePair*)lhs)->key < ((const ImGuiStoragePair*)rhs)->key) return -1;
return 0;
}
};
ImQsort(Data.Data, (size_t)Data.Size, sizeof(ImGuiStoragePair), StaticFunc::PairComparerByID);
} }
int ImGuiStorage::GetInt(ImGuiID key, int default_val) const int ImGuiStorage::GetInt(ImGuiID key, int default_val) const

Loading…
Cancel
Save