@@ -12060,11 +12060,15 @@ static void SetPlatformImeDataFn_DefaultImpl(ImGuiViewport*, ImGuiPlatformImeDat
12060
12060
//-----------------------------------------------------------------------------
12061
12061
// - RenderViewportThumbnail() [Internal]
12062
12062
// - RenderViewportsThumbnails() [Internal]
12063
+ // - DebugTextEncoding()
12063
12064
// - MetricsHelpMarker() [Internal]
12065
+ // - ShowFontAtlas() [Internal]
12064
12066
// - ShowMetricsWindow()
12065
12067
// - DebugNodeColumns() [Internal]
12066
12068
// - DebugNodeDrawList() [Internal]
12067
12069
// - DebugNodeDrawCmdShowMeshAndBoundingBox() [Internal]
12070
+ // - DebugNodeFont() [Internal]
12071
+ // - DebugNodeFontGlyph() [Internal]
12068
12072
// - DebugNodeStorage() [Internal]
12069
12073
// - DebugNodeTabBar() [Internal]
12070
12074
// - DebugNodeViewport() [Internal]
@@ -12127,79 +12131,40 @@ static void RenderViewportsThumbnails()
12127
12131
ImGui::Dummy(bb_full.GetSize() * SCALE);
12128
12132
}
12129
12133
12130
- static void ShowEncodingViewerChar(ImFont* font, ImWchar c, const char* c_utf8)
12134
+ // Helper tool to diagnose between text encoding issues and font loading issues. Pass your UTF-8 string and verify that there are correct.
12135
+ void ImGui::DebugTextEncoding(const char* str)
12131
12136
{
12132
- ImGui::TableNextColumn();
12133
- if (font->FindGlyphNoFallback(c))
12134
- ImGui::TextUnformatted(c_utf8);
12135
- else
12136
- ImGui::TextColored(ImVec4(1.0f, 0.0f, 0.0f, 1.0f), "(not in font)");
12137
-
12138
- ImGui::TableNextColumn();
12139
- char utf8_code[] = "0x.. 0x.. 0x.. 0x..";
12140
- for (int byte_index = 0; c_utf8[byte_index]; byte_index++)
12141
- {
12142
- if (byte_index > 0)
12143
- utf8_code[byte_index * 5 - 1] = ' ';
12144
- ImFormatString(utf8_code + (byte_index * 5) + 2, 3, "%02X", (int)(unsigned char)c_utf8[byte_index]);
12145
- }
12146
- ImGui::TextUnformatted(utf8_code);
12147
- ImGui::TableNextColumn();
12148
- ImGui::Text("U+%04X", (int)c);
12149
- }
12150
-
12151
- static void ShowUTF8EncodingViewer()
12152
- {
12153
- static char buf[256] = "";
12154
- static ImFontGlyphRangesBuilder range_builder;
12155
- static ImVector<ImWchar> ranges;
12156
- static bool unique_glyphs = false;
12157
-
12158
- ImGui::SetNextItemWidth(-FLT_MIN);
12159
-
12160
- bool rebuild = false;
12161
- rebuild |= ImGui::InputText("##Sample Text", buf, IM_ARRAYSIZE(buf));
12162
- rebuild |= ImGui::Checkbox("Sorted unique glyphs", &unique_glyphs);
12163
- if (rebuild && unique_glyphs)
12164
- {
12165
- range_builder.Clear();
12166
- range_builder.AddText(buf);
12167
- ranges.clear();
12168
- range_builder.BuildRanges(&ranges);
12169
- }
12170
- if (ImGui::BeginTable("list", 3, ImGuiTableFlags_Borders | ImGuiTableFlags_ScrollY, ImVec2(0.0f, ImGui::GetFontSize() * 15)))
12137
+ Text("Text: \"%s\"", str);
12138
+ if (!BeginTable("list", 4, ImGuiTableFlags_Borders | ImGuiTableFlags_RowBg | ImGuiTableFlags_SizingFixedFit))
12139
+ return;
12140
+ TableSetupColumn("Offset");
12141
+ TableSetupColumn("UTF-8");
12142
+ TableSetupColumn("Glyph");
12143
+ TableSetupColumn("Codepoint");
12144
+ TableHeadersRow();
12145
+ for (const char* p = str; *p != 0; )
12171
12146
{
12172
- ImGui::TableSetupColumn("Glyph");
12173
- ImGui::TableSetupColumn("UTF-8");
12174
- ImGui::TableSetupColumn("Codepoint");
12175
- ImGui::TableHeadersRow();
12176
-
12177
- ImFont* font = ImGui::GetFont();
12178
- if (unique_glyphs)
12179
- {
12180
- for (int range_index = 0; range_index < ranges.Size && ranges[range_index] != 0; range_index += 2)
12181
- for (ImWchar c = ranges[range_index]; c <= ranges[range_index + 1]; c++)
12182
- {
12183
- char c_utf8[4 + 1];
12184
- ImTextStrToUtf8(c_utf8, IM_ARRAYSIZE(c_utf8), &c, &c + 1);
12185
- ShowEncodingViewerChar(font, c, c_utf8);
12186
- }
12187
- }
12147
+ unsigned int c;
12148
+ const int c_utf8_len = ImTextCharFromUtf8(&c, p, NULL);
12149
+ TableNextColumn();
12150
+ Text("%d", (int)(p - str));
12151
+ TableNextColumn();
12152
+ for (int byte_index = 0; byte_index < c_utf8_len; byte_index++)
12153
+ {
12154
+ if (byte_index > 0)
12155
+ SameLine();
12156
+ Text("0x%02X", (int)(unsigned char)p[byte_index]);
12157
+ }
12158
+ TableNextColumn();
12159
+ if (GetFont()->FindGlyphNoFallback((ImWchar)c))
12160
+ TextUnformatted(p, p + c_utf8_len);
12188
12161
else
12189
- {
12190
- for (const char* p = buf; p[0] != 0;)
12191
- {
12192
- unsigned int c;
12193
- int c_utf8_len = ImTextCharFromUtf8(&c, p, NULL);
12194
- char c_utf8[4 + 1];
12195
- memcpy(c_utf8, p, c_utf8_len);
12196
- c_utf8[c_utf8_len] = 0;
12197
- ShowEncodingViewerChar(font, (ImWchar)c, c_utf8);
12198
- p += c_utf8_len;
12199
- }
12200
- }
12201
- ImGui::EndTable();
12162
+ TextUnformatted("[missing]");
12163
+ TableNextColumn();
12164
+ Text("U+%04X", (int)c);
12165
+ p += c_utf8_len;
12202
12166
}
12167
+ EndTable();
12203
12168
}
12204
12169
12205
12170
// Avoid naming collision with imgui_demo.cpp's HelpMarker() for unity builds.
@@ -12216,9 +12181,24 @@ static void MetricsHelpMarker(const char* desc)
12216
12181
}
12217
12182
}
12218
12183
12219
- #ifndef IMGUI_DISABLE_DEMO_WINDOWS
12220
- namespace ImGui { void ShowFontAtlas(ImFontAtlas* atlas); }
12221
- #endif
12184
+ // [DEBUG] List fonts in a font atlas and display its texture
12185
+ void ImGui::ShowFontAtlas(ImFontAtlas* atlas)
12186
+ {
12187
+ for (int i = 0; i < atlas->Fonts.Size; i++)
12188
+ {
12189
+ ImFont* font = atlas->Fonts[i];
12190
+ PushID(font);
12191
+ DebugNodeFont(font);
12192
+ PopID();
12193
+ }
12194
+ if (TreeNode("Atlas texture", "Atlas texture (%dx%d pixels)", atlas->TexWidth, atlas->TexHeight))
12195
+ {
12196
+ ImVec4 tint_col = ImVec4(1.0f, 1.0f, 1.0f, 1.0f);
12197
+ ImVec4 border_col = ImVec4(1.0f, 1.0f, 1.0f, 0.5f);
12198
+ Image(atlas->TexID, ImVec2((float)atlas->TexWidth, (float)atlas->TexHeight), ImVec2(0.0f, 0.0f), ImVec2(1.0f, 1.0f), tint_col, border_col);
12199
+ TreePop();
12200
+ }
12201
+ }
12222
12202
12223
12203
void ImGui::ShowMetricsWindow(bool* p_open)
12224
12204
{
@@ -12293,6 +12273,19 @@ void ImGui::ShowMetricsWindow(bool* p_open)
12293
12273
// Tools
12294
12274
if (TreeNode("Tools"))
12295
12275
{
12276
+ bool show_encoding_viewer = TreeNode("UTF-8 Encoding viewer");
12277
+ SameLine();
12278
+ MetricsHelpMarker("You can also call ImGui::DebugTextEncoding() from your code with a given string to test that your UTF-8 encoding settings are correct.");
12279
+ if (show_encoding_viewer)
12280
+ {
12281
+ static char buf[100] = "";
12282
+ SetNextItemWidth(-FLT_MIN);
12283
+ InputText("##Text", buf, IM_ARRAYSIZE(buf));
12284
+ if (buf[0] != 0)
12285
+ DebugTextEncoding(buf);
12286
+ TreePop();
12287
+ }
12288
+
12296
12289
// Stack Tool is your best friend!
12297
12290
Checkbox("Show stack tool", &cfg->ShowStackTool);
12298
12291
SameLine();
@@ -12360,12 +12353,6 @@ void ImGui::ShowMetricsWindow(bool* p_open)
12360
12353
}
12361
12354
}
12362
12355
12363
- if (TreeNode("UTF-8 Encoding viewer"))
12364
- {
12365
- ShowUTF8EncodingViewer();
12366
- TreePop();
12367
- }
12368
-
12369
12356
// The Item Picker tool is super useful to visually select an item and break into the call-stack of where it was submitted.
12370
12357
if (Button("Item Picker.."))
12371
12358
DebugStartItemPicker();
@@ -12461,14 +12448,12 @@ void ImGui::ShowMetricsWindow(bool* p_open)
12461
12448
}
12462
12449
12463
12450
// Details for Fonts
12464
- #ifndef IMGUI_DISABLE_DEMO_WINDOWS
12465
12451
ImFontAtlas* atlas = g.IO.Fonts;
12466
12452
if (TreeNode("Fonts", "Fonts (%d)", atlas->Fonts.Size))
12467
12453
{
12468
12454
ShowFontAtlas(atlas);
12469
12455
TreePop();
12470
12456
}
12471
- #endif
12472
12457
12473
12458
// Details for Docking
12474
12459
#ifdef IMGUI_HAS_DOCK
@@ -12628,25 +12613,6 @@ void ImGui::ShowMetricsWindow(bool* p_open)
12628
12613
End();
12629
12614
}
12630
12615
12631
- // [DEBUG] List fonts in a font atlas and display its texture
12632
- void ImGui::ShowFontAtlas(ImFontAtlas* atlas)
12633
- {
12634
- for (int i = 0; i < atlas->Fonts.Size; i++)
12635
- {
12636
- ImFont* font = atlas->Fonts[i];
12637
- PushID(font);
12638
- DebugNodeFont(font);
12639
- PopID();
12640
- }
12641
- if (TreeNode("Atlas texture", "Atlas texture (%dx%d pixels)", atlas->TexWidth, atlas->TexHeight))
12642
- {
12643
- ImVec4 tint_col = ImVec4(1.0f, 1.0f, 1.0f, 1.0f);
12644
- ImVec4 border_col = ImVec4(1.0f, 1.0f, 1.0f, 0.5f);
12645
- Image(atlas->TexID, ImVec2((float)atlas->TexWidth, (float)atlas->TexHeight), ImVec2(0.0f, 0.0f), ImVec2(1.0f, 1.0f), tint_col, border_col);
12646
- TreePop();
12647
- }
12648
- }
12649
-
12650
12616
// [DEBUG] Display contents of Columns
12651
12617
void ImGui::DebugNodeColumns(ImGuiOldColumns* columns)
12652
12618
{
@@ -12856,17 +12822,13 @@ void ImGui::DebugNodeFont(ImFont* font)
12856
12822
ImVec2 cell_p2(cell_p1.x + cell_size, cell_p1.y + cell_size);
12857
12823
const ImFontGlyph* glyph = font->FindGlyphNoFallback((ImWchar)(base + n));
12858
12824
draw_list->AddRect(cell_p1, cell_p2, glyph ? IM_COL32(255, 255, 255, 100) : IM_COL32(255, 255, 255, 50));
12859
- if (glyph)
12860
- font->RenderChar(draw_list, cell_size, cell_p1, glyph_col, (ImWchar)(base + n));
12861
- if (glyph && IsMouseHoveringRect(cell_p1, cell_p2))
12825
+ if (!glyph)
12826
+ continue;
12827
+ font->RenderChar(draw_list, cell_size, cell_p1, glyph_col, (ImWchar)(base + n));
12828
+ if (IsMouseHoveringRect(cell_p1, cell_p2))
12862
12829
{
12863
12830
BeginTooltip();
12864
- Text("Codepoint: U+%04X", base + n);
12865
- Separator();
12866
- Text("Visible: %d", glyph->Visible);
12867
- Text("AdvanceX: %.1f", glyph->AdvanceX);
12868
- Text("Pos: (%.2f,%.2f)->(%.2f,%.2f)", glyph->X0, glyph->Y0, glyph->X1, glyph->Y1);
12869
- Text("UV: (%.3f,%.3f)->(%.3f,%.3f)", glyph->U0, glyph->V0, glyph->U1, glyph->V1);
12831
+ DebugNodeFontGlyph(font, glyph);
12870
12832
EndTooltip();
12871
12833
}
12872
12834
}
@@ -12878,6 +12840,16 @@ void ImGui::DebugNodeFont(ImFont* font)
12878
12840
TreePop();
12879
12841
}
12880
12842
12843
+ void ImGui::DebugNodeFontGlyph(ImFont*, const ImFontGlyph* glyph)
12844
+ {
12845
+ Text("Codepoint: U+%04X", glyph->Codepoint);
12846
+ Separator();
12847
+ Text("Visible: %d", glyph->Visible);
12848
+ Text("AdvanceX: %.1f", glyph->AdvanceX);
12849
+ Text("Pos: (%.2f,%.2f)->(%.2f,%.2f)", glyph->X0, glyph->Y0, glyph->X1, glyph->Y1);
12850
+ Text("UV: (%.3f,%.3f)->(%.3f,%.3f)", glyph->U0, glyph->V0, glyph->U1, glyph->V1);
12851
+ }
12852
+
12881
12853
// [DEBUG] Display contents of ImGuiStorage
12882
12854
void ImGui::DebugNodeStorage(ImGuiStorage* storage, const char* label)
12883
12855
{
0 commit comments