Demonstrate/test rendering huge amount of text, and the incidence of clipping.
| 9836 | |
| 9837 | // Demonstrate/test rendering huge amount of text, and the incidence of clipping. |
| 9838 | static void ShowExampleAppLongText(bool* p_open) |
| 9839 | { |
| 9840 | ImGui::SetNextWindowSize(ImVec2(520, 600), ImGuiCond_FirstUseEver); |
| 9841 | if (!ImGui::Begin("Example: Long text display", p_open)) |
| 9842 | { |
| 9843 | ImGui::End(); |
| 9844 | return; |
| 9845 | } |
| 9846 | IMGUI_DEMO_MARKER("Examples/Long text display"); |
| 9847 | |
| 9848 | static int test_type = 0; |
| 9849 | static ImGuiTextBuffer log; |
| 9850 | static int lines = 0; |
| 9851 | ImGui::Text("Printing unusually long amount of text."); |
| 9852 | ImGui::Combo("Test type", &test_type, |
| 9853 | "Single call to TextUnformatted()\0" |
| 9854 | "Multiple calls to Text(), clipped\0" |
| 9855 | "Multiple calls to Text(), not clipped (slow)\0"); |
| 9856 | ImGui::Text("Buffer contents: %d lines, %d bytes", lines, log.size()); |
| 9857 | if (ImGui::Button("Clear")) { log.clear(); lines = 0; } |
| 9858 | ImGui::SameLine(); |
| 9859 | if (ImGui::Button("Add 1000 lines")) |
| 9860 | { |
| 9861 | for (int i = 0; i < 1000; i++) |
| 9862 | log.appendf("%i The quick brown fox jumps over the lazy dog\n", lines + i); |
| 9863 | lines += 1000; |
| 9864 | } |
| 9865 | ImGui::BeginChild("Log"); |
| 9866 | switch (test_type) |
| 9867 | { |
| 9868 | case 0: |
| 9869 | // Single call to TextUnformatted() with a big buffer |
| 9870 | ImGui::TextUnformatted(log.begin(), log.end()); |
| 9871 | break; |
| 9872 | case 1: |
| 9873 | { |
| 9874 | // Multiple calls to Text(), manually coarsely clipped - demonstrate how to use the ImGuiListClipper helper. |
| 9875 | ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0, 0)); |
| 9876 | ImGuiListClipper clipper; |
| 9877 | clipper.Begin(lines); |
| 9878 | while (clipper.Step()) |
| 9879 | for (int i = clipper.DisplayStart; i < clipper.DisplayEnd; i++) |
| 9880 | ImGui::Text("%i The quick brown fox jumps over the lazy dog", i); |
| 9881 | ImGui::PopStyleVar(); |
| 9882 | break; |
| 9883 | } |
| 9884 | case 2: |
| 9885 | // Multiple calls to Text(), not clipped (slow) |
| 9886 | ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0, 0)); |
| 9887 | for (int i = 0; i < lines; i++) |
| 9888 | ImGui::Text("%i The quick brown fox jumps over the lazy dog", i); |
| 9889 | ImGui::PopStyleVar(); |
| 9890 | break; |
| 9891 | } |
| 9892 | ImGui::EndChild(); |
| 9893 | ImGui::End(); |
| 9894 | } |
| 9895 |