MultiSelect: BoxSelect: fixed using in frozen table. (#7821, #5143) + added Demo.

Amend 0b4a1a40
This commit is contained in:
ocornut
2024-07-29 15:35:57 +02:00
parent 249d5caedb
commit b847c41437
3 changed files with 68 additions and 6 deletions
+46
View File
@@ -3306,6 +3306,52 @@ static void ShowDemoWindowMultiSelect(DemoWindowData* demo_data)
ImGui::TreePop();
}
// Demonstrate using the clipper with BeginMultiSelect()/EndMultiSelect()
IMGUI_DEMO_MARKER("Widgets/Selection State/Multi-Select (in a table)");
if (ImGui::TreeNode("Multi-Select (in a table)"))
{
static ImGuiSelectionBasicStorage selection;
const int ITEMS_COUNT = 10000;
ImGui::Text("Selection: %d/%d", selection.Size, ITEMS_COUNT);
if (ImGui::BeginTable("##Basket", 2, ImGuiTableFlags_ScrollY | ImGuiTableFlags_RowBg | ImGuiTableFlags_BordersOuter))
{
ImGui::TableSetupColumn("Object");
ImGui::TableSetupColumn("Action");
ImGui::TableSetupScrollFreeze(0, 1);
ImGui::TableHeadersRow();
ImGuiMultiSelectFlags flags = ImGuiMultiSelectFlags_ClearOnEscape | ImGuiMultiSelectFlags_BoxSelect1d;
ImGuiMultiSelectIO* ms_io = ImGui::BeginMultiSelect(flags, selection.Size, ITEMS_COUNT);
selection.ApplyRequests(ms_io);
ImGuiListClipper clipper;
clipper.Begin(ITEMS_COUNT);
if (ms_io->RangeSrcItem != -1)
clipper.IncludeItemByIndex((int)ms_io->RangeSrcItem); // Ensure RangeSrc item is not clipped.
while (clipper.Step())
{
for (int n = clipper.DisplayStart; n < clipper.DisplayEnd; n++)
{
ImGui::TableNextRow();
ImGui::TableNextColumn();
char label[64];
sprintf(label, "Object %05d: %s", n, ExampleNames[n % IM_ARRAYSIZE(ExampleNames)]);
bool item_is_selected = selection.Contains((ImGuiID)n);
ImGui::SetNextItemSelectionUserData(n);
ImGui::Selectable(label, item_is_selected, ImGuiSelectableFlags_SpanAllColumns | ImGuiSelectableFlags_AllowOverlap);
ImGui::TableNextColumn();
ImGui::SmallButton("hello");
}
}
ms_io = ImGui::EndMultiSelect();
selection.ApplyRequests(ms_io);
ImGui::EndTable();
}
ImGui::TreePop();
}
IMGUI_DEMO_MARKER("Widgets/Selection State/Multi-Select (checkboxes)");
if (ImGui::TreeNode("Multi-Select (checkboxes)"))
{