MultiSelect: Clarify and better enforce lifetime of BeginMultiSelect() value.

This commit is contained in:
ocornut
2023-06-07 16:25:19 +02:00
parent 961b81c362
commit 387fc13894
2 changed files with 8 additions and 6 deletions

View File

@@ -7131,6 +7131,7 @@ static void DebugLogMultiSelectRequests(const char* function, const ImGuiMultiSe
if (data->RequestSetRange) IMGUI_DEBUG_LOG_SELECTION("[selection] %s: RequestSetRange %p..%p = %d (dir %+d)\n", function, data->RangeSrcItem, data->RangeDstItem, data->RangeSelected, data->RangeDirection);
}
// Return ImGuiMultiSelectIO structure. Lifetime: valid until corresponding call to EndMultiSelect().
ImGuiMultiSelectIO* ImGui::BeginMultiSelect(ImGuiMultiSelectFlags flags, void* range_ref, bool range_ref_is_selected)
{
ImGuiContext& g = *GImGui;
@@ -7184,6 +7185,7 @@ ImGuiMultiSelectIO* ImGui::BeginMultiSelect(ImGuiMultiSelectFlags flags, void* r
return &ms->BeginIO;
}
// Return updated ImGuiMultiSelectIO structure. Lifetime: until EndFrame() or next BeginMultiSelect() call.
ImGuiMultiSelectIO* ImGui::EndMultiSelect()
{
ImGuiContext& g = *GImGui;
@@ -7205,6 +7207,7 @@ ImGuiMultiSelectIO* ImGui::EndMultiSelect()
ms->FocusScopeId = 0;
ms->Window = NULL;
ms->Flags = ImGuiMultiSelectFlags_None;
ms->BeginIO.Clear(); // Invalidate contents of BeginMultiSelect() to enforce scope.
PopFocusScope();
g.CurrentMultiSelect = NULL;