For quicker full rebuild of a storage (instead of an incremental one), you may add all your contents and then sort once.
| 2116 | |
| 2117 | // For quicker full rebuild of a storage (instead of an incremental one), you may add all your contents and then sort once. |
| 2118 | void ImGuiStorage::BuildSortByKey() |
| 2119 | { |
| 2120 | struct StaticFunc |
| 2121 | { |
| 2122 | static int IMGUI_CDECL PairComparerByID(const void* lhs, const void* rhs) |
| 2123 | { |
| 2124 | // We can't just do a subtraction because qsort uses signed integers and subtracting our ID doesn't play well with that. |
| 2125 | if (((const ImGuiStoragePair*)lhs)->key > ((const ImGuiStoragePair*)rhs)->key) return +1; |
| 2126 | if (((const ImGuiStoragePair*)lhs)->key < ((const ImGuiStoragePair*)rhs)->key) return -1; |
| 2127 | return 0; |
| 2128 | } |
| 2129 | }; |
| 2130 | ImQsort(Data.Data, (size_t)Data.Size, sizeof(ImGuiStoragePair), StaticFunc::PairComparerByID); |
| 2131 | } |
| 2132 | |
| 2133 | int ImGuiStorage::GetInt(ImGuiID key, int default_val) const |
| 2134 | { |