MultiSelect: (breaking) renamed ImGuiSelectionBasicStorage::AdapterData to UserData.
diff --git a/imgui.h b/imgui.h
index d5a3bda..58409f6 100644
--- a/imgui.h
+++ b/imgui.h
@@ -2843,14 +2843,14 @@
// Members
ImGuiStorage Storage; // [Internal] Selection set. Think of this as similar to e.g. std::set<ImGuiID>
int Size; // Number of selected items (== number of 1 in the Storage), maintained by this helper.
- void* AdapterData; // Adapter to convert item index to item identifier // e.g. selection.AdapterData = (void*)my_items;
ImGuiID (*AdapterIndexToStorageId)(ImGuiSelectionBasicStorage* self, int idx); // e.g. selection.AdapterIndexToStorageId = [](ImGuiSelectionBasicStorage* self, int idx) { return ((MyItems**)self->AdapterData)[idx]->ID; };
+ void* UserData; // User data for use by adapter function // e.g. selection.UserData = (void*)my_items;
// Methods: apply selection requests coming from BeginMultiSelect() and EndMultiSelect() functions
IMGUI_API void ApplyRequests(ImGuiMultiSelectIO* ms_io, int items_count);
// Methods: selection storage
- ImGuiSelectionBasicStorage() { Clear(); AdapterData = NULL; AdapterIndexToStorageId = [](ImGuiSelectionBasicStorage*, int idx) { return (ImGuiID)idx; }; }
+ ImGuiSelectionBasicStorage() { Clear(); UserData = NULL; AdapterIndexToStorageId = [](ImGuiSelectionBasicStorage*, int idx) { return (ImGuiID)idx; }; }
void Clear() { Storage.Data.resize(0); Size = 0; }
void Swap(ImGuiSelectionBasicStorage& r) { Storage.Data.swap(r.Storage.Data); }
bool Contains(ImGuiID id) const { return Storage.GetInt(id, 0) != 0; }
diff --git a/imgui_demo.cpp b/imgui_demo.cpp
index c984ee4..efaf116 100644
--- a/imgui_demo.cpp
+++ b/imgui_demo.cpp
@@ -2872,8 +2872,8 @@
void ApplySelectionRequests(ImGuiMultiSelectIO* ms_io, int side)
{
// In this example we store item id in selection (instead of item index)
- Selections[side].AdapterData = Items[side].Data;
- Selections[side].AdapterIndexToStorageId = [](ImGuiSelectionBasicStorage* self, int idx) { ImGuiID* items = (ImGuiID*)self->AdapterData; return items[idx]; };
+ Selections[side].UserData = Items[side].Data;
+ Selections[side].AdapterIndexToStorageId = [](ImGuiSelectionBasicStorage* self, int idx) { ImGuiID* items = (ImGuiID*)self->UserData; return items[idx]; };
Selections[side].ApplyRequests(ms_io, Items[side].Size);
}
static int IMGUI_CDECL CompareItemsByValue(const void* lhs, const void* rhs)
@@ -3135,8 +3135,8 @@
// Use a custom selection.Adapter: store item identifier in Selection (instead of index)
static ImVector<ImGuiID> items;
static ExampleSelectionWithDeletion selection;
- selection.AdapterData = (void*)&items;
- selection.AdapterIndexToStorageId = [](ImGuiSelectionBasicStorage* self, int idx) { ImVector<ImGuiID>* p_items = (ImVector<ImGuiID>*)self->AdapterData; return (*p_items)[idx]; }; // Index -> ID
+ selection.UserData = (void*)&items;
+ selection.AdapterIndexToStorageId = [](ImGuiSelectionBasicStorage* self, int idx) { ImVector<ImGuiID>* p_items = (ImVector<ImGuiID>*)self->UserData; return (*p_items)[idx]; }; // Index -> ID
ImGui::Text("Added features:");
ImGui::BulletText("Dynamic list with Delete key support.");
@@ -9847,8 +9847,8 @@
ImGuiMultiSelectIO* ms_io = ImGui::BeginMultiSelect(ms_flags, Selection.Size);
// Use custom selection adapter: store ID in selection (recommended)
- Selection.AdapterData = this;
- Selection.AdapterIndexToStorageId = [](ImGuiSelectionBasicStorage* self_, int idx) { ExampleAssetsBrowser* self = (ExampleAssetsBrowser*)self_->AdapterData; return self->Items[idx].ID; };
+ Selection.UserData = this;
+ Selection.AdapterIndexToStorageId = [](ImGuiSelectionBasicStorage* self_, int idx) { ExampleAssetsBrowser* self = (ExampleAssetsBrowser*)self_->UserData; return self->Items[idx].ID; };
Selection.ApplyRequests(ms_io, Items.Size);
const bool want_delete = (ImGui::Shortcut(ImGuiKey_Delete, ImGuiInputFlags_Repeat) && (Selection.Size > 0)) || RequestDelete;
diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp
index 062b364..7602b2c 100644
--- a/imgui_widgets.cpp
+++ b/imgui_widgets.cpp
@@ -7306,7 +7306,7 @@
// Lifetime: don't hold on ImGuiMultiSelectIO* pointers over multiple frames or past any subsequent call to BeginMultiSelect() or EndMultiSelect().
// Passing 'current_selection_size' is currently optional:
// - it is useful for shortcut routing with ImGuiMultiSelectFlags_ClearOnEscape: so we can have Escape be used to clear selection THEN to exit child window.
-// - if it is costly for you to compute, but can easily tell if your selection is empty or not, you may alter the ImGuiMultiSelectFlags_ClearOnEscape flag based on that.
+// - if it is costly for you to compute, but can easily tell if your selection is empty or not, you may pass 1, or use the ImGuiMultiSelectFlags_ClearOnEscape flag dynamically.
ImGuiMultiSelectIO* ImGui::BeginMultiSelect(ImGuiMultiSelectFlags flags, int current_selection_size)
{
ImGuiContext& g = *GImGui;
@@ -7347,6 +7347,7 @@
storage->Window = window;
ms->Storage = storage;
+ // Output to user
ms->IO.RangeSrcItem = storage->RangeSrcItem;
ms->IO.NavIdItem = storage->NavIdItem;
ms->IO.NavIdSelected = (storage->NavIdSelected == 1) ? true : false;