Demonstrate/test rendering huge amount of text, and the incidence of clipping.
| 6944 | |
| 6945 | // Demonstrate/test rendering huge amount of text, and the incidence of clipping. |
| 6946 | static void ShowExampleAppLongText(bool* p_open) |
| 6947 | { |
| 6948 | ImGui::SetNextWindowSize(ImVec2(520, 600), ImGuiCond_FirstUseEver); |
| 6949 | if (!ImGui::Begin("Example: Long text display", p_open)) |
| 6950 | { |
| 6951 | ImGui::End(); |
| 6952 | return; |
| 6953 | } |
| 6954 | |
| 6955 | static int test_type = 0; |
| 6956 | static ImGuiTextBuffer log; |
| 6957 | static int lines = 0; |
| 6958 | ImGui::Text("Printing unusually long amount of text."); |
| 6959 | ImGui::Combo("Test type", &test_type, |
| 6960 | "Single call to TextUnformatted()\0" |
| 6961 | "Multiple calls to Text(), clipped\0" |
| 6962 | "Multiple calls to Text(), not clipped (slow)\0"); |
| 6963 | ImGui::Text("Buffer contents: %d lines, %d bytes", lines, log.size()); |
| 6964 | if (ImGui::Button("Clear")) { log.clear(); lines = 0; } |
| 6965 | ImGui::SameLine(); |
| 6966 | if (ImGui::Button("Add 1000 lines")) |
| 6967 | { |
| 6968 | for (int i = 0; i < 1000; i++) |
| 6969 | log.appendf("%i The quick brown fox jumps over the lazy dog\n", lines + i); |
| 6970 | lines += 1000; |
| 6971 | } |
| 6972 | ImGui::BeginChild("Log"); |
| 6973 | switch (test_type) |
| 6974 | { |
| 6975 | case 0: |
| 6976 | // Single call to TextUnformatted() with a big buffer |
| 6977 | ImGui::TextUnformatted(log.begin(), log.end()); |
| 6978 | break; |
| 6979 | case 1: |
| 6980 | { |
| 6981 | // Multiple calls to Text(), manually coarsely clipped - demonstrate how to use the ImGuiListClipper helper. |
| 6982 | ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0, 0)); |
| 6983 | ImGuiListClipper clipper; |
| 6984 | clipper.Begin(lines); |
| 6985 | while (clipper.Step()) |
| 6986 | for (int i = clipper.DisplayStart; i < clipper.DisplayEnd; i++) |
| 6987 | ImGui::Text("%i The quick brown fox jumps over the lazy dog", i); |
| 6988 | ImGui::PopStyleVar(); |
| 6989 | break; |
| 6990 | } |
| 6991 | case 2: |
| 6992 | // Multiple calls to Text(), not clipped (slow) |
| 6993 | ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0, 0)); |
| 6994 | for (int i = 0; i < lines; i++) |
| 6995 | ImGui::Text("%i The quick brown fox jumps over the lazy dog", i); |
| 6996 | ImGui::PopStyleVar(); |
| 6997 | break; |
| 6998 | } |
| 6999 | ImGui::EndChild(); |
| 7000 | ImGui::End(); |
| 7001 | } |
| 7002 | |
| 7003 | //----------------------------------------------------------------------------- |