Skip to content

Commit afd3a36

Browse files
committed
Demo: added basic Fonts section under main demo (same as Metrics one) for visibility.
1 parent c5e2bb7 commit afd3a36

File tree

3 files changed

+41
-4
lines changed

3 files changed

+41
-4
lines changed

imgui.cpp

+20-4
Original file line numberDiff line numberDiff line change
@@ -15491,6 +15491,18 @@ static void MetricsHelpMarker(const char* desc)
1549115491
// [DEBUG] List fonts in a font atlas and display its texture
1549215492
void ImGui::ShowFontAtlas(ImFontAtlas* atlas)
1549315493
{
15494+
ImGuiContext& g = *GImGui;
15495+
15496+
Text("Read ");
15497+
SameLine(0, 0);
15498+
TextLinkOpenURL("https://www.dearimgui.com/faq/");
15499+
SameLine(0, 0);
15500+
Text(" for details on font loading.");
15501+
15502+
ImGuiMetricsConfig* cfg = &g.DebugMetricsConfig;
15503+
Checkbox("Show font preview", &cfg->ShowFontPreview);
15504+
15505+
// Font list
1549415506
for (ImFont* font : atlas->Fonts)
1549515507
{
1549615508
PushID(font);
@@ -15499,7 +15511,6 @@ void ImGui::ShowFontAtlas(ImFontAtlas* atlas)
1549915511
}
1550015512
if (TreeNode("Font Atlas", "Font Atlas (%dx%d pixels)", atlas->TexWidth, atlas->TexHeight))
1550115513
{
15502-
ImGuiContext& g = *GImGui;
1550315514
PushStyleVar(ImGuiStyleVar_ImageBorderSize, ImMax(1.0f, g.Style.ImageBorderSize));
1550415515
ImageWithBg(atlas->TexID, ImVec2((float)atlas->TexWidth, (float)atlas->TexHeight), ImVec2(0.0f, 0.0f), ImVec2(1.0f, 1.0f), ImVec4(0.0f, 0.0f, 0.0f, 1.0f));
1550515516
PopStyleVar();
@@ -16290,16 +16301,21 @@ void ImGui::DebugNodeDrawCmdShowMeshAndBoundingBox(ImDrawList* out_draw_list, co
1629016301
// [DEBUG] Display details for a single font, called by ShowStyleEditor().
1629116302
void ImGui::DebugNodeFont(ImFont* font)
1629216303
{
16304+
ImGuiContext& g = *GImGui;
16305+
ImGuiMetricsConfig* cfg = &g.DebugMetricsConfig;
1629316306
bool opened = TreeNode(font, "Font: \"%s\": %.2f px, %d glyphs, %d sources(s)",
1629416307
font->Sources ? font->Sources[0].Name : "", font->FontSize, font->Glyphs.Size, font->SourcesCount);
1629516308

1629616309
// Display preview text
1629716310
if (!opened)
1629816311
Indent();
1629916312
Indent();
16300-
PushFont(font);
16301-
Text("The quick brown fox jumps over the lazy dog");
16302-
PopFont();
16313+
if (cfg->ShowFontPreview)
16314+
{
16315+
PushFont(font);
16316+
Text("The quick brown fox jumps over the lazy dog");
16317+
PopFont();
16318+
}
1630316319
if (!opened)
1630416320
{
1630516321
Unindent();

imgui_demo.cpp

+20
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ Index of this file:
8282
// [SECTION] DemoWindowWidgetsDisableBlocks()
8383
// [SECTION] DemoWindowWidgetsDragAndDrop()
8484
// [SECTION] DemoWindowWidgetsDragsAndSliders()
85+
// [SECTION] DemoWindowWidgetsFonts()
8586
// [SECTION] DemoWindowWidgetsImages()
8687
// [SECTION] DemoWindowWidgetsListBoxes()
8788
// [SECTION] DemoWindowWidgetsMultiComponents()
@@ -1719,6 +1720,24 @@ static void DemoWindowWidgetsDragsAndSliders()
17191720
}
17201721
}
17211722

1723+
//-----------------------------------------------------------------------------
1724+
// [SECTION] DemoWindowWidgetsFonts()
1725+
//-----------------------------------------------------------------------------
1726+
1727+
// Forward declare ShowFontAtlas() which isn't worth putting in public API yet
1728+
namespace ImGui { IMGUI_API void ShowFontAtlas(ImFontAtlas* atlas); }
1729+
1730+
static void DemoWindowWidgetsFonts()
1731+
{
1732+
IMGUI_DEMO_MARKER("Widgets/Fonts");
1733+
if (ImGui::TreeNode("Fonts"))
1734+
{
1735+
ImFontAtlas* atlas = ImGui::GetIO().Fonts;
1736+
ImGui::ShowFontAtlas(atlas);
1737+
ImGui::TreePop();
1738+
}
1739+
}
1740+
17221741
//-----------------------------------------------------------------------------
17231742
// [SECTION] DemoWindowWidgetsImages()
17241743
//-----------------------------------------------------------------------------
@@ -4182,6 +4201,7 @@ static void DemoWindowWidgets(ImGuiDemoWindowData* demo_data)
41824201

41834202
DemoWindowWidgetsDragAndDrop();
41844203
DemoWindowWidgetsDragsAndSliders();
4204+
DemoWindowWidgetsFonts();
41854205
DemoWindowWidgetsImages();
41864206
DemoWindowWidgetsListBoxes();
41874207
DemoWindowWidgetsMultiComponents();

imgui_internal.h

+1
Original file line numberDiff line numberDiff line change
@@ -2020,6 +2020,7 @@ struct ImGuiMetricsConfig
20202020
int ShowTablesRectsType = -1;
20212021
int HighlightMonitorIdx = -1;
20222022
ImGuiID HighlightViewportID = 0;
2023+
bool ShowFontPreview = true;
20232024
};
20242025

20252026
struct ImGuiStackLevelInfo

0 commit comments

Comments
 (0)