mirror of
https://github.com/ocornut/imgui.git
synced 2026-01-11 00:04:24 +00:00
MultiSelect: ImGuiSelectionBasicStorage: simplify by removing compacting code (compacting may be opt-in?).
GetNextSelectedItem() wrapper gives us more flexibility to work on this kind of stuff now.
This commit is contained in:
parent
e61612a687
commit
2af3b2ac81
2 changed files with 11 additions and 40 deletions
4
imgui.h
4
imgui.h
|
|
@ -2835,7 +2835,7 @@ struct ImGuiSelectionBasicStorage
|
|||
{
|
||||
// Members
|
||||
ImGuiStorage _Storage; // [Internal] Selection set. Think of this as similar to e.g. std::set<ImGuiID>. Prefer not accessing directly: iterate with GetNextSelectedItem().
|
||||
int Size; // Number of selected items, maintained by this helper.
|
||||
int Size; // Number of selected items (== number of 1 in the Storage), maintained by this helper.
|
||||
void* UserData; // User data for use by adapter function // e.g. selection.UserData = (void*)my_items;
|
||||
ImGuiID (*AdapterIndexToStorageId)(ImGuiSelectionBasicStorage* self, int idx); // e.g. selection.AdapterIndexToStorageId = [](ImGuiSelectionBasicStorage* self, int idx) { return ((MyItems**)self->UserData)[idx]->ID; };
|
||||
|
||||
|
|
@ -2849,7 +2849,7 @@ struct ImGuiSelectionBasicStorage
|
|||
ImGuiSelectionBasicStorage() { Size = 0; 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); int lhs_size = Size; Size = r.Size; r.Size = lhs_size; }
|
||||
IMGUI_API void SetItemSelected(ImGuiID id, bool selected);
|
||||
void SetItemSelected(ImGuiID id, bool v) { int* p_int = _Storage.GetIntRef(id, 0); if (v && *p_int == 0) { *p_int = 1; Size++; } else if (!v && *p_int != 0) { *p_int = 0; Size--; } }
|
||||
};
|
||||
|
||||
// Optional helper to apply multi-selection requests to existing randomly accessible storage.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue