From f270d6c52cdd4ce2dac1c6a52b49966a93f1b6a0 Mon Sep 17 00:00:00 2001 From: omar Date: Fri, 13 Apr 2018 16:21:34 +0200 Subject: [PATCH] Viewport: Fix to allow changing/animated window name to be reflected in the OS e.g. task bar, so named documents can appear properly. (#1542) --- imgui.cpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index aded38a8..e32fb60a 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -3596,15 +3596,15 @@ void ImGui::UpdatePlatformWindows() // Update title bar const char* title_begin = viewport->Window->Name; - const char* title_end = ImGui::FindRenderedTextEnd(title_begin); + char* title_end = (char*)ImGui::FindRenderedTextEnd(title_begin); const ImGuiID title_hash = ImHash(title_begin, (int)(title_end - title_begin)); if (viewport->LastNameHash != title_hash) { viewport->LastNameHash = title_hash; - char* title_displayed = ImStrdup(viewport->Window->Name); - title_displayed[title_end - title_begin] = 0; - g.PlatformIO.Platform_SetWindowTitle(viewport, title_displayed); - ImGui::MemFree(title_displayed); + char title_end_backup_c = *title_end; + *title_end = 0; // Cut existing buffer short instead of doing an alloc/free + g.PlatformIO.Platform_SetWindowTitle(viewport, title_begin); + *title_end = title_end_backup_c; } // Update alpha @@ -6422,6 +6422,13 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) window = CreateNewWindow(name, size_on_first_use, flags); } + // Update name when it changes (which can only happen with the "###" operator), but only if it is meant to be displayed to the end user, else there is no point. + if (!window_just_created && window->Viewport && window->Viewport->Window == window && strcmp(name, window->Name) != 0) + { + IM_DELETE(window->Name); + window->Name = ImStrdup(name); + } + // Automatically disable manual moving/resizing when NoInputs is set if (flags & ImGuiWindowFlags_NoInputs) flags |= ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize;