mirror of
https://github.com/ocornut/imgui.git
synced 2024-11-25 00:00:40 +01:00
Examples: displaying more font information.
This commit is contained in:
parent
faec745438
commit
fc6545830b
26
imgui.cpp
26
imgui.cpp
@ -11165,25 +11165,35 @@ void ImGui::ShowTestWindow(bool* opened)
|
||||
if (ImGui::TreeNode("Fonts", "Fonts (%d)", ImGui::GetIO().Fonts->Fonts.Size))
|
||||
{
|
||||
ImGui::TextWrapped("Tip: Load fonts with GetIO().Fonts->AddFontFromFileTTF().");
|
||||
for (int i = 0; i < ImGui::GetIO().Fonts->Fonts.Size; i++)
|
||||
ImFontAtlas* atlas = ImGui::GetIO().Fonts;
|
||||
if (ImGui::TreeNode("Atlas texture"))
|
||||
{
|
||||
ImFont* font = ImGui::GetIO().Fonts->Fonts[i];
|
||||
ImGui::Image(atlas->TexID, ImVec2((float)atlas->TexWidth, (float)atlas->TexHeight), ImVec2(0,0), ImVec2(1,1), ImColor(255,255,255,255), ImColor(255,255,255,128));
|
||||
ImGui::TreePop();
|
||||
}
|
||||
ImGui::PushItemWidth(100);
|
||||
for (int i = 0; i < atlas->Fonts.Size; i++)
|
||||
{
|
||||
ImFont* font = atlas->Fonts[i];
|
||||
ImGui::BulletText("Font %d: %.2f pixels, %d glyphs", i, font->FontSize, font->Glyphs.Size);
|
||||
ImGui::TreePush((void*)i);
|
||||
if (i > 0) { ImGui::SameLine(); if (ImGui::SmallButton("Set as default")) { atlas->Fonts[i] = atlas->Fonts[0]; atlas->Fonts[0] = font; } }
|
||||
ImGui::PushFont(font);
|
||||
ImGui::Text("The quick brown fox jumps over the lazy dog");
|
||||
ImGui::PopFont();
|
||||
if (i > 0 && ImGui::Button("Set as default"))
|
||||
if (ImGui::TreeNode("Details"))
|
||||
{
|
||||
ImGui::GetIO().Fonts->Fonts[i] = ImGui::GetIO().Fonts->Fonts[0];
|
||||
ImGui::GetIO().Fonts->Fonts[0] = font;
|
||||
ImGui::DragFloat("font scale", &font->Scale, 0.005f, 0.3f, 2.0f, "%.1f"); // scale only this font
|
||||
ImGui::Text("Ascent: %f, Descent: %f", font->Ascent, font->Descent);
|
||||
ImGui::Text("Fallback character: '%c' (%d)", font->FallbackChar, font->FallbackChar);
|
||||
ImGui::TreePop();
|
||||
}
|
||||
ImGui::SliderFloat("font scale", &font->Scale, 0.3f, 2.0f, "%.1f"); // scale only this font
|
||||
ImGui::TreePop();
|
||||
}
|
||||
static float window_scale = 1.0f;
|
||||
ImGui::SliderFloat("this window scale", &window_scale, 0.3f, 2.0f, "%.1f"); // scale only this window
|
||||
ImGui::SliderFloat("global scale", &ImGui::GetIO().FontGlobalScale, 0.3f, 2.0f, "%.1f"); // scale everything
|
||||
ImGui::DragFloat("this window scale", &window_scale, 0.005f, 0.3f, 2.0f, "%.1f"); // scale only this window
|
||||
ImGui::DragFloat("global scale", &ImGui::GetIO().FontGlobalScale, 0.005f, 0.3f, 2.0f, "%.1f"); // scale everything
|
||||
ImGui::PopItemWidth();
|
||||
ImGui::SetWindowFontScale(window_scale);
|
||||
ImGui::TreePop();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user