imgui
imgui copied to clipboard
Font scale in PushFont
Attempt to solve issue #1018
PushFont
api change from void PushFont(ImFont* font);
to void PushFont(ImFont* font, float scale = 1.0f);
, to allow additional scale for each font scope.
In my case this change is valuable to simpler implementation of font resize after dpi change or user request without rebuilding font textures (using only couple of sizes built on loading).
Simple demo panel:
Code:
void fonts_demo_node(ImFont* font, float scale=1.0f)
{
ImGui::PushFont(font, scale);
ImGui::Text("Font scale: %f", scale);
if (ImGui::TreeNode("smaller node"))
{
fonts_demo_node(font, scale * 0.9f);
ImGui::TreePop();
}
if (ImGui::TreeNode("bigger node"))
{
fonts_demo_node(font, scale * 1.1f);
ImGui::TreePop();
}
ImGui::PopFont();
}
void font_demo_panel(bool* p_open)
{
if (!p_open || *p_open)
{
ImGui::Begin("Font Resize Demo", p_open);
fonts_demo_node(ImGui::GetFont());
ImGui::End();
}
}
Visual (in examples/example_win32_directx11 project):
Thanks for the PR. Would need to think about this, but one thing you can do already is to merge the two vectors into one and add a struct e.g. ImGuiFontMod.