Demonstrate/test rendering huge amount of text, and the incidence of clipping.
| 7057 | |
| 7058 | // Demonstrate/test rendering huge amount of text, and the incidence of clipping. |
| 7059 | static void ShowExampleAppLongText(bool* p_open) |
| 7060 | { |
| 7061 | ImGui::SetNextWindowSize(ImVec2(520, 600), ImGuiCond_FirstUseEver); |
| 7062 | if (!ImGui::Begin("Example: Long text display", p_open)) |
| 7063 | { |
| 7064 | ImGui::End(); |
| 7065 | return; |
| 7066 | } |
| 7067 | IMGUI_DEMO_MARKER("Examples/Long text display"); |
| 7068 | |
| 7069 | static int test_type = 0; |
| 7070 | static ImGuiTextBuffer log; |
| 7071 | static int lines = 0; |
| 7072 | ImGui::Text("Printing unusually long amount of text."); |
| 7073 | ImGui::Combo("Test type", &test_type, |
| 7074 | "Single call to TextUnformatted()\0" |
| 7075 | "Multiple calls to Text(), clipped\0" |
| 7076 | "Multiple calls to Text(), not clipped (slow)\0"); |
| 7077 | ImGui::Text("Buffer contents: %d lines, %d bytes", lines, log.size()); |
| 7078 | if (ImGui::Button("Clear")) { log.clear(); lines = 0; } |
| 7079 | ImGui::SameLine(); |
| 7080 | if (ImGui::Button("Add 1000 lines")) |
| 7081 | { |
| 7082 | for (int i = 0; i < 1000; i++) |
| 7083 | log.appendf("%i The quick brown fox jumps over the lazy dog\n", lines + i); |
| 7084 | lines += 1000; |
| 7085 | } |
| 7086 | ImGui::BeginChild("Log"); |
| 7087 | switch (test_type) |
| 7088 | { |
| 7089 | case 0: |
| 7090 | // Single call to TextUnformatted() with a big buffer |
| 7091 | ImGui::TextUnformatted(log.begin(), log.end()); |
| 7092 | break; |
| 7093 | case 1: |
| 7094 | { |
| 7095 | // Multiple calls to Text(), manually coarsely clipped - demonstrate how to use the ImGuiListClipper helper. |
| 7096 | ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0, 0)); |
| 7097 | ImGuiListClipper clipper; |
| 7098 | clipper.Begin(lines); |
| 7099 | while (clipper.Step()) |
| 7100 | for (int i = clipper.DisplayStart; i < clipper.DisplayEnd; i++) |
| 7101 | ImGui::Text("%i The quick brown fox jumps over the lazy dog", i); |
| 7102 | ImGui::PopStyleVar(); |
| 7103 | break; |
| 7104 | } |
| 7105 | case 2: |
| 7106 | // Multiple calls to Text(), not clipped (slow) |
| 7107 | ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0, 0)); |
| 7108 | for (int i = 0; i < lines; i++) |
| 7109 | ImGui::Text("%i The quick brown fox jumps over the lazy dog", i); |
| 7110 | ImGui::PopStyleVar(); |
| 7111 | break; |
| 7112 | } |
| 7113 | ImGui::EndChild(); |
| 7114 | ImGui::End(); |
| 7115 | } |
| 7116 |