MultiSelect: Demo: Added pointer indirection and indent level.

This is to reduce noise for upcoming commits, ahead of adding a loop here.
This commit is contained in:
ocornut 2023-04-11 19:33:38 +02:00
parent 19086c1c48
commit b91ae122e1

View File

@ -2906,9 +2906,10 @@ static void ShowDemoWindowMultiSelect()
if (ImGui::TreeNode("Multiple Selection (full, advanced)")) if (ImGui::TreeNode("Multiple Selection (full, advanced)"))
{ {
// Demonstrate holding/updating multi-selection data and using the BeginMultiSelect/EndMultiSelect API to support range-selection and clipping. // Demonstrate holding/updating multi-selection data and using the BeginMultiSelect/EndMultiSelect API to support range-selection and clipping.
static ExampleSelection selection; static ExampleSelection selections_data[1];
ExampleSelection* selection = &selections_data[0];
// Test both Selectable() and TreeNode() widgets // Options
enum WidgetType { WidgetType_Selectable, WidgetType_TreeNode }; enum WidgetType { WidgetType_Selectable, WidgetType_TreeNode };
static bool use_table = false; static bool use_table = false;
static bool use_drag_drop = true; static bool use_drag_drop = true;
@ -2919,7 +2920,9 @@ static void ShowDemoWindowMultiSelect()
ImGui::Checkbox("Use table", &use_table); ImGui::Checkbox("Use table", &use_table);
ImGui::Checkbox("Use drag & drop", &use_drag_drop); ImGui::Checkbox("Use drag & drop", &use_drag_drop);
ImGui::Text("Selection size: %d", selection.GetSelectionSize()); // (spare brace to add a loop here later)
{
ImGui::Text("Selection size: %d", selection->GetSelectionSize());
// Open a scrolling region // Open a scrolling region
const int ITEMS_COUNT = 1000; const int ITEMS_COUNT = 1000;
@ -2929,9 +2932,9 @@ static void ShowDemoWindowMultiSelect()
if (widget_type == WidgetType_TreeNode) if (widget_type == WidgetType_TreeNode)
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(ImGui::GetStyle().ItemSpacing.x, 0.0f)); ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(ImGui::GetStyle().ItemSpacing.x, 0.0f));
ImGuiMultiSelectData* multi_select_data = ImGui::BeginMultiSelect(ImGuiMultiSelectFlags_None, (void*)(intptr_t)selection.RangeRef, selection.GetSelected(selection.RangeRef)); ImGuiMultiSelectData* multi_select_data = ImGui::BeginMultiSelect(ImGuiMultiSelectFlags_None, (void*)(intptr_t)selection->RangeRef, selection->GetSelected(selection->RangeRef));
if (multi_select_data->RequestClear) { selection.Clear(); } if (multi_select_data->RequestClear) { selection->Clear(); }
if (multi_select_data->RequestSelectAll) { selection.SelectAll(ITEMS_COUNT); } if (multi_select_data->RequestSelectAll) { selection->SelectAll(ITEMS_COUNT); }
if (use_table) if (use_table)
{ {
@ -2947,7 +2950,7 @@ static void ShowDemoWindowMultiSelect()
while (clipper.Step()) while (clipper.Step())
{ {
// IF clipping is used you need to set 'RangeSrcPassedBy = true' if RangeRef was passed over. // IF clipping is used you need to set 'RangeSrcPassedBy = true' if RangeRef was passed over.
if (clipper.DisplayStart > selection.RangeRef) if (clipper.DisplayStart > selection->RangeRef)
multi_select_data->RangeSrcPassedBy = true; multi_select_data->RangeSrcPassedBy = true;
for (int n = clipper.DisplayStart; n < clipper.DisplayEnd; n++) for (int n = clipper.DisplayStart; n < clipper.DisplayEnd; n++)
@ -2959,7 +2962,7 @@ static void ShowDemoWindowMultiSelect()
const char* category = random_names[n % IM_ARRAYSIZE(random_names)]; const char* category = random_names[n % IM_ARRAYSIZE(random_names)];
char label[64]; char label[64];
sprintf(label, "Object %05d (category: %s)", n, category); sprintf(label, "Object %05d (category: %s)", n, category);
bool item_is_selected = selection.GetSelected(n); bool item_is_selected = selection->GetSelected(n);
// Emit a color button, to test that Shift+LeftArrow landing on an item that is not part // Emit a color button, to test that Shift+LeftArrow landing on an item that is not part
// of the selection scope doesn't erroneously alter our selection (FIXME-TESTS: Add a test for that!). // of the selection scope doesn't erroneously alter our selection (FIXME-TESTS: Add a test for that!).
@ -2972,10 +2975,10 @@ static void ShowDemoWindowMultiSelect()
{ {
ImGui::Selectable(label, item_is_selected); ImGui::Selectable(label, item_is_selected);
if (ImGui::IsItemToggledSelection()) if (ImGui::IsItemToggledSelection())
selection.SetSelected(n, !item_is_selected); selection->SetSelected(n, !item_is_selected);
if (use_drag_drop && ImGui::BeginDragDropSource()) if (use_drag_drop && ImGui::BeginDragDropSource())
{ {
ImGui::Text("(Dragging %d items)", selection.GetSelectionSize()); ImGui::Text("(Dragging %d items)", selection->GetSelectionSize());
ImGui::EndDragDropSource(); ImGui::EndDragDropSource();
} }
} }
@ -2987,10 +2990,10 @@ static void ShowDemoWindowMultiSelect()
tree_node_flags |= ImGuiTreeNodeFlags_Selected; tree_node_flags |= ImGuiTreeNodeFlags_Selected;
bool open = ImGui::TreeNodeEx(label, tree_node_flags); bool open = ImGui::TreeNodeEx(label, tree_node_flags);
if (ImGui::IsItemToggledSelection()) if (ImGui::IsItemToggledSelection())
selection.SetSelected(n, !item_is_selected); selection->SetSelected(n, !item_is_selected);
if (use_drag_drop && ImGui::BeginDragDropSource()) if (use_drag_drop && ImGui::BeginDragDropSource())
{ {
ImGui::Text("(Dragging %d items)", selection.GetSelectionSize()); ImGui::Text("(Dragging %d items)", selection->GetSelectionSize());
ImGui::EndDragDropSource(); ImGui::EndDragDropSource();
} }
if (open) if (open)
@ -3026,10 +3029,10 @@ static void ShowDemoWindowMultiSelect()
// Apply multi-select requests // Apply multi-select requests
multi_select_data = ImGui::EndMultiSelect(); multi_select_data = ImGui::EndMultiSelect();
selection.RangeRef = (int)(intptr_t)multi_select_data->RangeSrc; selection->RangeRef = (int)(intptr_t)multi_select_data->RangeSrc;
if (multi_select_data->RequestClear) { selection.Clear(); } if (multi_select_data->RequestClear) { selection->Clear(); }
if (multi_select_data->RequestSelectAll) { selection.SelectAll(ITEMS_COUNT); } if (multi_select_data->RequestSelectAll) { selection->SelectAll(ITEMS_COUNT); }
if (multi_select_data->RequestSetRange) { selection.SetRange((int)(intptr_t)multi_select_data->RangeSrc, (int)(intptr_t)multi_select_data->RangeDst, multi_select_data->RangeValue ? 1 : 0); } if (multi_select_data->RequestSetRange) { selection->SetRange((int)(intptr_t)multi_select_data->RangeSrc, (int)(intptr_t)multi_select_data->RangeDst, multi_select_data->RangeValue ? 1 : 0); }
if (widget_type == WidgetType_TreeNode) if (widget_type == WidgetType_TreeNode)
ImGui::PopStyleVar(); ImGui::PopStyleVar();
@ -3037,6 +3040,12 @@ static void ShowDemoWindowMultiSelect()
ImGui::EndListBox(); ImGui::EndListBox();
} }
if (use_table)
{
ImGui::EndTable();
ImGui::PopStyleVar();
}
}
ImGui::TreePop(); ImGui::TreePop();
} }
ImGui::TreePop(); ImGui::TreePop();