mirror of
https://github.com/ocornut/imgui.git
synced 2025-01-31 12:03:49 +01:00
MultiSelect: added support for nested/stacked BeginMultiSelect().
Mimicking table logic, reusing amortized buffers.
This commit is contained in:
parent
b747d6fe59
commit
0af6fbb51d
@ -3819,6 +3819,7 @@ void ImGui::Shutdown()
|
|||||||
g.DrawChannelsTempMergeBuffer.clear();
|
g.DrawChannelsTempMergeBuffer.clear();
|
||||||
|
|
||||||
g.MultiSelectStorage.Clear();
|
g.MultiSelectStorage.Clear();
|
||||||
|
g.MultiSelectTempData.clear_destruct();
|
||||||
|
|
||||||
g.ClipboardHandlerData.clear();
|
g.ClipboardHandlerData.clear();
|
||||||
g.MenusIdSubmittedThisFrame.clear();
|
g.MenusIdSubmittedThisFrame.clear();
|
||||||
@ -3930,6 +3931,8 @@ void ImGui::GcCompactTransientMiscBuffers()
|
|||||||
ImGuiContext& g = *GImGui;
|
ImGuiContext& g = *GImGui;
|
||||||
g.ItemFlagsStack.clear();
|
g.ItemFlagsStack.clear();
|
||||||
g.GroupStack.clear();
|
g.GroupStack.clear();
|
||||||
|
g.MultiSelectTempDataStacked = 0;
|
||||||
|
g.MultiSelectTempData.clear_destruct();
|
||||||
TableGcCompactSettings();
|
TableGcCompactSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
3
imgui.h
3
imgui.h
@ -2811,6 +2811,9 @@ struct ImGuiSelectionRequest
|
|||||||
ImGuiSelectionRequest(ImGuiSelectionRequestType type = ImGuiSelectionRequestType_None) { Type = type; RangeSelected = false; RangeFirstItem = RangeLastItem = (ImGuiSelectionUserData)-1; }
|
ImGuiSelectionRequest(ImGuiSelectionRequestType type = ImGuiSelectionRequestType_None) { Type = type; RangeSelected = false; RangeFirstItem = RangeLastItem = (ImGuiSelectionUserData)-1; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Main IO structure returned by BeginMultiSelect()/EndMultiSelect().
|
||||||
|
// Read the large comments block above for details.
|
||||||
|
// Lifetime: don't hold on ImGuiMultiSelectIO* pointers over multiple frames or past any subsequent call to BeginMultiSelect() or EndMultiSelect().
|
||||||
struct ImGuiMultiSelectIO
|
struct ImGuiMultiSelectIO
|
||||||
{
|
{
|
||||||
ImVector<ImGuiSelectionRequest> Requests; // ms:w, app:r / ms:w app:r // Requests
|
ImVector<ImGuiSelectionRequest> Requests; // ms:w, app:r / ms:w app:r // Requests
|
||||||
|
@ -2200,8 +2200,9 @@ struct ImGuiContext
|
|||||||
ImVector<ImGuiShrinkWidthItem> ShrinkWidthBuffer;
|
ImVector<ImGuiShrinkWidthItem> ShrinkWidthBuffer;
|
||||||
|
|
||||||
// Multi-Select state
|
// Multi-Select state
|
||||||
ImGuiMultiSelectTempData* CurrentMultiSelect; // FIXME-MULTISELECT: We currently don't support recursing/stacking multi-select
|
ImGuiMultiSelectTempData* CurrentMultiSelect;
|
||||||
ImGuiMultiSelectTempData MultiSelectTempData[1];
|
int MultiSelectTempDataStacked; // Temporary multi-select data size (because we leave previous instances undestructed, we generally don't use MultiSelectTempData.Size)
|
||||||
|
ImVector<ImGuiMultiSelectTempData> MultiSelectTempData;
|
||||||
ImPool<ImGuiMultiSelectState> MultiSelectStorage;
|
ImPool<ImGuiMultiSelectState> MultiSelectStorage;
|
||||||
|
|
||||||
// Hover Delay system
|
// Hover Delay system
|
||||||
@ -2445,6 +2446,7 @@ struct ImGuiContext
|
|||||||
TablesTempDataStacked = 0;
|
TablesTempDataStacked = 0;
|
||||||
CurrentTabBar = NULL;
|
CurrentTabBar = NULL;
|
||||||
CurrentMultiSelect = NULL;
|
CurrentMultiSelect = NULL;
|
||||||
|
MultiSelectTempDataStacked = 0;
|
||||||
|
|
||||||
HoverItemDelayId = HoverItemDelayIdPreviousFrame = HoverItemUnlockedStationaryId = HoverWindowUnlockedStationaryId = 0;
|
HoverItemDelayId = HoverItemDelayIdPreviousFrame = HoverItemUnlockedStationaryId = HoverWindowUnlockedStationaryId = 0;
|
||||||
HoverItemDelayTimer = HoverItemDelayClearTimer = 0.0f;
|
HoverItemDelayTimer = HoverItemDelayClearTimer = 0.0f;
|
||||||
|
@ -7156,8 +7156,10 @@ ImGuiMultiSelectIO* ImGui::BeginMultiSelect(ImGuiMultiSelectFlags flags)
|
|||||||
{
|
{
|
||||||
ImGuiContext& g = *GImGui;
|
ImGuiContext& g = *GImGui;
|
||||||
ImGuiWindow* window = g.CurrentWindow;
|
ImGuiWindow* window = g.CurrentWindow;
|
||||||
ImGuiMultiSelectTempData* ms = &g.MultiSelectTempData[0];
|
|
||||||
IM_ASSERT(g.CurrentMultiSelect == NULL); // No recursion allowed yet (we could allow it if we deem it useful)
|
if (++g.MultiSelectTempDataStacked > g.MultiSelectTempData.Size)
|
||||||
|
g.MultiSelectTempData.resize(g.MultiSelectTempDataStacked, ImGuiMultiSelectTempData());
|
||||||
|
ImGuiMultiSelectTempData* ms = &g.MultiSelectTempData[g.MultiSelectTempDataStacked - 1];
|
||||||
IM_STATIC_ASSERT(offsetof(ImGuiMultiSelectTempData, IO) == 0); // Clear() relies on that.
|
IM_STATIC_ASSERT(offsetof(ImGuiMultiSelectTempData, IO) == 0); // Clear() relies on that.
|
||||||
g.CurrentMultiSelect = ms;
|
g.CurrentMultiSelect = ms;
|
||||||
if ((flags & (ImGuiMultiSelectFlags_ScopeWindow | ImGuiMultiSelectFlags_ScopeRect)) == 0)
|
if ((flags & (ImGuiMultiSelectFlags_ScopeWindow | ImGuiMultiSelectFlags_ScopeRect)) == 0)
|
||||||
@ -7276,6 +7278,7 @@ ImGuiMultiSelectIO* ImGui::EndMultiSelect()
|
|||||||
ImGuiWindow* window = g.CurrentWindow;
|
ImGuiWindow* window = g.CurrentWindow;
|
||||||
IM_ASSERT(ms->FocusScopeId == g.CurrentFocusScopeId);
|
IM_ASSERT(ms->FocusScopeId == g.CurrentFocusScopeId);
|
||||||
IM_ASSERT(g.CurrentMultiSelect != NULL && storage->Window == g.CurrentWindow);
|
IM_ASSERT(g.CurrentMultiSelect != NULL && storage->Window == g.CurrentWindow);
|
||||||
|
IM_ASSERT(g.MultiSelectTempDataStacked > 0 && &g.MultiSelectTempData[g.MultiSelectTempDataStacked - 1] == g.CurrentMultiSelect);
|
||||||
|
|
||||||
const ImRect scope_rect = (ms->Flags & ImGuiMultiSelectFlags_ScopeRect) ? ImRect(ms->ScopeRectMin, ImMax(window->DC.CursorMaxPos, ms->ScopeRectMin)) : window->InnerClipRect;
|
const ImRect scope_rect = (ms->Flags & ImGuiMultiSelectFlags_ScopeRect) ? ImRect(ms->ScopeRectMin, ImMax(window->DC.CursorMaxPos, ms->ScopeRectMin)) : window->InnerClipRect;
|
||||||
if (ms->IsFocused)
|
if (ms->IsFocused)
|
||||||
@ -7332,14 +7335,15 @@ ImGuiMultiSelectIO* ImGui::EndMultiSelect()
|
|||||||
|
|
||||||
// Unwind
|
// Unwind
|
||||||
window->DC.CursorMaxPos = ImMax(ms->BackupCursorMaxPos, window->DC.CursorMaxPos);
|
window->DC.CursorMaxPos = ImMax(ms->BackupCursorMaxPos, window->DC.CursorMaxPos);
|
||||||
ms->FocusScopeId = 0;
|
|
||||||
ms->Flags = ImGuiMultiSelectFlags_None;
|
|
||||||
PopFocusScope();
|
PopFocusScope();
|
||||||
g.CurrentMultiSelect = NULL;
|
|
||||||
|
|
||||||
if (g.DebugLogFlags & ImGuiDebugLogFlags_EventSelection)
|
if (g.DebugLogFlags & ImGuiDebugLogFlags_EventSelection)
|
||||||
DebugLogMultiSelectRequests("EndMultiSelect", &ms->IO);
|
DebugLogMultiSelectRequests("EndMultiSelect", &ms->IO);
|
||||||
|
|
||||||
|
ms->FocusScopeId = 0;
|
||||||
|
ms->Flags = ImGuiMultiSelectFlags_None;
|
||||||
|
g.CurrentMultiSelect = (--g.MultiSelectTempDataStacked > 0) ? &g.MultiSelectTempData[g.MultiSelectTempDataStacked - 1] : NULL;
|
||||||
|
|
||||||
return &ms->IO;
|
return &ms->IO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user