diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index afc5290dc..82af01649 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -79,17 +79,21 @@ Other Changes: to auto-size on a given axis would keep marking ini settings as dirty. - Disabled: fixed a bug when a previously enabled item that got nav focus and then turns disabled could still be activated using keyboard. (#9036) -- InputText: when buffer is not resizable, trying to paste contents that - cannot fit will now truncate text to nearest UTF-8 codepoint boundaries, - instead of completely ignoring the paste. (#9029) -- InputText: avoid continuously overwriting ownership of ImGuiKey_Enter/_KeypadEnter - keys in order to allow e.g. external Shortcut override behavior. (#9004) -- InputText: when using a callback to reduce/manipulate the value of BufTextLen, - we do not require anymore that CursorPos be clamped by user code. (#9029) -- InputTextMultiline: fixed a crash when using ImGuiInputTextFlags_WordWrap and - resizing the parent window while keeping the multi-line field active (which is - most typically achieved when resizing programmatically or via a docking layout - reacting to a platform window resize). (#3237, #9007) [@anton-kl, @ocornut] +- InputText: + - When buffer is not resizable, trying to paste contents that cannot + fit will now truncate text to nearest UTF-8 codepoint boundaries, + instead of completely ignoring the paste. (#9029) + - Avoid continuously overwriting ownership of ImGuiKey_Enter/_KeypadEnter + keys in order to allow e.g. external Shortcut override behavior. (#9004) + - When using a callback to reduce/manipulate the value of BufTextLen, + we do not require anymore that CursorPos be clamped by user code. (#9029) + - InputTextMultiline: fixed a crash when using ImGuiInputTextFlags_WordWrap and + resizing the parent window while keeping the multi-line field active (which is + most typically achieved when resizing programmatically or via a docking layout + reacting to a platform window resize). (#3237, #9007) [@anton-kl, @ocornut] +- Fonts: + - Calling ImFontAtlas::Clear() mid-frame without re-adding a font will + lead to a more explicit crash. - Textures: - Fixed an issue preventing multi-contexts from using each others' fonts if context 2 runs after context 1's Render() function. (#9039) diff --git a/imgui.h b/imgui.h index ca1b9b6de..a52ec5764 100644 --- a/imgui.h +++ b/imgui.h @@ -3638,7 +3638,7 @@ struct ImFontAtlas IMGUI_API ImFont* AddFontFromMemoryCompressedBase85TTF(const char* compressed_font_data_base85, float size_pixels = 0.0f, const ImFontConfig* font_cfg = NULL, const ImWchar* glyph_ranges = NULL); // 'compressed_font_data_base85' still owned by caller. Compress with binary_to_compressed_c.cpp with -base85 parameter. IMGUI_API void RemoveFont(ImFont* font); - IMGUI_API void Clear(); // Clear everything (input fonts, output glyphs/textures) + IMGUI_API void Clear(); // Clear everything (input fonts, output glyphs/textures). IMGUI_API void CompactCache(); // Compact cached glyphs and texture. IMGUI_API void SetFontLoader(const ImFontLoader* font_loader); // Change font loader at runtime. diff --git a/imgui_draw.cpp b/imgui_draw.cpp index 21ae9e258..7111fb0b9 100644 --- a/imgui_draw.cpp +++ b/imgui_draw.cpp @@ -2656,6 +2656,7 @@ ImFontAtlas::~ImFontAtlas() TexData = NULL; } +// If you call this mid-frame, you would need to add new font and bind them! void ImFontAtlas::Clear() { bool backup_renderer_has_textures = RendererHasTextures; @@ -2706,6 +2707,8 @@ void ImFontAtlas::ClearFonts() { // FIXME-NEWATLAS: Illegal to remove currently bound font. IM_ASSERT(!Locked && "Cannot modify a locked ImFontAtlas!"); + for (ImFont* font : Fonts) + ImFontAtlasBuildNotifySetFont(this, font, NULL); ImFontAtlasBuildDestroy(this); ClearInputData(); Fonts.clear_delete(); @@ -3200,7 +3203,7 @@ ImFont* ImFontAtlas::AddFontFromMemoryCompressedBase85TTF(const char* compressed // On font removal we need to remove references (otherwise we could queue removal?) // We allow old_font == new_font which forces updating all values (e.g. sizes) -static void ImFontAtlasBuildNotifySetFont(ImFontAtlas* atlas, ImFont* old_font, ImFont* new_font) +void ImFontAtlasBuildNotifySetFont(ImFontAtlas* atlas, ImFont* old_font, ImFont* new_font) { for (ImDrawListSharedData* shared_data : atlas->DrawListSharedDatas) { diff --git a/imgui_internal.h b/imgui_internal.h index 091873bf8..2ada86891 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -3856,6 +3856,7 @@ IMGUI_API void ImFontAtlasBuildInit(ImFontAtlas* atlas); IMGUI_API void ImFontAtlasBuildDestroy(ImFontAtlas* atlas); IMGUI_API void ImFontAtlasBuildMain(ImFontAtlas* atlas); IMGUI_API void ImFontAtlasBuildSetupFontLoader(ImFontAtlas* atlas, const ImFontLoader* font_loader); +IMGUI_API void ImFontAtlasBuildNotifySetFont(ImFontAtlas* atlas, ImFont* old_font, ImFont* new_font); IMGUI_API void ImFontAtlasBuildUpdatePointers(ImFontAtlas* atlas); IMGUI_API void ImFontAtlasBuildRenderBitmapFromString(ImFontAtlas* atlas, int x, int y, int w, int h, const char* in_str, char in_marker_char); IMGUI_API void ImFontAtlasBuildClear(ImFontAtlas* atlas); // Clear output and custom rects