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)
| 862 | // (warning: this can allocates MANY MANY more times than other code in all of Dear ImGui + demo combined) |
| 863 | // (a real application managing one million nodes would likely store its tree data differently) |
| 864 | static ExampleTreeNode* ExampleTree_CreateDemoTree() |
| 865 | { |
| 866 | // 20 root nodes -> 211 total nodes, ~261 allocs. |
| 867 | // 1000 root nodes -> ~11K total nodes, ~14K allocs. |
| 868 | // 10000 root nodes -> ~123K total nodes, ~154K allocs. |
| 869 | // 100000 root nodes -> ~1338K total nodes, ~1666K allocs. |
| 870 | const int ROOT_ITEMS_COUNT = 20; |
| 871 | |
| 872 | static const char* category_names[] = { "Apple", "Banana", "Cherry", "Kiwi", "Mango", "Orange", "Pear", "Pineapple", "Strawberry", "Watermelon" }; |
| 873 | const int category_count = IM_COUNTOF(category_names); |
| 874 | const size_t NAME_MAX_LEN = sizeof(ExampleTreeNode::Name); |
| 875 | char name_buf[NAME_MAX_LEN]; |
| 876 | int uid = 0; |
| 877 | ExampleTreeNode* node_L0 = ExampleTree_CreateNode("<ROOT>", ++uid, NULL); |
| 878 | for (int idx_L0 = 0; idx_L0 < ROOT_ITEMS_COUNT; idx_L0++) |
| 879 | { |
| 880 | 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)); |
| 881 | ExampleTreeNode* node_L1 = ExampleTree_CreateNode(name_buf, ++uid, node_L0); |
| 882 | const int number_of_childs = (int)strlen(node_L1->Name); |
| 883 | for (int idx_L1 = 0; idx_L1 < number_of_childs; idx_L1++) |
| 884 | { |
| 885 | snprintf(name_buf, IM_COUNTOF(name_buf), "Child %d", idx_L1); |
| 886 | ExampleTreeNode* node_L2 = ExampleTree_CreateNode(name_buf, ++uid, node_L1); |
| 887 | node_L2->HasData = true; |
| 888 | if (idx_L1 == 0) |
| 889 | { |
| 890 | snprintf(name_buf, IM_COUNTOF(name_buf), "Sub-child %d", 0); |
| 891 | ExampleTreeNode* node_L3 = ExampleTree_CreateNode(name_buf, ++uid, node_L2); |
| 892 | node_L3->HasData = true; |
| 893 | } |
| 894 | } |
| 895 | } |
| 896 | return node_L0; |
| 897 | } |
| 898 | |
| 899 | //----------------------------------------------------------------------------- |
| 900 | // [SECTION] DemoWindowWidgetsBasic() |
no test coverage detected