mirror of
				https://github.com/ocornut/imgui.git
				synced 2025-11-04 09:44:29 +00:00 
			
		
		
		
	Demo: added basic Fonts section under main demo (same as Metrics one) for visibility.
This commit is contained in:
		
							
								
								
									
										18
									
								
								imgui.cpp
									
									
									
									
									
								
							
							
						
						
									
										18
									
								
								imgui.cpp
									
									
									
									
									
								
							@@ -15491,6 +15491,18 @@ static void MetricsHelpMarker(const char* desc)
 | 
				
			|||||||
// [DEBUG] List fonts in a font atlas and display its texture
 | 
					// [DEBUG] List fonts in a font atlas and display its texture
 | 
				
			||||||
void ImGui::ShowFontAtlas(ImFontAtlas* atlas)
 | 
					void ImGui::ShowFontAtlas(ImFontAtlas* atlas)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
					    ImGuiContext& g = *GImGui;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    Text("Read ");
 | 
				
			||||||
 | 
					    SameLine(0, 0);
 | 
				
			||||||
 | 
					    TextLinkOpenURL("https://www.dearimgui.com/faq/");
 | 
				
			||||||
 | 
					    SameLine(0, 0);
 | 
				
			||||||
 | 
					    Text(" for details on font loading.");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    ImGuiMetricsConfig* cfg = &g.DebugMetricsConfig;
 | 
				
			||||||
 | 
					    Checkbox("Show font preview", &cfg->ShowFontPreview);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // Font list
 | 
				
			||||||
    for (ImFont* font : atlas->Fonts)
 | 
					    for (ImFont* font : atlas->Fonts)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        PushID(font);
 | 
					        PushID(font);
 | 
				
			||||||
@@ -15499,7 +15511,6 @@ void ImGui::ShowFontAtlas(ImFontAtlas* atlas)
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
    if (TreeNode("Font Atlas", "Font Atlas (%dx%d pixels)", atlas->TexWidth, atlas->TexHeight))
 | 
					    if (TreeNode("Font Atlas", "Font Atlas (%dx%d pixels)", atlas->TexWidth, atlas->TexHeight))
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        ImGuiContext& g = *GImGui;
 | 
					 | 
				
			||||||
        PushStyleVar(ImGuiStyleVar_ImageBorderSize, ImMax(1.0f, g.Style.ImageBorderSize));
 | 
					        PushStyleVar(ImGuiStyleVar_ImageBorderSize, ImMax(1.0f, g.Style.ImageBorderSize));
 | 
				
			||||||
        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));
 | 
					        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));
 | 
				
			||||||
        PopStyleVar();
 | 
					        PopStyleVar();
 | 
				
			||||||
@@ -16290,6 +16301,8 @@ void ImGui::DebugNodeDrawCmdShowMeshAndBoundingBox(ImDrawList* out_draw_list, co
 | 
				
			|||||||
// [DEBUG] Display details for a single font, called by ShowStyleEditor().
 | 
					// [DEBUG] Display details for a single font, called by ShowStyleEditor().
 | 
				
			||||||
void ImGui::DebugNodeFont(ImFont* font)
 | 
					void ImGui::DebugNodeFont(ImFont* font)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
					    ImGuiContext& g = *GImGui;
 | 
				
			||||||
 | 
					    ImGuiMetricsConfig* cfg = &g.DebugMetricsConfig;
 | 
				
			||||||
    bool opened = TreeNode(font, "Font: \"%s\": %.2f px, %d glyphs, %d sources(s)",
 | 
					    bool opened = TreeNode(font, "Font: \"%s\": %.2f px, %d glyphs, %d sources(s)",
 | 
				
			||||||
        font->Sources ? font->Sources[0].Name : "", font->FontSize, font->Glyphs.Size, font->SourcesCount);
 | 
					        font->Sources ? font->Sources[0].Name : "", font->FontSize, font->Glyphs.Size, font->SourcesCount);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -16297,9 +16310,12 @@ void ImGui::DebugNodeFont(ImFont* font)
 | 
				
			|||||||
    if (!opened)
 | 
					    if (!opened)
 | 
				
			||||||
        Indent();
 | 
					        Indent();
 | 
				
			||||||
    Indent();
 | 
					    Indent();
 | 
				
			||||||
 | 
					    if (cfg->ShowFontPreview)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
        PushFont(font);
 | 
					        PushFont(font);
 | 
				
			||||||
        Text("The quick brown fox jumps over the lazy dog");
 | 
					        Text("The quick brown fox jumps over the lazy dog");
 | 
				
			||||||
        PopFont();
 | 
					        PopFont();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
    if (!opened)
 | 
					    if (!opened)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        Unindent();
 | 
					        Unindent();
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -82,6 +82,7 @@ Index of this file:
 | 
				
			|||||||
// [SECTION] DemoWindowWidgetsDisableBlocks()
 | 
					// [SECTION] DemoWindowWidgetsDisableBlocks()
 | 
				
			||||||
// [SECTION] DemoWindowWidgetsDragAndDrop()
 | 
					// [SECTION] DemoWindowWidgetsDragAndDrop()
 | 
				
			||||||
// [SECTION] DemoWindowWidgetsDragsAndSliders()
 | 
					// [SECTION] DemoWindowWidgetsDragsAndSliders()
 | 
				
			||||||
 | 
					// [SECTION] DemoWindowWidgetsFonts()
 | 
				
			||||||
// [SECTION] DemoWindowWidgetsImages()
 | 
					// [SECTION] DemoWindowWidgetsImages()
 | 
				
			||||||
// [SECTION] DemoWindowWidgetsListBoxes()
 | 
					// [SECTION] DemoWindowWidgetsListBoxes()
 | 
				
			||||||
// [SECTION] DemoWindowWidgetsMultiComponents()
 | 
					// [SECTION] DemoWindowWidgetsMultiComponents()
 | 
				
			||||||
@@ -1719,6 +1720,24 @@ static void DemoWindowWidgetsDragsAndSliders()
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					//-----------------------------------------------------------------------------
 | 
				
			||||||
 | 
					// [SECTION] DemoWindowWidgetsFonts()
 | 
				
			||||||
 | 
					//-----------------------------------------------------------------------------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Forward declare ShowFontAtlas() which isn't worth putting in public API yet
 | 
				
			||||||
 | 
					namespace ImGui { IMGUI_API void ShowFontAtlas(ImFontAtlas* atlas); }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void DemoWindowWidgetsFonts()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    IMGUI_DEMO_MARKER("Widgets/Fonts");
 | 
				
			||||||
 | 
					    if (ImGui::TreeNode("Fonts"))
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        ImFontAtlas* atlas = ImGui::GetIO().Fonts;
 | 
				
			||||||
 | 
					        ImGui::ShowFontAtlas(atlas);
 | 
				
			||||||
 | 
					        ImGui::TreePop();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
//-----------------------------------------------------------------------------
 | 
					//-----------------------------------------------------------------------------
 | 
				
			||||||
// [SECTION] DemoWindowWidgetsImages()
 | 
					// [SECTION] DemoWindowWidgetsImages()
 | 
				
			||||||
//-----------------------------------------------------------------------------
 | 
					//-----------------------------------------------------------------------------
 | 
				
			||||||
@@ -4182,6 +4201,7 @@ static void DemoWindowWidgets(ImGuiDemoWindowData* demo_data)
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    DemoWindowWidgetsDragAndDrop();
 | 
					    DemoWindowWidgetsDragAndDrop();
 | 
				
			||||||
    DemoWindowWidgetsDragsAndSliders();
 | 
					    DemoWindowWidgetsDragsAndSliders();
 | 
				
			||||||
 | 
					    DemoWindowWidgetsFonts();
 | 
				
			||||||
    DemoWindowWidgetsImages();
 | 
					    DemoWindowWidgetsImages();
 | 
				
			||||||
    DemoWindowWidgetsListBoxes();
 | 
					    DemoWindowWidgetsListBoxes();
 | 
				
			||||||
    DemoWindowWidgetsMultiComponents();
 | 
					    DemoWindowWidgetsMultiComponents();
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -2020,6 +2020,7 @@ struct ImGuiMetricsConfig
 | 
				
			|||||||
    int         ShowTablesRectsType = -1;
 | 
					    int         ShowTablesRectsType = -1;
 | 
				
			||||||
    int         HighlightMonitorIdx = -1;
 | 
					    int         HighlightMonitorIdx = -1;
 | 
				
			||||||
    ImGuiID     HighlightViewportID = 0;
 | 
					    ImGuiID     HighlightViewportID = 0;
 | 
				
			||||||
 | 
					    bool        ShowFontPreview = true;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct ImGuiStackLevelInfo
 | 
					struct ImGuiStackLevelInfo
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user