Demonstrate/test rendering huge amount of text, and the incidence of clipping.
| 4239 | |
| 4240 | // Demonstrate/test rendering huge amount of text, and the incidence of clipping. |
| 4241 | static void ShowExampleAppLongText(bool* p_open) |
| 4242 | { |
| 4243 | ImGui::SetNextWindowSize(ImVec2(520,600), ImGuiCond_FirstUseEver); |
| 4244 | if (!ImGui::Begin("Example: Long text display", p_open)) |
| 4245 | { |
| 4246 | ImGui::End(); |
| 4247 | return; |
| 4248 | } |
| 4249 | |
| 4250 | static int test_type = 0; |
| 4251 | static ImGuiTextBuffer log; |
| 4252 | static int lines = 0; |
| 4253 | ImGui::Text("Printing unusually long amount of text."); |
| 4254 | ImGui::Combo("Test type", &test_type, "Single call to TextUnformatted()\0Multiple calls to Text(), clipped\0Multiple calls to Text(), not clipped (slow)\0"); |
| 4255 | ImGui::Text("Buffer contents: %d lines, %d bytes", lines, log.size()); |
| 4256 | if (ImGui::Button("Clear")) { log.clear(); lines = 0; } |
| 4257 | ImGui::SameLine(); |
| 4258 | if (ImGui::Button("Add 1000 lines")) |
| 4259 | { |
| 4260 | for (int i = 0; i < 1000; i++) |
| 4261 | log.appendf("%i The quick brown fox jumps over the lazy dog\n", lines+i); |
| 4262 | lines += 1000; |
| 4263 | } |
| 4264 | ImGui::BeginChild("Log"); |
| 4265 | switch (test_type) |
| 4266 | { |
| 4267 | case 0: |
| 4268 | // Single call to TextUnformatted() with a big buffer |
| 4269 | ImGui::TextUnformatted(log.begin(), log.end()); |
| 4270 | break; |
| 4271 | case 1: |
| 4272 | { |
| 4273 | // Multiple calls to Text(), manually coarsely clipped - demonstrate how to use the ImGuiListClipper helper. |
| 4274 | ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0,0)); |
| 4275 | ImGuiListClipper clipper(lines); |
| 4276 | while (clipper.Step()) |
| 4277 | for (int i = clipper.DisplayStart; i < clipper.DisplayEnd; i++) |
| 4278 | ImGui::Text("%i The quick brown fox jumps over the lazy dog", i); |
| 4279 | ImGui::PopStyleVar(); |
| 4280 | break; |
| 4281 | } |
| 4282 | case 2: |
| 4283 | // Multiple calls to Text(), not clipped (slow) |
| 4284 | ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0,0)); |
| 4285 | for (int i = 0; i < lines; i++) |
| 4286 | ImGui::Text("%i The quick brown fox jumps over the lazy dog", i); |
| 4287 | ImGui::PopStyleVar(); |
| 4288 | break; |
| 4289 | } |
| 4290 | ImGui::EndChild(); |
| 4291 | ImGui::End(); |
| 4292 | } |
| 4293 | |
| 4294 | //----------------------------------------------------------------------------- |
| 4295 | // [SECTION] Example App: Auto Resize / ShowExampleAppAutoResize() |