MultiSelect: Renamed SetNextItemMultiSelectData() to SetNextItemSelectionUserData()
This commit is contained in:
parent
17c4c2154a
commit
4afbfd5e71
4
imgui.h
4
imgui.h
@ -2749,7 +2749,7 @@ enum ImGuiMultiSelectFlags_
|
||||
// performance penalty, but requires a little more work on the code. If you only have a few hundreds elements in your possible selection set,
|
||||
// you may as well not bother with clipping, as the cost should be negligible (as least on imgui side).
|
||||
// If you are not sure, always start without clipping and you can work your way to the more optimized version afterwards.
|
||||
// - The void* Src/Dst value represent a selectable object. They are the values you pass to SetNextItemMultiSelectData().
|
||||
// - The void* Src/Dst value represent a selectable object. They are the values you pass to SetNextItemSelectionUserData().
|
||||
// Storing an integer index is the easiest thing to do, as SetRange requests will give you two end points. But the code never assume that sortable integers are used.
|
||||
// - In the spirit of imgui design, your code own the selection data. So this is designed to handle all kind of selection data: instructive (store a bool inside each object),
|
||||
// external array (store an array aside from your objects), set (store only selected items in a hash/map/set), using intervals (store indices in an interval tree), etc.
|
||||
@ -2760,7 +2760,7 @@ enum ImGuiMultiSelectFlags_
|
||||
// 3) Set RangeSrcPassedBy=true if the RangeSrc item is part of the items clipped before the first submitted/visible item. [Only required if you are using a clipper in step 4]
|
||||
// This is because for range-selection we need to know if we are currently "inside" or "outside" the range.
|
||||
// If you are using integer indices everywhere, this is easy to compute: if (clipper.DisplayStart > (int)data->RangeSrc) { data->RangeSrcPassedBy = true; }
|
||||
// 4) Submit your items with SetNextItemMultiSelectData() + Selectable()/TreeNode() calls.
|
||||
// 4) Submit your items with SetNextItemSelectionUserData() + Selectable()/TreeNode() calls.
|
||||
// Call IsItemSelectionToggled() to query with the selection state has been toggled, in which you need the info immediately (before EndMultiSelect()) for your display.
|
||||
// When cannot reliably return a "IsItemSelected()" value because we need to consider clipped (unprocessed) item, this is why we return a toggle event instead.
|
||||
// 5) Call EndMultiSelect(). Save the value of ->RangeSrc for the next frame (you may convert the value in a format that is safe for persistance)
|
||||
|
@ -2845,7 +2845,7 @@ static void ShowDemoWindowMultiSelect()
|
||||
};
|
||||
|
||||
int COUNT = 1000;
|
||||
HelpMarker("Hold CTRL and click to select multiple items. Hold SHIFT to select a range.");
|
||||
HelpMarker("Hold CTRL and click to select multiple items. Hold SHIFT to select a range. Keyboard is also supported.");
|
||||
ImGui::CheckboxFlags("io.ConfigFlags: NavEnableKeyboard", (unsigned int*)&ImGui::GetIO().ConfigFlags, ImGuiConfigFlags_NavEnableKeyboard);
|
||||
|
||||
if (ImGui::BeginListBox("##Basket", ImVec2(-FLT_MIN, ImGui::GetFontSize() * 20)))
|
||||
@ -2853,6 +2853,7 @@ static void ShowDemoWindowMultiSelect()
|
||||
ImGuiMultiSelectData* multi_select_data = ImGui::BeginMultiSelect(ImGuiMultiSelectFlags_None, (void*)(intptr_t)selection_ref, selection.GetSelected((int)selection_ref));
|
||||
if (multi_select_data->RequestClear) { selection.Clear(); }
|
||||
if (multi_select_data->RequestSelectAll) { selection.SelectAll(COUNT); }
|
||||
ImVec2 color_button_sz(ImGui::GetFontSize(), ImGui::GetFontSize());
|
||||
ImGuiListClipper clipper;
|
||||
clipper.Begin(COUNT);
|
||||
while (clipper.Step())
|
||||
@ -2865,6 +2866,13 @@ static void ShowDemoWindowMultiSelect()
|
||||
char label[64];
|
||||
sprintf(label, "Object %05d (category: %s)", n, random_names[n % IM_ARRAYSIZE(random_names)]);
|
||||
bool item_is_selected = selection.GetSelected(n);
|
||||
|
||||
// Emit a color button, to test that Shift+LeftArrow landing on an item that is not part
|
||||
// of the selection scope doesn't erroneously alter our selection.
|
||||
ImVec4 dummy_col = ImColor((ImU32)ImGui::GetID(label));
|
||||
ImGui::ColorButton("##", dummy_col, ImGuiColorEditFlags_NoTooltip, color_button_sz);
|
||||
ImGui::SameLine();
|
||||
|
||||
ImGui::SetNextItemSelectionUserData(n);
|
||||
if (ImGui::Selectable(label, item_is_selected))
|
||||
selection.SetSelected(n, !item_is_selected);
|
||||
|
@ -7113,7 +7113,7 @@ void ImGui::DebugNodeTypingSelectState(ImGuiTypingSelectState* data)
|
||||
//-------------------------------------------------------------------------
|
||||
// - BeginMultiSelect()
|
||||
// - EndMultiSelect()
|
||||
// - SetNextItemMultiSelectData()
|
||||
// - SetNextItemSelectionUserData()
|
||||
// - MultiSelectItemHeader() [Internal]
|
||||
// - MultiSelectItemFooter() [Internal]
|
||||
//-------------------------------------------------------------------------
|
||||
@ -7197,7 +7197,7 @@ void ImGui::MultiSelectItemHeader(ImGuiID id, bool* p_selected)
|
||||
ImGuiContext& g = *GImGui;
|
||||
ImGuiMultiSelectState* ms = &g.MultiSelectState;
|
||||
|
||||
IM_ASSERT((g.NextItemData.SelectionUserData != ImGuiSelectionUserData_Invalid) && "Forgot to call SetNextItemMultiSelectData() prior to item, required in BeginMultiSelect()/EndMultiSelect() scope");
|
||||
IM_ASSERT((g.NextItemData.SelectionUserData != ImGuiSelectionUserData_Invalid) && "Forgot to call SetNextItemSelectionUserData() prior to item, required in BeginMultiSelect()/EndMultiSelect() scope");
|
||||
void* item_data = (void*)g.NextItemData.SelectionUserData;
|
||||
|
||||
// Apply Clear/SelectAll requests requested by BeginMultiSelect().
|
||||
|
Loading…
Reference in New Issue
Block a user