|
|
|
@ -54,7 +54,6 @@ Index of this file: |
|
|
|
|
// - sub section: ShowDemoWindowTables()
|
|
|
|
|
// - sub section: ShowDemoWindowMisc()
|
|
|
|
|
// [SECTION] About Window / ShowAboutWindow()
|
|
|
|
|
// [SECTION] Font Viewer / ShowFontAtlas()
|
|
|
|
|
// [SECTION] Style Editor / ShowStyleEditor()
|
|
|
|
|
// [SECTION] Example App: Main Menu Bar / ShowExampleAppMainMenuBar()
|
|
|
|
|
// [SECTION] Example App: Debug Console / ShowExampleAppConsole()
|
|
|
|
@ -5744,15 +5743,15 @@ void ImGui::ShowAboutWindow(bool* p_open) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
// [SECTION] Font viewer / ShowFontAtlas()
|
|
|
|
|
// [SECTION] Style Editor / ShowStyleEditor()
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
// - ShowFontSelector()
|
|
|
|
|
// - ShowFont()
|
|
|
|
|
// - ShowFontAtlas()
|
|
|
|
|
// - ShowStyleSelector()
|
|
|
|
|
// - ShowStyleEditor()
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
// This isn't worth putting in public API but we want Metrics to use it
|
|
|
|
|
namespace ImGui { void ShowFontAtlas(ImFontAtlas* atlas); } |
|
|
|
|
// 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 more the more flexible one.
|
|
|
|
@ -5780,124 +5779,6 @@ void ImGui::ShowFontSelector(const char* label) |
|
|
|
|
"- If you need to add/remove fonts at runtime (e.g. for DPI change), do it before calling NewFrame()."); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// [Internal] Display details for a single font, called by ShowStyleEditor().
|
|
|
|
|
static void ShowFont(ImFont* font) |
|
|
|
|
{ |
|
|
|
|
ImGuiIO& io = ImGui::GetIO(); |
|
|
|
|
ImGuiStyle& style = ImGui::GetStyle(); |
|
|
|
|
bool font_details_opened = ImGui::TreeNode(font, "Font: \"%s\"\n%.2f px, %d glyphs, %d file(s)", |
|
|
|
|
font->ConfigData ? font->ConfigData[0].Name : "", font->FontSize, font->Glyphs.Size, font->ConfigDataCount); |
|
|
|
|
ImGui::SameLine(); if (ImGui::SmallButton("Set as default")) { io.FontDefault = font; } |
|
|
|
|
if (!font_details_opened) |
|
|
|
|
return; |
|
|
|
|
|
|
|
|
|
// Display preview text
|
|
|
|
|
ImGui::PushFont(font); |
|
|
|
|
ImGui::Text("The quick brown fox jumps over the lazy dog"); |
|
|
|
|
ImGui::PopFont(); |
|
|
|
|
|
|
|
|
|
// Display details
|
|
|
|
|
ImGui::SetNextItemWidth(ImGui::GetFontSize() * 8); |
|
|
|
|
ImGui::DragFloat("Font scale", &font->Scale, 0.005f, 0.3f, 2.0f, "%.1f"); // Scale only this font
|
|
|
|
|
ImGui::SameLine(); HelpMarker( |
|
|
|
|
"Note than the default embedded font is NOT meant to be scaled.\n\n" |
|
|
|
|
"Font are currently rendered into bitmaps at a given size at the time of building the atlas. " |
|
|
|
|
"You may oversample them to get some flexibility with scaling. " |
|
|
|
|
"You can also render at multiple sizes and select which one to use at runtime.\n\n" |
|
|
|
|
"(Glimmer of hope: the atlas system will be rewritten in the future to make scaling more flexible.)"); |
|
|
|
|
ImGui::Text("Ascent: %f, Descent: %f, Height: %f", font->Ascent, font->Descent, font->Ascent - font->Descent); |
|
|
|
|
ImGui::Text("Fallback character: '%c' (U+%04X)", font->FallbackChar, font->FallbackChar); |
|
|
|
|
ImGui::Text("Ellipsis character: '%c' (U+%04X)", font->EllipsisChar, font->EllipsisChar); |
|
|
|
|
const int surface_sqrt = (int)sqrtf((float)font->MetricsTotalSurface); |
|
|
|
|
ImGui::Text("Texture Area: about %d px ~%dx%d px", font->MetricsTotalSurface, surface_sqrt, surface_sqrt); |
|
|
|
|
for (int config_i = 0; config_i < font->ConfigDataCount; config_i++) |
|
|
|
|
if (font->ConfigData) |
|
|
|
|
if (const ImFontConfig* cfg = &font->ConfigData[config_i]) |
|
|
|
|
ImGui::BulletText("Input %d: \'%s\', Oversample: (%d,%d), PixelSnapH: %d, Offset: (%.1f,%.1f)", |
|
|
|
|
config_i, cfg->Name, cfg->OversampleH, cfg->OversampleV, cfg->PixelSnapH, cfg->GlyphOffset.x, cfg->GlyphOffset.y); |
|
|
|
|
|
|
|
|
|
// Display all glyphs of the fonts in separate pages of 256 characters
|
|
|
|
|
if (ImGui::TreeNode("Glyphs", "Glyphs (%d)", font->Glyphs.Size)) |
|
|
|
|
{ |
|
|
|
|
const ImU32 glyph_col = ImGui::GetColorU32(ImGuiCol_Text); |
|
|
|
|
for (unsigned int base = 0; base <= IM_UNICODE_CODEPOINT_MAX; base += 256) |
|
|
|
|
{ |
|
|
|
|
// Skip ahead if a large bunch of glyphs are not present in the font (test in chunks of 4k)
|
|
|
|
|
// This is only a small optimization to reduce the number of iterations when IM_UNICODE_MAX_CODEPOINT
|
|
|
|
|
// is large // (if ImWchar==ImWchar32 we will do at least about 272 queries here)
|
|
|
|
|
if (!(base & 4095) && font->IsGlyphRangeUnused(base, base + 4095)) |
|
|
|
|
{ |
|
|
|
|
base += 4096 - 256; |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
int count = 0; |
|
|
|
|
for (unsigned int n = 0; n < 256; n++) |
|
|
|
|
if (font->FindGlyphNoFallback((ImWchar)(base + n))) |
|
|
|
|
count++; |
|
|
|
|
if (count <= 0) |
|
|
|
|
continue; |
|
|
|
|
if (!ImGui::TreeNode((void*)(intptr_t)base, "U+%04X..U+%04X (%d %s)", base, base + 255, count, count > 1 ? "glyphs" : "glyph")) |
|
|
|
|
continue; |
|
|
|
|
float cell_size = font->FontSize * 1; |
|
|
|
|
float cell_spacing = style.ItemSpacing.y; |
|
|
|
|
ImVec2 base_pos = ImGui::GetCursorScreenPos(); |
|
|
|
|
ImDrawList* draw_list = ImGui::GetWindowDrawList(); |
|
|
|
|
for (unsigned int n = 0; n < 256; n++) |
|
|
|
|
{ |
|
|
|
|
// We use ImFont::RenderChar as a shortcut because we don't have UTF-8 conversion functions
|
|
|
|
|
// available here and thus cannot easily generate a zero-terminated UTF-8 encoded string.
|
|
|
|
|
ImVec2 cell_p1(base_pos.x + (n % 16) * (cell_size + cell_spacing), base_pos.y + (n / 16) * (cell_size + cell_spacing)); |
|
|
|
|
ImVec2 cell_p2(cell_p1.x + cell_size, cell_p1.y + cell_size); |
|
|
|
|
const ImFontGlyph* glyph = font->FindGlyphNoFallback((ImWchar)(base + n)); |
|
|
|
|
draw_list->AddRect(cell_p1, cell_p2, glyph ? IM_COL32(255, 255, 255, 100) : IM_COL32(255, 255, 255, 50)); |
|
|
|
|
if (glyph) |
|
|
|
|
font->RenderChar(draw_list, cell_size, cell_p1, glyph_col, (ImWchar)(base + n)); |
|
|
|
|
if (glyph && ImGui::IsMouseHoveringRect(cell_p1, cell_p2)) |
|
|
|
|
{ |
|
|
|
|
ImGui::BeginTooltip(); |
|
|
|
|
ImGui::Text("Codepoint: U+%04X", base + n); |
|
|
|
|
ImGui::Separator(); |
|
|
|
|
ImGui::Text("Visible: %d", glyph->Visible); |
|
|
|
|
ImGui::Text("AdvanceX: %.1f", glyph->AdvanceX); |
|
|
|
|
ImGui::Text("Pos: (%.2f,%.2f)->(%.2f,%.2f)", glyph->X0, glyph->Y0, glyph->X1, glyph->Y1); |
|
|
|
|
ImGui::Text("UV: (%.3f,%.3f)->(%.3f,%.3f)", glyph->U0, glyph->V0, glyph->U1, glyph->V1); |
|
|
|
|
ImGui::EndTooltip(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
ImGui::Dummy(ImVec2((cell_size + cell_spacing) * 16, (cell_size + cell_spacing) * 16)); |
|
|
|
|
ImGui::TreePop(); |
|
|
|
|
} |
|
|
|
|
ImGui::TreePop(); |
|
|
|
|
} |
|
|
|
|
ImGui::TreePop(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void ImGui::ShowFontAtlas(ImFontAtlas* atlas) |
|
|
|
|
{ |
|
|
|
|
for (int i = 0; i < atlas->Fonts.Size; i++) |
|
|
|
|
{ |
|
|
|
|
ImFont* font = atlas->Fonts[i]; |
|
|
|
|
ImGui::PushID(font); |
|
|
|
|
ShowFont(font); |
|
|
|
|
ImGui::PopID(); |
|
|
|
|
} |
|
|
|
|
if (ImGui::TreeNode("Atlas texture", "Atlas texture (%dx%d pixels)", atlas->TexWidth, atlas->TexHeight)) |
|
|
|
|
{ |
|
|
|
|
ImVec4 tint_col = ImVec4(1.0f, 1.0f, 1.0f, 1.0f); |
|
|
|
|
ImVec4 border_col = ImVec4(1.0f, 1.0f, 1.0f, 0.5f); |
|
|
|
|
ImGui::Image(atlas->TexID, ImVec2((float)atlas->TexWidth, (float)atlas->TexHeight), ImVec2(0, 0), ImVec2(1, 1), tint_col, border_col); |
|
|
|
|
ImGui::TreePop(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
// [SECTION] Style Editor / ShowStyleEditor()
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
// - ShowStyleSelector()
|
|
|
|
|
// - ShowStyleEditor()
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
// Demo helper function to select among default colors. See ShowStyleEditor() for more advanced options.
|
|
|
|
|
// Here we use the simplified Combo() api that packs items into a single literal string.
|
|
|
|
|
// Useful for quick combo boxes where the choices are known locally.
|
|
|
|
|