MCPcopy Create free account
hub / github.com/Raais/ImStudio / ShowExampleAppLongText

Function ShowExampleAppLongText

src/third-party/imgui/imgui_demo.cpp:7126–7182  ·  view source on GitHub ↗

Demonstrate/test rendering huge amount of text, and the incidence of clipping.

Source from the content-addressed store, hash-verified

7124
7125// Demonstrate/test rendering huge amount of text, and the incidence of clipping.
7126static void ShowExampleAppLongText(bool* p_open)
7127{
7128 ImGui::SetNextWindowSize(ImVec2(520, 600), ImGuiCond_FirstUseEver);
7129 if (!ImGui::Begin("Example: Long text display", p_open))
7130 {
7131 ImGui::End();
7132 return;
7133 }
7134 IMGUI_DEMO_MARKER("Examples/Long text display");
7135
7136 static int test_type = 0;
7137 static ImGuiTextBuffer log;
7138 static int lines = 0;
7139 ImGui::Text("Printing unusually long amount of text.");
7140 ImGui::Combo("Test type", &test_type,
7141 "Single call to TextUnformatted()\0"
7142 "Multiple calls to Text(), clipped\0"
7143 "Multiple calls to Text(), not clipped (slow)\0");
7144 ImGui::Text("Buffer contents: %d lines, %d bytes", lines, log.size());
7145 if (ImGui::Button("Clear")) { log.clear(); lines = 0; }
7146 ImGui::SameLine();
7147 if (ImGui::Button("Add 1000 lines"))
7148 {
7149 for (int i = 0; i < 1000; i++)
7150 log.appendf("%i The quick brown fox jumps over the lazy dog\n", lines + i);
7151 lines += 1000;
7152 }
7153 ImGui::BeginChild("Log");
7154 switch (test_type)
7155 {
7156 case 0:
7157 // Single call to TextUnformatted() with a big buffer
7158 ImGui::TextUnformatted(log.begin(), log.end());
7159 break;
7160 case 1:
7161 {
7162 // Multiple calls to Text(), manually coarsely clipped - demonstrate how to use the ImGuiListClipper helper.
7163 ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0, 0));
7164 ImGuiListClipper clipper;
7165 clipper.Begin(lines);
7166 while (clipper.Step())
7167 for (int i = clipper.DisplayStart; i < clipper.DisplayEnd; i++)
7168 ImGui::Text("%i The quick brown fox jumps over the lazy dog", i);
7169 ImGui::PopStyleVar();
7170 break;
7171 }
7172 case 2:
7173 // Multiple calls to Text(), not clipped (slow)
7174 ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0, 0));
7175 for (int i = 0; i < lines; i++)
7176 ImGui::Text("%i The quick brown fox jumps over the lazy dog", i);
7177 ImGui::PopStyleVar();
7178 break;
7179 }
7180 ImGui::EndChild();
7181 ImGui::End();
7182}
7183

Callers 1

ShowDemoWindowMethod · 0.85

Calls 8

ImVec2Function · 0.85
appendfMethod · 0.80
BeginMethod · 0.80
sizeMethod · 0.45
clearMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
StepMethod · 0.45

Tested by

no test coverage detected