WIP - Demo: Add a "Fonts" section for visibility.

This commit is contained in:
ocornut 2025-03-05 17:05:24 +01:00
parent 48c0166f43
commit 6a41bccf3d
2 changed files with 32 additions and 9 deletions

View file

@ -21247,6 +21247,11 @@ namespace ImGuiFreeType { IMGUI_API const ImFontLoader* GetFontLoader(); }
// [DEBUG] List fonts in a font atlas and display its texture
void ImGui::ShowFontAtlas(ImFontAtlas* atlas)
{
SeparatorText("Backend Support for Dynamic Fonts");
BeginDisabled();
CheckboxFlags("io.BackendFlags: RendererHasTextures", &GetIO().BackendFlags, ImGuiBackendFlags_RendererHasTextures);
EndDisabled();
SeparatorText("Fonts");
Text("Read the FAQ at ");
SameLine(0, 0);
@ -22327,12 +22332,11 @@ void ImGui::DebugNodeFont(ImFont* font)
}
if (SmallButton("Set as default"))
GetIO().FontDefault = font;
if (atlas->Fonts.Size > 1 && !atlas->Locked)
{
SameLine();
if (SmallButton("Remove"))
atlas->RemoveFont(font);
}
SameLine();
BeginDisabled(atlas->Fonts.Size <= 1 || atlas->Locked);
if (SmallButton("Remove"))
atlas->RemoveFont(font);
EndDisabled();
// Display details
SetNextItemWidth(GetFontSize() * 8);

View file

@ -82,6 +82,7 @@ Index of this file:
// [SECTION] DemoWindowWidgetsDisableBlocks()
// [SECTION] DemoWindowWidgetsDragAndDrop()
// [SECTION] DemoWindowWidgetsDragsAndSliders()
// [SECTION] DemoWindowWidgetsFonts()
// [SECTION] DemoWindowWidgetsImages()
// [SECTION] DemoWindowWidgetsListBoxes()
// [SECTION] DemoWindowWidgetsMultiComponents()
@ -1780,6 +1781,26 @@ 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::SeparatorText("Advanced");
// FIXME-NEWATLAS: Provide a demo to add/create a procedural font?
ImGui::TreePop();
}
}
//-----------------------------------------------------------------------------
// [SECTION] DemoWindowWidgetsImages()
//-----------------------------------------------------------------------------
@ -4222,6 +4243,7 @@ static void DemoWindowWidgets(ImGuiDemoWindowData* demo_data)
DemoWindowWidgetsDragAndDrop();
DemoWindowWidgetsDragsAndSliders();
DemoWindowWidgetsFonts();
DemoWindowWidgetsImages();
DemoWindowWidgetsListBoxes();
DemoWindowWidgetsMultiComponents();
@ -8189,9 +8211,6 @@ void ImGui::ShowAboutWindow(bool* p_open)
// - ShowStyleEditor()
//-----------------------------------------------------------------------------
// Forward declare ShowFontAtlas() which isn't worth putting in public API yet
namespace ImGui { IMGUI_API void ShowFontAtlas(ImFontAtlas* atlas); }
// Demo helper function to select among loaded fonts.
// Here we use the regular BeginCombo()/EndCombo() api which is the more flexible one.
void ImGui::ShowFontSelector(const char* label)