Demo: Assets Browser: added a way to disable sorting and hide sorting options.

This is mostly designed to showcase that on very large sets (e.g. 1 million) most of the time is likely spent on sorting.
This commit is contained in:
ocornut 2024-06-11 20:56:41 +02:00
parent c07864f64a
commit f472f17054

View File

@ -9676,6 +9676,7 @@ struct ExampleAssetsBrowser
{
// Options
bool ShowTypeOverlay = true;
bool AllowSorting = true;
bool AllowDragUnselected = false;
bool AllowBoxSelect = true;
float IconSize = 32.0f;
@ -9778,6 +9779,7 @@ struct ExampleAssetsBrowser
ImGui::SeparatorText("Contents");
ImGui::Checkbox("Show Type Overlay", &ShowTypeOverlay);
ImGui::Checkbox("Allow Sorting", &AllowSorting);
ImGui::SeparatorText("Selection Behavior");
ImGui::Checkbox("Allow dragging unselected item", &AllowDragUnselected);
@ -9796,22 +9798,25 @@ struct ExampleAssetsBrowser
}
// Show a table with ONLY one header row to showcase the idea/possibility of using this to provide a sorting UI
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0, 0));
ImGuiTableFlags table_flags_for_sort_specs = ImGuiTableFlags_Sortable | ImGuiTableFlags_SortMulti | ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_Borders;
if (ImGui::BeginTable("for_sort_specs_only", 2, table_flags_for_sort_specs, ImVec2(0.0f, ImGui::GetFrameHeight())))
if (AllowSorting)
{
ImGui::TableSetupColumn("Index");
ImGui::TableSetupColumn("Type");
ImGui::TableHeadersRow();
if (ImGuiTableSortSpecs* sort_specs = ImGui::TableGetSortSpecs())
if (sort_specs->SpecsDirty || RequestSort)
{
ExampleAsset::SortWithSortSpecs(sort_specs, Items.Data, Items.Size);
sort_specs->SpecsDirty = RequestSort = false;
}
ImGui::EndTable();
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0, 0));
ImGuiTableFlags table_flags_for_sort_specs = ImGuiTableFlags_Sortable | ImGuiTableFlags_SortMulti | ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_Borders;
if (ImGui::BeginTable("for_sort_specs_only", 2, table_flags_for_sort_specs, ImVec2(0.0f, ImGui::GetFrameHeight())))
{
ImGui::TableSetupColumn("Index");
ImGui::TableSetupColumn("Type");
ImGui::TableHeadersRow();
if (ImGuiTableSortSpecs* sort_specs = ImGui::TableGetSortSpecs())
if (sort_specs->SpecsDirty || RequestSort)
{
ExampleAsset::SortWithSortSpecs(sort_specs, Items.Data, Items.Size);
sort_specs->SpecsDirty = RequestSort = false;
}
ImGui::EndTable();
}
ImGui::PopStyleVar();
}
ImGui::PopStyleVar();
ImGuiIO& io = ImGui::GetIO();
ImGui::SetNextWindowContentSize(ImVec2(0.0f, LayoutOuterPadding + LayoutLineCount * (LayoutItemSize.x + LayoutItemSpacing)));