MCPcopy Create free account
hub / github.com/IppClub/Dora-SSR / ExampleTree_CreateDemoTree

Function ExampleTree_CreateDemoTree

Source/3rdParty/imgui/imgui_demo.cpp:793–826  ·  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

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

Calls 3

ExampleTree_CreateNodeFunction · 0.85
strlenFunction · 0.85
snprintfFunction · 0.50

Tested by

no test coverage detected