Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Windows Binding] Incorrect string coding for sub-viewport window title in Multi-viewport mode #2164

Closed
JX-Master opened this issue Oct 31, 2018 · 1 comment

Comments

@JX-Master
Copy link

Version/Branch of Dear ImGui:

Version v1.66 WIP, Docking branch.

Back-end file/Renderer/OS: (or specify if you are using a custom engine back-end)

Back-ends: imgui_impl_d3d11.cpp + imgui_impl_win32.cpp
OS: Windows 10 (Simplified Chinese)
Compiler: MSVC 2017(v141)

My Issue/Question:

tim 20181031183602

This is a very small issue that can be quickly fixed in no more than 5 minutes (I think :) ).

The problem is that when setting sub-window titles in multi-viewport mode in Windows,
the imgui binding program directly pass UTF-8 string to the system, where multi-byte characters is expected. This leads to incorrect title displaying when the input string is not ANSI C string.

The solution is inImGui_ImplWin32_SetWindowTitle funtion in imgui_impl_win32.cpp file, translate a UTF-8 string to UTF-16 wide char string and pass it to system by using ::SetWindowTextW(data->Hwnd, titlew); call. My solution would be like this:

static void ImGui_ImplWin32_SetWindowTitle(ImGuiViewport* viewport, const char* title)
{
	ImGuiViewportDataWin32* data = (ImGuiViewportDataWin32*)viewport->PlatformUserData;
	IM_ASSERT(data->Hwnd != 0);
	wchar_t titlew[260];
	UTF8ToUTF16(titlew, 260, title);   // Translate UTF-8 string to UTF-16
	::SetWindowTextW(data->Hwnd, titlew);  // And pass it to Windows.
}

Standalone, minimal, complete and verifiable example:

ImGui::Begin(u8"TTS测试");
// Some Stuff Here.
ImGui::End();
@ocornut
Copy link
Owner

ocornut commented Nov 5, 2018

Thank you @JX-Master, I have made a similar fix using Windows MultiByteToWideChar().
I have also confirmed that UTF-8 works as expected in the equivalent GLFW and SDL2 functions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants