MCPcopy Create free account
hub / github.com/PCSX2/pcsx2 / ExampleTree_CreateDemoTree

Function ExampleTree_CreateDemoTree

3rdparty/imgui/src/imgui_demo.cpp:799–832  ·  view source on GitHub ↗

Create example tree data (warning: this can allocates MANY MANY more times than other code in all of Dear ImGui + demo combined) (a real application managing one million nodes would likely store its tree data differently)

Source from the content-addressed store, hash-verified

797// (warning: this can allocates MANY MANY more times than other code in all of Dear ImGui + demo combined)
798// (a real application managing one million nodes would likely store its tree data differently)
799static ExampleTreeNode* ExampleTree_CreateDemoTree()
800{
801 // 20 root nodes -> 211 total nodes, ~261 allocs.
802 // 1000 root nodes -> ~11K total nodes, ~14K allocs.
803 // 10000 root nodes -> ~123K total nodes, ~154K allocs.
804 // 100000 root nodes -> ~1338K total nodes, ~1666K allocs.
805 const int ROOT_ITEMS_COUNT = 20;
806
807 static const char* category_names[] = { "Apple", "Banana", "Cherry", "Kiwi", "Mango", "Orange", "Pear", "Pineapple", "Strawberry", "Watermelon" };
808 const int category_count = IM_COUNTOF(category_names);
809 const size_t NAME_MAX_LEN = sizeof(ExampleTreeNode::Name);
810 char name_buf[NAME_MAX_LEN];
811 int uid = 0;
812 ExampleTreeNode* node_L0 = ExampleTree_CreateNode("<ROOT>", ++uid, NULL);
813 for (int idx_L0 = 0; idx_L0 < ROOT_ITEMS_COUNT; idx_L0++)
814 {
815 snprintf(name_buf, IM_COUNTOF(name_buf), "%s %d", category_names[idx_L0 / (ROOT_ITEMS_COUNT / category_count)], idx_L0 % (ROOT_ITEMS_COUNT / category_count));
816 ExampleTreeNode* node_L1 = ExampleTree_CreateNode(name_buf, ++uid, node_L0);
817 const int number_of_childs = (int)strlen(node_L1->Name);
818 for (int idx_L1 = 0; idx_L1 < number_of_childs; idx_L1++)
819 {
820 snprintf(name_buf, IM_COUNTOF(name_buf), "Child %d", idx_L1);
821 ExampleTreeNode* node_L2 = ExampleTree_CreateNode(name_buf, ++uid, node_L1);
822 node_L2->HasData = true;
823 if (idx_L1 == 0)
824 {
825 snprintf(name_buf, IM_COUNTOF(name_buf), "Sub-child %d", 0);
826 ExampleTreeNode* node_L3 = ExampleTree_CreateNode(name_buf, ++uid, node_L2);
827 node_L3->HasData = true;
828 }
829 }
830 }
831 return node_L0;
832}
833
834//-----------------------------------------------------------------------------
835// [SECTION] Helpers: ExampleImageViewer

Calls 1

ExampleTree_CreateNodeFunction · 0.85

Tested by

no test coverage detected