1
0
Fork 0
mirror of https://github.com/ocornut/imgui.git synced 2026-02-07 04:30:08 +00:00

MultiSelect: made SetNextItemSelectionData() optional to allow disjoint selection (e.g. with a CollapsingHeader between items). Amend demo.

This commit is contained in:
ocornut 2023-05-20 15:51:39 +02:00
parent 815c61b82e
commit d2f208a30c
3 changed files with 29 additions and 22 deletions

View file

@ -6391,6 +6391,7 @@ bool ImGui::TreeNodeBehavior(ImGuiID id, ImGuiID storage_id, ImGuiTreeNodeFlags
// Compute open and multi-select states before ItemAdd() as it clear NextItem data.
bool is_open = TreeNodeUpdateNextOpen(storage_id, flags);
const bool is_multi_select = (g.NextItemData.Flags & ImGuiNextItemDataFlags_HasSelectionData) != 0; // Before ItemAdd()
bool item_add = ItemAdd(interact_bb, id);
g.LastItemData.StatusFlags |= ImGuiItemStatusFlags_HasDisplayRect;
g.LastItemData.DisplayRect = frame_bb;
@ -6464,7 +6465,6 @@ bool ImGui::TreeNodeBehavior(ImGuiID id, ImGuiID storage_id, ImGuiTreeNodeFlags
const bool was_selected = selected;
// Multi-selection support (header)
const bool is_multi_select = (g.MultiSelectState.Window == window);
if (is_multi_select)
{
MultiSelectItemHeader(id, &selected);
@ -6780,7 +6780,9 @@ bool ImGui::Selectable(const char* label, bool selected, ImGuiSelectableFlags fl
}
const bool disabled_item = (flags & ImGuiSelectableFlags_Disabled) != 0;
const bool is_multi_select = (g.NextItemData.Flags & ImGuiNextItemDataFlags_HasSelectionData) != 0; // Before ItemAdd()
const bool item_add = ItemAdd(bb, id, NULL, disabled_item ? (ImGuiItemFlags)ImGuiItemFlags_Disabled : ImGuiItemFlags_None);
if (span_all_columns)
{
window->ClipRect.Min.x = backup_clip_rect_min_x;
@ -6816,7 +6818,6 @@ 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.MultiSelectState.Window == window);
const bool was_selected = selected;
if (is_multi_select)
{
@ -7166,7 +7167,7 @@ ImGuiMultiSelectData* ImGui::BeginMultiSelect(ImGuiMultiSelectFlags flags, void*
ms->In.RequestSelectAll = true;
if (flags & ImGuiMultiSelectFlags_ClearOnEscape)
if (Shortcut(ImGuiKey_Escape))
if (Shortcut(ImGuiKey_Escape)) // FIXME-MULTISELECT: Only hog shortcut if selection is not null, meaning we need "has selection or "selection size" data here.
ms->In.RequestClear = true;
}