mirror of
https://github.com/ocornut/imgui.git
synced 2025-09-07 11:58:22 +00:00
Fonts: removed size rounding in AddFont() which breaks relative sizing of merged fonts (8502)
# Conflicts: # imgui.cpp
This commit is contained in:
@@ -8628,7 +8628,12 @@ void ImGui::UpdateCurrentFontSize()
|
|||||||
final_size *= g.Font->Scale;
|
final_size *= g.Font->Scale;
|
||||||
if (ImGuiWindow* window = g.CurrentWindow)
|
if (ImGuiWindow* window = g.CurrentWindow)
|
||||||
final_size *= window->FontWindowScale;
|
final_size *= window->FontWindowScale;
|
||||||
final_size = ImMax(1.0f, IM_ROUND(final_size));
|
|
||||||
|
// Round font size
|
||||||
|
// - We started rounding in 1.90 WIP (18991) as our layout system currently doesn't support non-rounded font size well yet.
|
||||||
|
// - We may support it better later and remove this rounding.
|
||||||
|
final_size = GetRoundedFontSize(final_size);
|
||||||
|
final_size = ImMax(1.0f, final_size);
|
||||||
|
|
||||||
g.FontSize = final_size;
|
g.FontSize = final_size;
|
||||||
g.FontBaked = (g.Font != NULL) ? g.Font->GetFontBaked(g.FontSize) : NULL;
|
g.FontBaked = (g.Font != NULL) ? g.Font->GetFontBaked(g.FontSize) : NULL;
|
||||||
|
@@ -3024,6 +3024,7 @@ ImFont* ImFontAtlas::AddFont(const ImFontConfig* font_cfg)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Sanity check
|
// Sanity check
|
||||||
|
// We don't round cfg.SizePixels yet as relative size of merged fonts are used afterwards.
|
||||||
if (font_cfg->GlyphExcludeRanges != NULL)
|
if (font_cfg->GlyphExcludeRanges != NULL)
|
||||||
{
|
{
|
||||||
int size = 0;
|
int size = 0;
|
||||||
@@ -3039,12 +3040,6 @@ ImFont* ImFontAtlas::AddFont(const ImFontConfig* font_cfg)
|
|||||||
}
|
}
|
||||||
IM_ASSERT(font_cfg->FontLoaderData == NULL);
|
IM_ASSERT(font_cfg->FontLoaderData == NULL);
|
||||||
|
|
||||||
// Round font size
|
|
||||||
// - We started rounding in 1.90 WIP (18991) as our layout system currently doesn't support non-rounded font size well yet.
|
|
||||||
// - Note that using io.FontGlobalScale or SetWindowFontScale(), with are legacy-ish, partially supported features, can still lead to unrounded sizes.
|
|
||||||
// - We may support it better later and remove this rounding.
|
|
||||||
new_font_cfg.SizePixels = ImTrunc(new_font_cfg.SizePixels);
|
|
||||||
|
|
||||||
// Pointers to Sources are otherwise dangling
|
// Pointers to Sources are otherwise dangling
|
||||||
ImFontAtlasBuildUpdatePointers(this);
|
ImFontAtlasBuildUpdatePointers(this);
|
||||||
if (!ImFontAtlasBuildAddFont(this, &new_font_cfg))
|
if (!ImFontAtlasBuildAddFont(this, &new_font_cfg))
|
||||||
@@ -5164,6 +5159,11 @@ ImGuiID ImFontAtlasBakedGetId(ImGuiID font_id, float baked_size)
|
|||||||
ImFontBaked* ImFont::GetFontBaked(float size)
|
ImFontBaked* ImFont::GetFontBaked(float size)
|
||||||
{
|
{
|
||||||
ImFontBaked* baked = LastBaked;
|
ImFontBaked* baked = LastBaked;
|
||||||
|
|
||||||
|
// Round font size
|
||||||
|
// - ImGui::PushFontSize() will already round, but other paths calling GetFontBaked() directly also needs it (e.g. ImFontAtlasBuildPreloadAllGlyphRanges)
|
||||||
|
size = ImGui::GetRoundedFontSize(size);
|
||||||
|
|
||||||
if (baked && baked->Size == size)
|
if (baked && baked->Size == size)
|
||||||
return baked;
|
return baked;
|
||||||
|
|
||||||
|
@@ -3111,6 +3111,7 @@ namespace ImGui
|
|||||||
// Fonts, drawing
|
// Fonts, drawing
|
||||||
IMGUI_API void SetCurrentFont(ImFont* font, float font_size);
|
IMGUI_API void SetCurrentFont(ImFont* font, float font_size);
|
||||||
IMGUI_API void UpdateCurrentFontSize();
|
IMGUI_API void UpdateCurrentFontSize();
|
||||||
|
inline float GetRoundedFontSize(float size) { return IM_ROUND(size); }
|
||||||
inline ImFont* GetDefaultFont() { ImGuiContext& g = *GImGui; return g.IO.FontDefault ? g.IO.FontDefault : g.IO.Fonts->Fonts[0]; }
|
inline ImFont* GetDefaultFont() { ImGuiContext& g = *GImGui; return g.IO.FontDefault ? g.IO.FontDefault : g.IO.Fonts->Fonts[0]; }
|
||||||
IMGUI_API void PushPasswordFont();
|
IMGUI_API void PushPasswordFont();
|
||||||
IMGUI_API void PopPasswordFont();
|
IMGUI_API void PopPasswordFont();
|
||||||
|
Reference in New Issue
Block a user