mirror of
https://github.com/ocornut/imgui.git
synced 2026-01-17 01:04:19 +00:00
MultiSelect: Transition to use FocusScope bits merged in master.
Preserve ability to shift+arrow into an item that is part of FocusScope but doesn't carry a selection without breaking selection.
This commit is contained in:
parent
4afbfd5e71
commit
9c7183dd04
3 changed files with 31 additions and 22 deletions
|
|
@ -6466,7 +6466,7 @@ bool ImGui::TreeNodeBehavior(ImGuiID id, ImGuiID storage_id, ImGuiTreeNodeFlags
|
|||
const bool was_selected = selected;
|
||||
|
||||
// Multi-selection support (header)
|
||||
const bool is_multi_select = (g.MultiSelectScopeWindow == window);
|
||||
const bool is_multi_select = g.MultiSelectEnabled;
|
||||
if (is_multi_select)
|
||||
{
|
||||
flags |= ImGuiTreeNodeFlags_OpenOnArrow;
|
||||
|
|
@ -6814,7 +6814,7 @@ bool ImGui::Selectable(const char* label, bool selected, ImGuiSelectableFlags fl
|
|||
if ((flags & ImGuiSelectableFlags_AllowOverlap) || (g.LastItemData.InFlags & ImGuiItemFlags_AllowOverlap)) { button_flags |= ImGuiButtonFlags_AllowOverlap; }
|
||||
|
||||
// Multi-selection support (header)
|
||||
const bool is_multi_select = (g.MultiSelectScopeWindow == window);
|
||||
const bool is_multi_select = g.MultiSelectEnabled;
|
||||
const bool was_selected = selected;
|
||||
if (is_multi_select)
|
||||
{
|
||||
|
|
@ -7120,17 +7120,20 @@ void ImGui::DebugNodeTypingSelectState(ImGuiTypingSelectState* data)
|
|||
|
||||
ImGuiMultiSelectData* ImGui::BeginMultiSelect(ImGuiMultiSelectFlags flags, void* range_ref, bool range_ref_is_selected)
|
||||
{
|
||||
ImGuiContext& g = *ImGui::GetCurrentContext();
|
||||
ImGuiContext& g = *GImGui;
|
||||
ImGuiWindow* window = g.CurrentWindow;
|
||||
|
||||
IM_ASSERT(g.MultiSelectScopeId == 0); // No recursion allowed yet (we could allow it if we deem it useful)
|
||||
IM_ASSERT(g.MultiSelectEnabled == false); // No recursion allowed yet (we could allow it if we deem it useful)
|
||||
IM_ASSERT(g.MultiSelectFlags == 0);
|
||||
IM_ASSERT(g.MultiSelectState.FocusScopeId == 0);
|
||||
|
||||
// FIXME: BeginFocusScope()
|
||||
ImGuiMultiSelectState* ms = &g.MultiSelectState;
|
||||
g.MultiSelectScopeId = window->IDStack.back();
|
||||
g.MultiSelectScopeWindow = window;
|
||||
g.MultiSelectFlags = flags;
|
||||
ms->Clear();
|
||||
ms->FocusScopeId = window->IDStack.back();
|
||||
PushFocusScope(ms->FocusScopeId);
|
||||
g.MultiSelectEnabled = true;
|
||||
g.MultiSelectFlags = flags;
|
||||
|
||||
if ((flags & ImGuiMultiSelectFlags_NoMultiSelect) == 0)
|
||||
{
|
||||
|
|
@ -7139,7 +7142,7 @@ ImGuiMultiSelectData* ImGui::BeginMultiSelect(ImGuiMultiSelectFlags flags, void*
|
|||
}
|
||||
|
||||
// Auto clear when using Navigation to move within the selection (we compare SelectScopeId so it possible to use multiple lists inside a same window)
|
||||
if (g.NavJustMovedToId != 0 && g.NavJustMovedToFocusScopeId == g.MultiSelectScopeId)
|
||||
if (g.NavJustMovedToId != 0 && g.NavJustMovedToFocusScopeId == ms->FocusScopeId && g.NavJustMovedToHasSelectionData)
|
||||
{
|
||||
if (g.IO.KeyShift)
|
||||
ms->InRequestSetRangeNav = true;
|
||||
|
|
@ -7162,14 +7165,16 @@ ImGuiMultiSelectData* ImGui::BeginMultiSelect(ImGuiMultiSelectFlags flags, void*
|
|||
|
||||
ImGuiMultiSelectData* ImGui::EndMultiSelect()
|
||||
{
|
||||
ImGuiContext& g = *ImGui::GetCurrentContext();
|
||||
ImGuiContext& g = *GImGui;
|
||||
ImGuiMultiSelectState* ms = &g.MultiSelectState;
|
||||
IM_ASSERT(g.MultiSelectScopeId != 0);
|
||||
IM_ASSERT(g.MultiSelectState.FocusScopeId == g.CurrentFocusScopeId);
|
||||
|
||||
if (g.MultiSelectFlags & ImGuiMultiSelectFlags_NoUnselect)
|
||||
ms->Out.RangeValue = true;
|
||||
g.MultiSelectScopeId = 0;
|
||||
g.MultiSelectScopeWindow = NULL;
|
||||
g.MultiSelectFlags = 0;
|
||||
g.MultiSelectState.FocusScopeId = 0;
|
||||
PopFocusScope();
|
||||
g.MultiSelectEnabled = false;
|
||||
g.MultiSelectFlags = ImGuiMultiSelectFlags_None;
|
||||
|
||||
#ifdef IMGUI_DEBUG_MULTISELECT
|
||||
if (ms->Out.RequestClear) printf("[%05d] EndMultiSelect: RequestClear\n", g.FrameCount);
|
||||
|
|
@ -7185,18 +7190,22 @@ void ImGui::SetNextItemSelectionUserData(ImGuiSelectionUserData selection_user_d
|
|||
// Note that flags will be cleared by ItemAdd(), so it's only useful for Navigation code!
|
||||
// This designed so widgets can also cheaply set this before calling ItemAdd(), so we are not tied to MultiSelect api.
|
||||
ImGuiContext& g = *GImGui;
|
||||
if (g.MultiSelectScopeId != 0)
|
||||
if (g.MultiSelectState.FocusScopeId != 0)
|
||||
g.NextItemData.ItemFlags |= ImGuiItemFlags_HasSelectionUserData | ImGuiItemFlags_IsMultiSelect;
|
||||
else
|
||||
g.NextItemData.ItemFlags |= ImGuiItemFlags_HasSelectionUserData;
|
||||
g.NextItemData.SelectionUserData = selection_user_data;
|
||||
g.NextItemData.FocusScopeId = g.CurrentFocusScopeId;
|
||||
}
|
||||
|
||||
void ImGui::MultiSelectItemHeader(ImGuiID id, bool* p_selected)
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
ImGuiWindow* window = g.CurrentWindow;
|
||||
ImGuiMultiSelectState* ms = &g.MultiSelectState;
|
||||
|
||||
IM_UNUSED(window);
|
||||
IM_ASSERT(g.NextItemData.FocusScopeId == g.CurrentFocusScopeId && "Forgot to call SetNextItemSelectionUserData() 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;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue