From c38526d14b38eff269032ac2b00a748ee16964c6 Mon Sep 17 00:00:00 2001 From: Anthony Pesch Date: Sun, 1 Oct 2017 23:40:29 -0400 Subject: [PATCH 1/3] Completely clear font when rebuilding atlas. Previously, IndexLookup was not cleared on each font, causing FindGlyph to return old glyphs when using MergeMode. --- imgui_draw.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/imgui_draw.cpp b/imgui_draw.cpp index 73647689..b45cc1ff 100644 --- a/imgui_draw.cpp +++ b/imgui_draw.cpp @@ -1540,7 +1540,6 @@ bool ImFontAtlasBuildWithStbTruetype(ImFontAtlas* atlas) const float off_x = cfg.GlyphOffset.x; const float off_y = cfg.GlyphOffset.y + (float)(int)(dst_font->Ascent + 0.5f); - dst_font->FallbackGlyph = NULL; // Always clear fallback so FindGlyph can return NULL. It will be set again in BuildLookupTable() for (int i = 0; i < tmp.RangesCount; i++) { stbtt_pack_range& range = tmp.Ranges[i]; @@ -1582,14 +1581,16 @@ void ImFontAtlasBuildSetupFont(ImFontAtlas* atlas, ImFont* font, ImFontConfig* f { if (!font_config->MergeMode) { - font->ContainerAtlas = atlas; - font->ConfigData = font_config; - font->ConfigDataCount = 0; + ImVec2 display_offset = font->DisplayOffset; + + font->Clear(); + font->FontSize = font_config->SizePixels; + font->DisplayOffset = display_offset; + font->ConfigData = font_config; + font->ContainerAtlas = atlas; font->Ascent = ascent; font->Descent = descent; - font->Glyphs.resize(0); - font->MetricsTotalSurface = 0; } font->ConfigDataCount++; } From fce41d0b5569ceaf9e7901a013efc68980d57662 Mon Sep 17 00:00:00 2001 From: omar Date: Sun, 22 Oct 2017 10:21:49 +0200 Subject: [PATCH 2/3] Demo: Fixed Fonts "set as default button" not having collading id on collapsed nodes. --- imgui_demo.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/imgui_demo.cpp b/imgui_demo.cpp index 404dcbdb..35ee618b 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -1951,6 +1951,7 @@ void ImGui::ShowStyleEditor(ImGuiStyle* ref) for (int i = 0; i < atlas->Fonts.Size; i++) { ImFont* font = atlas->Fonts[i]; + ImGui::PushID(font); bool font_details_opened = ImGui::TreeNode(font, "Font %d: \'%s\', %.2f px, %d glyphs", i, font->ConfigData ? font->ConfigData[0].Name : "", font->FontSize, font->Glyphs.Size); ImGui::SameLine(); if (ImGui::SmallButton("Set as default")) ImGui::GetIO().FontDefault = font; if (font_details_opened) @@ -2011,6 +2012,7 @@ void ImGui::ShowStyleEditor(ImGuiStyle* ref) } ImGui::TreePop(); } + ImGui::PopID(); } static float window_scale = 1.0f; ImGui::DragFloat("this window scale", &window_scale, 0.005f, 0.3f, 2.0f, "%.1f"); // scale only this window From 7f880674e5c3e594ac034215252b7d1455a1579f Mon Sep 17 00:00:00 2001 From: omar Date: Sun, 22 Oct 2017 10:24:56 +0200 Subject: [PATCH 3/3] Font: Renamed ImFont::Clear() to ImFont::ClearOutputData() for consistency with what ImFontAtlas does. DisplayOffset is set by constructor but not reset by ClearOutputData. (#1349) --- imgui.h | 2 +- imgui_draw.cpp | 14 +++++--------- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/imgui.h b/imgui.h index e281b4f1..c865d357 100644 --- a/imgui.h +++ b/imgui.h @@ -1500,7 +1500,7 @@ struct ImFont // Methods IMGUI_API ImFont(); IMGUI_API ~ImFont(); - IMGUI_API void Clear(); + IMGUI_API void ClearOutputData(); IMGUI_API void BuildLookupTable(); IMGUI_API const ImFontGlyph*FindGlyph(ImWchar c) const; IMGUI_API void SetFallbackChar(ImWchar c); diff --git a/imgui_draw.cpp b/imgui_draw.cpp index 302c338b..c3a5f3d5 100644 --- a/imgui_draw.cpp +++ b/imgui_draw.cpp @@ -1618,12 +1618,8 @@ void ImFontAtlasBuildSetupFont(ImFontAtlas* atlas, ImFont* font, ImFontConfig* f { if (!font_config->MergeMode) { - ImVec2 display_offset = font->DisplayOffset; - - font->Clear(); - + font->ClearOutputData(); font->FontSize = font_config->SizePixels; - font->DisplayOffset = display_offset; font->ConfigData = font_config; font->ContainerAtlas = atlas; font->Ascent = ascent; @@ -1904,7 +1900,8 @@ ImFont::ImFont() { Scale = 1.0f; FallbackChar = (ImWchar)'?'; - Clear(); + DisplayOffset = ImVec2(0.0f, 1.0f); + ClearOutputData(); } ImFont::~ImFont() @@ -1917,13 +1914,12 @@ ImFont::~ImFont() if (g.Font == this) g.Font = NULL; */ - Clear(); + ClearOutputData(); } -void ImFont::Clear() +void ImFont::ClearOutputData() { FontSize = 0.0f; - DisplayOffset = ImVec2(0.0f, 1.0f); Glyphs.clear(); IndexAdvanceX.clear(); IndexLookup.clear();