From fd943182bd9fe1d801e721a20a41dcde84be39d0 Mon Sep 17 00:00:00 2001 From: Koostosh Date: Tue, 25 Apr 2023 14:22:47 +0200 Subject: [PATCH 01/14] ImVec2: Added unary minus operator (#6368) --- docs/CHANGELOG.txt | 1 + imgui.h | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 8fe22f063..bd6d3e6b7 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -52,6 +52,7 @@ Other changes: erroneously initializing default nav layer to menu layer. - Menus: Fixed an issue when opening a menu hierarchy in a given menu-bar would allow opening another via simple hovering. (#3496, #4797) +- Misc: Added ImVec2 unary minus operator. (#6368) [@Koostosh] - Debug Tools: Debug Log: Fixed not parsing 0xXXXXXXXX values for geo-locating on mouse hover hover when the identifier is at the end of the line. (#5855) - Backends: Clear bits sets io.BackendFlags on backend Shutdown(). (#6334, #6335] [@GereonV] diff --git a/imgui.h b/imgui.h index e8b7e9eb3..a450ffe2a 100644 --- a/imgui.h +++ b/imgui.h @@ -2352,7 +2352,6 @@ struct ImGuiListClipper // - It is important that we are keeping those disabled by default so they don't leak in user space. // - This is in order to allow user enabling implicit cast operators between ImVec2/ImVec4 and their own types (using IM_VEC2_CLASS_EXTRA in imconfig.h) // - You can use '#define IMGUI_DEFINE_MATH_OPERATORS' to import our operators, provided as a courtesy. -// - We unfortunately don't have a unary- operator for ImVec2 because this would needs to be defined inside the class itself. #ifdef IMGUI_DEFINE_MATH_OPERATORS #define IMGUI_DEFINE_MATH_OPERATORS_IMPLEMENTED IM_MSVC_RUNTIME_CHECKS_OFF @@ -2362,6 +2361,7 @@ static inline ImVec2 operator+(const ImVec2& lhs, const ImVec2& rhs) { return static inline ImVec2 operator-(const ImVec2& lhs, const ImVec2& rhs) { return ImVec2(lhs.x - rhs.x, lhs.y - rhs.y); } static inline ImVec2 operator*(const ImVec2& lhs, const ImVec2& rhs) { return ImVec2(lhs.x * rhs.x, lhs.y * rhs.y); } static inline ImVec2 operator/(const ImVec2& lhs, const ImVec2& rhs) { return ImVec2(lhs.x / rhs.x, lhs.y / rhs.y); } +static inline ImVec2 operator-(const ImVec2& lhs) { return ImVec2(-lhs.x, -lhs.y); } static inline ImVec2& operator*=(ImVec2& lhs, const float rhs) { lhs.x *= rhs; lhs.y *= rhs; return lhs; } static inline ImVec2& operator/=(ImVec2& lhs, const float rhs) { lhs.x /= rhs; lhs.y /= rhs; return lhs; } static inline ImVec2& operator+=(ImVec2& lhs, const ImVec2& rhs) { lhs.x += rhs.x; lhs.y += rhs.y; return lhs; } From 15da1a9abca92c876e10e9f60b8fba92ae131c12 Mon Sep 17 00:00:00 2001 From: ocornut Date: Tue, 25 Apr 2023 16:39:02 +0200 Subject: [PATCH 02/14] Fixed misleading local name (#4493) + minor typo (#6369) --- docs/FAQ.md | 2 +- imgui.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/FAQ.md b/docs/FAQ.md index 8dd0c4416..20aa9a732 100644 --- a/docs/FAQ.md +++ b/docs/FAQ.md @@ -557,7 +557,7 @@ backslash \ within a string literal, you need to write it double backslash "\\": ```cpp io.Fonts->AddFontFromFileTTF("MyFolder\MyFont.ttf", size); // WRONG (you are escaping the M here!) -io.Fonts->AddFontFromFileTTF("MyFolder\\MyFont.ttf", size; // CORRECT (Windows only) +io.Fonts->AddFontFromFileTTF("MyFolder\\MyFont.ttf", size); // CORRECT (Windows only) io.Fonts->AddFontFromFileTTF("MyFolder/MyFont.ttf", size); // ALSO CORRECT ``` diff --git a/imgui.cpp b/imgui.cpp index 172bccdeb..2c34b5c20 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -6599,8 +6599,8 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags) // - We disable this when the parent window has zero vertices, which is a common pattern leading to laying out multiple overlapping childs ImGuiWindow* previous_child = parent_window->DC.ChildWindows.Size >= 2 ? parent_window->DC.ChildWindows[parent_window->DC.ChildWindows.Size - 2] : NULL; bool previous_child_overlapping = previous_child ? previous_child->Rect().Overlaps(window->Rect()) : false; - bool parent_is_empty = parent_window->DrawList->VtxBuffer.Size > 0; - if (window->DrawList->CmdBuffer.back().ElemCount == 0 && parent_is_empty && !previous_child_overlapping) + bool parent_is_empty = (parent_window->DrawList->VtxBuffer.Size == 0); + if (window->DrawList->CmdBuffer.back().ElemCount == 0 && !parent_is_empty && !previous_child_overlapping) render_decorations_in_parent = true; } if (render_decorations_in_parent) From 031e152d292b386b7b6149e455924cfc6bab8c7c Mon Sep 17 00:00:00 2001 From: ocornut Date: Thu, 27 Apr 2023 14:57:09 +0200 Subject: [PATCH 03/14] Examples: DX9, DX10, DX11: Queue framebuffer resize instead of processing in WM_SIZE. (#6374) --- docs/CHANGELOG.txt | 2 ++ examples/example_win32_directx10/main.cpp | 20 ++++++++++++++------ examples/example_win32_directx11/main.cpp | 20 ++++++++++++++------ examples/example_win32_directx9/main.cpp | 19 +++++++++++++------ 4 files changed, 43 insertions(+), 18 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index bd6d3e6b7..6917f1dd0 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -64,6 +64,8 @@ Other changes: - Examples: Added native Win32+OpenGL3 example. We don't recommend using this setup but we provide it for completeness. (#3218, #5170, #6086, #2772, #2600, #2359, #2022, #1553) [@learn-more] - Examples: Vulkan: Use integrated GPU if nothing else is available. (#6359) [@kimidaisuki22] +- Examples: DX9, DX10, DX11: Queue framebuffer resize instead of processing in WM_SIZE, + as some drivers tends to only cleanup after existing the native resize modal loop. (#6374) ----------------------------------------------------------------------- diff --git a/examples/example_win32_directx10/main.cpp b/examples/example_win32_directx10/main.cpp index 5211157d3..34e013fa8 100644 --- a/examples/example_win32_directx10/main.cpp +++ b/examples/example_win32_directx10/main.cpp @@ -12,6 +12,7 @@ // Data static ID3D10Device* g_pd3dDevice = nullptr; static IDXGISwapChain* g_pSwapChain = nullptr; +static UINT g_ResizeWidth = 0, g_ResizeHeight = 0; static ID3D10RenderTargetView* g_mainRenderTargetView = nullptr; // Forward declarations of helper functions @@ -95,6 +96,15 @@ int main(int, char**) if (done) break; + // Handle window resize (we don't resize directly in the WM_SIZE handler) + if (g_ResizeWidth != 0 && g_ResizeHeight != 0) + { + CleanupRenderTarget(); + g_pSwapChain->ResizeBuffers(0, g_ResizeWidth, g_ResizeHeight, DXGI_FORMAT_UNKNOWN, 0); + g_ResizeWidth = g_ResizeHeight = 0; + CreateRenderTarget(); + } + // Start the Dear ImGui frame ImGui_ImplDX10_NewFrame(); ImGui_ImplWin32_NewFrame(); @@ -228,12 +238,10 @@ LRESULT WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) switch (msg) { case WM_SIZE: - if (g_pd3dDevice != nullptr && wParam != SIZE_MINIMIZED) - { - CleanupRenderTarget(); - g_pSwapChain->ResizeBuffers(0, (UINT)LOWORD(lParam), (UINT)HIWORD(lParam), DXGI_FORMAT_UNKNOWN, 0); - CreateRenderTarget(); - } + if (wParam == SIZE_MINIMIZED) + return 0; + g_ResizeWidth = (UINT)LOWORD(lParam); // Queue resize + g_ResizeHeight = (UINT)HIWORD(lParam); return 0; case WM_SYSCOMMAND: if ((wParam & 0xfff0) == SC_KEYMENU) // Disable ALT application menu diff --git a/examples/example_win32_directx11/main.cpp b/examples/example_win32_directx11/main.cpp index df6cd06ff..c242a4ccb 100644 --- a/examples/example_win32_directx11/main.cpp +++ b/examples/example_win32_directx11/main.cpp @@ -12,6 +12,7 @@ static ID3D11Device* g_pd3dDevice = nullptr; static ID3D11DeviceContext* g_pd3dDeviceContext = nullptr; static IDXGISwapChain* g_pSwapChain = nullptr; +static UINT g_ResizeWidth = 0, g_ResizeHeight = 0; static ID3D11RenderTargetView* g_mainRenderTargetView = nullptr; // Forward declarations of helper functions @@ -95,6 +96,15 @@ int main(int, char**) if (done) break; + // Handle window resize (we don't resize directly in the WM_SIZE handler) + if (g_ResizeWidth != 0 && g_ResizeHeight != 0) + { + CleanupRenderTarget(); + g_pSwapChain->ResizeBuffers(0, g_ResizeWidth, g_ResizeHeight, DXGI_FORMAT_UNKNOWN, 0); + g_ResizeWidth = g_ResizeHeight = 0; + CreateRenderTarget(); + } + // Start the Dear ImGui frame ImGui_ImplDX11_NewFrame(); ImGui_ImplWin32_NewFrame(); @@ -232,12 +242,10 @@ LRESULT WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) switch (msg) { case WM_SIZE: - if (g_pd3dDevice != nullptr && wParam != SIZE_MINIMIZED) - { - CleanupRenderTarget(); - g_pSwapChain->ResizeBuffers(0, (UINT)LOWORD(lParam), (UINT)HIWORD(lParam), DXGI_FORMAT_UNKNOWN, 0); - CreateRenderTarget(); - } + if (wParam == SIZE_MINIMIZED) + return 0; + g_ResizeWidth = (UINT)LOWORD(lParam); // Queue resize + g_ResizeHeight = (UINT)HIWORD(lParam); return 0; case WM_SYSCOMMAND: if ((wParam & 0xfff0) == SC_KEYMENU) // Disable ALT application menu diff --git a/examples/example_win32_directx9/main.cpp b/examples/example_win32_directx9/main.cpp index fa5190d98..85aadd278 100644 --- a/examples/example_win32_directx9/main.cpp +++ b/examples/example_win32_directx9/main.cpp @@ -11,6 +11,7 @@ // Data static LPDIRECT3D9 g_pD3D = nullptr; static LPDIRECT3DDEVICE9 g_pd3dDevice = nullptr; +static UINT g_ResizeWidth = 0, g_ResizeHeight = 0; static D3DPRESENT_PARAMETERS g_d3dpp = {}; // Forward declarations of helper functions @@ -93,6 +94,14 @@ int main(int, char**) if (done) break; + // Handle window resize (we don't resize directly in the WM_SIZE handler) + if (g_ResizeWidth != 0 && g_ResizeHeight != 0) + { + g_d3dpp.BackBufferWidth = g_ResizeWidth; + g_d3dpp.BackBufferHeight = g_ResizeHeight; + ResetDevice(); + } + // Start the Dear ImGui frame ImGui_ImplDX9_NewFrame(); ImGui_ImplWin32_NewFrame(); @@ -219,12 +228,10 @@ LRESULT WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) switch (msg) { case WM_SIZE: - if (g_pd3dDevice != nullptr && wParam != SIZE_MINIMIZED) - { - g_d3dpp.BackBufferWidth = LOWORD(lParam); - g_d3dpp.BackBufferHeight = HIWORD(lParam); - ResetDevice(); - } + if (wParam == SIZE_MINIMIZED) + return 0; + g_ResizeWidth = (UINT)LOWORD(lParam); // Queue resize + g_ResizeHeight = (UINT)HIWORD(lParam); return 0; case WM_SYSCOMMAND: if ((wParam & 0xfff0) == SC_KEYMENU) // Disable ALT application menu From 085fa42b7df25cff3030a8c58547bb6c95d284f5 Mon Sep 17 00:00:00 2001 From: cfillion Date: Thu, 27 Apr 2023 19:15:48 +0200 Subject: [PATCH 04/14] Adedd workaround for GCC erroneous/zealous warning (#5343) --- imgui_draw.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/imgui_draw.cpp b/imgui_draw.cpp index 313bc0f3e..b76f876d2 100644 --- a/imgui_draw.cpp +++ b/imgui_draw.cpp @@ -2623,6 +2623,9 @@ void ImFontAtlasBuildPackCustomRects(ImFontAtlas* atlas, void* stbrp_context_opa ImVector& user_rects = atlas->CustomRects; IM_ASSERT(user_rects.Size >= 1); // We expect at least the default custom rects to be registered, else something went wrong. +#ifdef __GNUC__ + if (user_rects.Size < 1) { __builtin_unreachable(); } // Workaround for GCC bug if IM_ASSERT() is defined to conditionally throw (see #5343) +#endif ImVector pack_rects; pack_rects.resize(user_rects.Size); From 7c291ba31b3ad0651ad6341bf08d3bb9eeae2453 Mon Sep 17 00:00:00 2001 From: ocornut Date: Fri, 28 Apr 2023 13:58:59 +0200 Subject: [PATCH 05/14] Tables: Fixed command merging when compiling with VS2013. (#6377) --- docs/CHANGELOG.txt | 2 ++ imgui_tables.cpp | 6 +++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 6917f1dd0..3411485d2 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -44,6 +44,8 @@ Other changes: - Tables: Fixed a small miscalculation in TableHeader() leading to an empty tooltip showing when a sorting column has no visible name. (#6342) [@lukaasm] +- Tables: Fixed command merging when compiling with VS2013 (one array on stack was not + initialized on VS2013. Unsure if due to a bug or UB/standard conformance). (#6377) - InputText: Avoid setting io.WantTextInputNextFrame during the deactivation frame. (#6341) [@lukaasm] - Nav: Fixed navigation within tables/columns where item boundaries goes beyond columns limits, diff --git a/imgui_tables.cpp b/imgui_tables.cpp index ea0367416..7ff5d643c 100644 --- a/imgui_tables.cpp +++ b/imgui_tables.cpp @@ -2383,11 +2383,11 @@ void ImGui::TableMergeDrawChannels(ImGuiTable* table) struct MergeGroup { ImRect ClipRect; - int ChannelsCount; - ImBitArrayPtr ChannelsMask; + int ChannelsCount = 0; + ImBitArrayPtr ChannelsMask = NULL; }; int merge_group_mask = 0x00; - MergeGroup merge_groups[4] = {}; + MergeGroup merge_groups[4]; // Use a reusable temp buffer for the merge masks as they are dynamically sized. const int max_draw_channels = (4 + table->ColumnsCount * 2); From 5dc60137139cb9a8b70adc192fcc3549874dc17b Mon Sep 17 00:00:00 2001 From: ocornut Date: Thu, 4 May 2023 17:06:36 +0200 Subject: [PATCH 06/14] Backends: SDL3: Fixed build on Emscripten/iOS/Android. (#6391) --- backends/imgui_impl_sdl3.cpp | 2 ++ docs/CHANGELOG.txt | 1 + 2 files changed, 3 insertions(+) diff --git a/backends/imgui_impl_sdl3.cpp b/backends/imgui_impl_sdl3.cpp index 5b0c82d95..4427f2c84 100644 --- a/backends/imgui_impl_sdl3.cpp +++ b/backends/imgui_impl_sdl3.cpp @@ -19,6 +19,7 @@ // CHANGELOG // (minor and older changes stripped away, please see git history for details) +// 2023-05-04: Fixed build on Emscripten/iOS/Android. (#6391) // 2023-04-06: Inputs: Avoid calling SDL_StartTextInput()/SDL_StopTextInput() as they don't only pertain to IME. It's unclear exactly what their relation is to IME. (#6306) // 2023-04-04: Inputs: Added support for io.AddMouseSourceEvent() to discriminate ImGuiMouseSource_Mouse/ImGuiMouseSource_TouchScreen. (#2702) // 2023-02-23: Accept SDL_GetPerformanceCounter() not returning a monotonically increasing value. (#6189, #6114, #3644) @@ -441,6 +442,7 @@ static void ImGui_ImplSDL3_UpdateMouseData() SDL_Window* focused_window = SDL_GetKeyboardFocus(); const bool is_app_focused = (bd->Window == focused_window); #else + SDL_Window* focused_window = bd->Window; const bool is_app_focused = (SDL_GetWindowFlags(bd->Window) & SDL_WINDOW_INPUT_FOCUS) != 0; // SDL 2.0.3 and non-windowed systems: single-viewport only #endif if (is_app_focused) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 3411485d2..ba15f8434 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -63,6 +63,7 @@ Other changes: Win32/Winapi with OpenGL. (#3218) - Backends: OpenGL3: Restore front and back polygon mode separately when supported by context (Desktop 3.0, 3.1, or 3.2+ with compat bit). (#6333) [@GereonV] +- Backends: SDL3: Fixed build on Emscripten/iOS/Android. (#6391) [@jo-codegirl] - Examples: Added native Win32+OpenGL3 example. We don't recommend using this setup but we provide it for completeness. (#3218, #5170, #6086, #2772, #2600, #2359, #2022, #1553) [@learn-more] - Examples: Vulkan: Use integrated GPU if nothing else is available. (#6359) [@kimidaisuki22] From 70cca1eac07aa3809bdd3717253c3754a5b7cfcc Mon Sep 17 00:00:00 2001 From: Alex Date: Thu, 4 May 2023 08:18:29 -0700 Subject: [PATCH 07/14] Backends: avoid null dereference in metal and osx shutdown (#6385, #6334) Co-authored-by: Alexander Rath --- backends/imgui_impl_metal.mm | 5 +++-- backends/imgui_impl_osx.mm | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/backends/imgui_impl_metal.mm b/backends/imgui_impl_metal.mm index 00f5c0c65..dbf7a87f3 100644 --- a/backends/imgui_impl_metal.mm +++ b/backends/imgui_impl_metal.mm @@ -137,12 +137,13 @@ void ImGui_ImplMetal_Shutdown() { ImGui_ImplMetal_Data* bd = ImGui_ImplMetal_GetBackendData(); IM_ASSERT(bd != nullptr && "No renderer backend to shutdown, or already shutdown?"); + ImGui_ImplMetal_DestroyDeviceObjects(); + ImGui_ImplMetal_DestroyBackendData(); + ImGuiIO& io = ImGui::GetIO(); io.BackendRendererName = nullptr; io.BackendRendererUserData = nullptr; io.BackendFlags &= ~ImGuiBackendFlags_RendererHasVtxOffset; - ImGui_ImplMetal_DestroyDeviceObjects(); - ImGui_ImplMetal_DestroyBackendData(); } void ImGui_ImplMetal_NewFrame(MTLRenderPassDescriptor* renderPassDescriptor) diff --git a/backends/imgui_impl_osx.mm b/backends/imgui_impl_osx.mm index bf2747862..97c3e8f78 100644 --- a/backends/imgui_impl_osx.mm +++ b/backends/imgui_impl_osx.mm @@ -477,7 +477,6 @@ void ImGui_ImplOSX_Shutdown() { ImGui_ImplOSX_Data* bd = ImGui_ImplOSX_GetBackendData(); IM_ASSERT(bd != nullptr && "No platform backend to shutdown, or already shutdown?"); - ImGuiIO& io = ImGui::GetIO(); bd->Observer = nullptr; if (bd->Monitor != nullptr) @@ -486,10 +485,12 @@ void ImGui_ImplOSX_Shutdown() bd->Monitor = nullptr; } + ImGui_ImplOSX_DestroyBackendData(); + + ImGuiIO& io = ImGui::GetIO(); io.BackendPlatformName = nullptr; io.BackendPlatformUserData = nullptr; io.BackendFlags &= ~(ImGuiBackendFlags_HasMouseCursors | ImGuiBackendFlags_HasGamepad); - ImGui_ImplOSX_DestroyBackendData(); } static void ImGui_ImplOSX_UpdateMouseCursor() From 6cdedf58347b9b267383ef06096e09e9fcc34e18 Mon Sep 17 00:00:00 2001 From: ocornut Date: Tue, 9 May 2023 12:04:04 +0200 Subject: [PATCH 08/14] Drag, Sliders: if the format string doesn't contain any %, when using CTRL+Click to input we use a default format. (#6405) --- docs/CHANGELOG.txt | 3 +++ imgui.h | 2 +- imgui_demo.cpp | 4 ++-- imgui_widgets.cpp | 14 ++++++++++---- 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index ba15f8434..112987d5b 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -48,6 +48,9 @@ Other changes: initialized on VS2013. Unsure if due to a bug or UB/standard conformance). (#6377) - InputText: Avoid setting io.WantTextInputNextFrame during the deactivation frame. (#6341) [@lukaasm] +- Drag, Sliders: if the format string doesn't contain any %, CTRL+Click to input text will + use the default format specifier for the type. Allow display/input of raw value when using + "enums" patterns (display label instead of value) + allow using when value is hidden. (#6405) - Nav: Fixed navigation within tables/columns where item boundaries goes beyond columns limits, unclipped bounding boxes would interfere with other columns. (#2221) [@zzzyap, @ocornut] - Nav: Fixed CTRL+Tab into a root window with only childs with _NavFlattened flags diff --git a/imgui.h b/imgui.h index a450ffe2a..2d71f8546 100644 --- a/imgui.h +++ b/imgui.h @@ -23,7 +23,7 @@ // Library Version // (Integer encoded as XYYZZ for use in #if preprocessor conditionals, e.g. '#if IMGUI_VERSION_NUM > 12345') #define IMGUI_VERSION "1.89.6 WIP" -#define IMGUI_VERSION_NUM 18954 +#define IMGUI_VERSION_NUM 18955 #define IMGUI_HAS_TABLE /* diff --git a/imgui_demo.cpp b/imgui_demo.cpp index af3000e4d..908381e7c 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -631,7 +631,7 @@ static void ShowDemoWindowWidgets() ImGui::Text("Tooltips:"); ImGui::SameLine(); - ImGui::SmallButton("Button"); + ImGui::SmallButton("Basic"); if (ImGui::IsItemHovered()) ImGui::SetTooltip("I am a tooltip"); @@ -744,7 +744,7 @@ static void ShowDemoWindowWidgets() static int elem = Element_Fire; const char* elems_names[Element_COUNT] = { "Fire", "Earth", "Air", "Water" }; const char* elem_name = (elem >= 0 && elem < Element_COUNT) ? elems_names[elem] : "Unknown"; - ImGui::SliderInt("slider enum", &elem, 0, Element_COUNT - 1, elem_name); + ImGui::SliderInt("slider enum", &elem, 0, Element_COUNT - 1, elem_name); // Use ImGuiSliderFlags_NoInput flag to disable CTRL+Click here. ImGui::SameLine(); HelpMarker("Using the format string parameter to display a name instead of the underlying integer."); } diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index 31a1fa687..b7c5fca43 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -2090,7 +2090,8 @@ bool ImGui::DataTypeApplyFromText(const char* buf, ImGuiDataType data_type, void memcpy(&data_backup, p_data, type_info->Size); // Sanitize format - // For float/double we have to ignore format with precision (e.g. "%.2f") because sscanf doesn't take them in, so force them into %f and %lf + // - For float/double we have to ignore format with precision (e.g. "%.2f") because sscanf doesn't take them in, so force them into %f and %lf + // - In theory could treat empty format as using default, but this would only cover rare/bizarre case of using InputScalar() + integer + format string without %. char format_sanitized[32]; if (data_type == ImGuiDataType_Float || data_type == ImGuiDataType_Double) format = type_info->ScanFmt; @@ -3273,7 +3274,7 @@ const char* ImParseFormatFindEnd(const char* fmt) } // Extract the format out of a format string with leading or trailing decorations -// fmt = "blah blah" -> return fmt +// fmt = "blah blah" -> return "" // fmt = "%.3f" -> return fmt // fmt = "hello %.3f" -> return fmt + 6 // fmt = "%.3f hello" -> return buf written with "%.3f" @@ -3281,7 +3282,7 @@ const char* ImParseFormatTrimDecorations(const char* fmt, char* buf, size_t buf_ { const char* fmt_start = ImParseFormatFindStart(fmt); if (fmt_start[0] != '%') - return fmt; + return ""; const char* fmt_end = ImParseFormatFindEnd(fmt_start); if (fmt_end[0] == 0) // If we only have leading decoration, we don't need to copy the data. return fmt_start; @@ -3399,9 +3400,14 @@ static inline ImGuiInputTextFlags InputScalar_DefaultCharsFilter(ImGuiDataType d // However this may not be ideal for all uses, as some user code may break on out of bound values. bool ImGui::TempInputScalar(const ImRect& bb, ImGuiID id, const char* label, ImGuiDataType data_type, void* p_data, const char* format, const void* p_clamp_min, const void* p_clamp_max) { + // FIXME: May need to clarify display behavior if format doesn't contain %. + // "%d" -> "%d" / "There are %d items" -> "%d" / "items" -> "%d" (fallback). Also see #6405 + const ImGuiDataTypeInfo* type_info = DataTypeGetInfo(data_type); char fmt_buf[32]; char data_buf[32]; format = ImParseFormatTrimDecorations(format, fmt_buf, IM_ARRAYSIZE(fmt_buf)); + if (format[0] == 0) + format = type_info->PrintFmt; DataTypeFormatString(data_buf, IM_ARRAYSIZE(data_buf), data_type, p_data, format); ImStrTrimBlanks(data_buf); @@ -3412,7 +3418,7 @@ bool ImGui::TempInputScalar(const ImRect& bb, ImGuiID id, const char* label, ImG if (TempInputText(bb, id, label, data_buf, IM_ARRAYSIZE(data_buf), flags)) { // Backup old value - size_t data_type_size = DataTypeGetInfo(data_type)->Size; + size_t data_type_size = type_info->Size; ImGuiDataTypeTempStorage data_backup; memcpy(&data_backup, p_data, data_type_size); From dd9db5e889e64e4265bcc18e7b054d9d4893a5db Mon Sep 17 00:00:00 2001 From: ocornut Date: Tue, 9 May 2023 15:09:47 +0200 Subject: [PATCH 09/14] Backends: OpenGL3: Added runtime flags for ES2/ES3 to simplify coding-style. (#6375) --- backends/imgui_impl_opengl3.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/backends/imgui_impl_opengl3.cpp b/backends/imgui_impl_opengl3.cpp index b97992d57..6cd684a83 100644 --- a/backends/imgui_impl_opengl3.cpp +++ b/backends/imgui_impl_opengl3.cpp @@ -205,6 +205,8 @@ struct ImGui_ImplOpenGL3_Data { GLuint GlVersion; // Extracted at runtime using GL_MAJOR_VERSION, GL_MINOR_VERSION queries (e.g. 320 for GL 3.2) char GlslVersionString[32]; // Specified by user or detected based on compile time GL settings. + bool GlProfileIsES2; + bool GlProfileIsES3; bool GlProfileIsCompat; GLint GlProfileMask; GLuint FontTexture; @@ -301,8 +303,12 @@ bool ImGui_ImplOpenGL3_Init(const char* glsl_version) bd->UseBufferSubData = true; #endif */ -#else +#elif defined(IMGUI_IMPL_OPENGL_ES2) bd->GlVersion = 200; // GLES 2 + bd->GlProfileIsES2 = true; +#elif defined(IMGUI_IMPL_OPENGL_ES3) + bd->GlVersion = 200; // Don't raise version as it is intended as a desktop version check for now. + bd->GlProfileIsES3 = true; #endif #ifdef IMGUI_IMPL_OPENGL_DEBUG From 39f7248d4aa9eda0e5e39b50070f513df5204af8 Mon Sep 17 00:00:00 2001 From: Jason Millard Date: Wed, 26 Apr 2023 11:47:37 -0400 Subject: [PATCH 10/14] Backends: OpenGL3: Add glBindSampler for GL ES 3.0. (#6375) Amended given addition of GlProfileIsES3 in dd9db5e --- backends/imgui_impl_opengl3.cpp | 13 +++++++------ docs/CHANGELOG.txt | 1 + 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/backends/imgui_impl_opengl3.cpp b/backends/imgui_impl_opengl3.cpp index 6cd684a83..cbbd4fd2a 100644 --- a/backends/imgui_impl_opengl3.cpp +++ b/backends/imgui_impl_opengl3.cpp @@ -14,6 +14,7 @@ // CHANGELOG // (minor and older changes stripped away, please see git history for details) +// 2023-05-09: OpenGL: Support for glBindSampler() backup/restore on ES3. (#6375) // 2023-04-18: OpenGL: Restore front and back polygon mode separately when supported by context. (#6333) // 2023-03-23: OpenGL: Properly restoring "no shader program bound" if it was the case prior to running the rendering function. (#6267, #6220, #6224) // 2023-03-15: OpenGL: Fixed GL loader crash when GL_VERSION returns NULL. (#6154, #4445, #3530) @@ -176,8 +177,8 @@ #define IMGUI_IMPL_OPENGL_MAY_HAVE_VTX_OFFSET #endif -// Desktop GL 3.3+ has glBindSampler() -#if !defined(IMGUI_IMPL_OPENGL_ES2) && !defined(IMGUI_IMPL_OPENGL_ES3) && defined(GL_VERSION_3_3) +// Desktop GL 3.3+ and GL ES 3.0+ have glBindSampler() +#if !defined(IMGUI_IMPL_OPENGL_ES2) && (defined(IMGUI_IMPL_OPENGL_ES3) || defined(GL_VERSION_3_3)) #define IMGUI_IMPL_OPENGL_MAY_HAVE_BIND_SAMPLER #endif @@ -434,8 +435,8 @@ static void ImGui_ImplOpenGL3_SetupRenderState(ImDrawData* draw_data, int fb_wid glUniformMatrix4fv(bd->AttribLocationProjMtx, 1, GL_FALSE, &ortho_projection[0][0]); #ifdef IMGUI_IMPL_OPENGL_MAY_HAVE_BIND_SAMPLER - if (bd->GlVersion >= 330) - glBindSampler(0, 0); // We use combined texture/sampler state. Applications using GL 3.3 may set that otherwise. + if (bd->GlVersion >= 330 || bd->GlProfileIsES3) + glBindSampler(0, 0); // We use combined texture/sampler state. Applications using GL 3.3 and GL ES 3.0 may set that otherwise. #endif (void)vertex_array_object; @@ -473,7 +474,7 @@ void ImGui_ImplOpenGL3_RenderDrawData(ImDrawData* draw_data) GLuint last_program; glGetIntegerv(GL_CURRENT_PROGRAM, (GLint*)&last_program); GLuint last_texture; glGetIntegerv(GL_TEXTURE_BINDING_2D, (GLint*)&last_texture); #ifdef IMGUI_IMPL_OPENGL_MAY_HAVE_BIND_SAMPLER - GLuint last_sampler; if (bd->GlVersion >= 330) { glGetIntegerv(GL_SAMPLER_BINDING, (GLint*)&last_sampler); } else { last_sampler = 0; } + GLuint last_sampler; if (bd->GlVersion >= 330 || bd->GlProfileIsES3) { glGetIntegerv(GL_SAMPLER_BINDING, (GLint*)&last_sampler); } else { last_sampler = 0; } #endif GLuint last_array_buffer; glGetIntegerv(GL_ARRAY_BUFFER_BINDING, (GLint*)&last_array_buffer); #ifndef IMGUI_IMPL_OPENGL_USE_VERTEX_ARRAY @@ -600,7 +601,7 @@ void ImGui_ImplOpenGL3_RenderDrawData(ImDrawData* draw_data) if (last_program == 0 || glIsProgram(last_program)) glUseProgram(last_program); glBindTexture(GL_TEXTURE_2D, last_texture); #ifdef IMGUI_IMPL_OPENGL_MAY_HAVE_BIND_SAMPLER - if (bd->GlVersion >= 330) + if (bd->GlVersion >= 330 || bd->GlProfileIsES3) glBindSampler(0, last_sampler); #endif glActiveTexture(last_active_texture); diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 112987d5b..b755b1931 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -66,6 +66,7 @@ Other changes: Win32/Winapi with OpenGL. (#3218) - Backends: OpenGL3: Restore front and back polygon mode separately when supported by context (Desktop 3.0, 3.1, or 3.2+ with compat bit). (#6333) [@GereonV] +- Backends: OpenGL3: Support for glBindSampler() backup/restore on ES3. (#6375) [@jsm174] - Backends: SDL3: Fixed build on Emscripten/iOS/Android. (#6391) [@jo-codegirl] - Examples: Added native Win32+OpenGL3 example. We don't recommend using this setup but we provide it for completeness. (#3218, #5170, #6086, #2772, #2600, #2359, #2022, #1553) [@learn-more] From 6656553fa493b87b5780132a7a4cb01e80b4e996 Mon Sep 17 00:00:00 2001 From: ocornut Date: Wed, 26 Apr 2023 15:20:40 +0200 Subject: [PATCH 11/14] Nav: Record/restore preferred position on each given axis. Tagging #6344 #6003 #2694 #1688 as it relates to scoring, however this doesn't technically fix any of them fully yet. But e.g. once we restore axial path for #2694 this commit will allow going back and forth to initial location. --- docs/CHANGELOG.txt | 4 +++ imgui.cpp | 87 ++++++++++++++++++++++++++++++++++++++-------- imgui.h | 2 +- imgui_internal.h | 3 ++ imgui_widgets.cpp | 2 ++ 5 files changed, 83 insertions(+), 15 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index b755b1931..2745cf3f8 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -51,6 +51,10 @@ Other changes: - Drag, Sliders: if the format string doesn't contain any %, CTRL+Click to input text will use the default format specifier for the type. Allow display/input of raw value when using "enums" patterns (display label instead of value) + allow using when value is hidden. (#6405) +- Nav: Record/restore preferred position on each given axis after a movement on that axis, + then score movement on the other axis using this as a bias. This allows going up and down + between e.g. a large header spanning horizontal space and three-ways-columns, landing + on the same column as before. - Nav: Fixed navigation within tables/columns where item boundaries goes beyond columns limits, unclipped bounding boxes would interfere with other columns. (#2221) [@zzzyap, @ocornut] - Nav: Fixed CTRL+Tab into a root window with only childs with _NavFlattened flags diff --git a/imgui.cpp b/imgui.cpp index 2c34b5c20..738dfb0ac 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -3688,6 +3688,7 @@ ImGuiWindow::ImGuiWindow(ImGuiContext* ctx, const char* name) : DrawListInst(NUL DrawList = &DrawListInst; DrawList->_Data = &Ctx->DrawListSharedData; DrawList->_OwnerName = Name; + NavPreferredScoringPosRel[0] = NavPreferredScoringPosRel[1] = ImVec2(FLT_MAX, FLT_MAX); } ImGuiWindow::~ImGuiWindow() @@ -10620,6 +10621,12 @@ void ImGui::SetNavWindow(ImGuiWindow* window) NavUpdateAnyRequestFlag(); } +void ImGui::NavClearPreferredPosForAxis(ImGuiAxis axis) +{ + ImGuiContext& g = *GImGui; + g.NavWindow->RootWindowForNav->NavPreferredScoringPosRel[g.NavLayer][axis] = FLT_MAX; +} + void ImGui::SetNavID(ImGuiID id, ImGuiNavLayer nav_layer, ImGuiID focus_scope_id, const ImRect& rect_rel) { ImGuiContext& g = *GImGui; @@ -10630,6 +10637,10 @@ void ImGui::SetNavID(ImGuiID id, ImGuiNavLayer nav_layer, ImGuiID focus_scope_id g.NavFocusScopeId = focus_scope_id; g.NavWindow->NavLastIds[nav_layer] = id; g.NavWindow->NavRectRel[nav_layer] = rect_rel; + + // Clear preferred scoring position (NavMoveRequestApplyResult() will tend to restore it) + NavClearPreferredPosForAxis(ImGuiAxis_X); + NavClearPreferredPosForAxis(ImGuiAxis_Y); } void ImGui::SetFocusID(ImGuiID id, ImGuiWindow* window) @@ -10654,6 +10665,10 @@ void ImGui::SetFocusID(ImGuiID id, ImGuiWindow* window) g.NavDisableMouseHover = true; else g.NavDisableHighlight = true; + + // Clear preferred scoring position (NavMoveRequestApplyResult() will tend to restore it) + NavClearPreferredPosForAxis(ImGuiAxis_X); + NavClearPreferredPosForAxis(ImGuiAxis_Y); } ImGuiDir ImGetDirQuadrantFromDelta(float dx, float dy) @@ -10746,16 +10761,22 @@ static bool ImGui::NavScoreItem(ImGuiNavItemData* result) draw_list->AddText(cand.Min, IM_COL32(255, 255, 255, 255), buf); } } - if (IsMouseHoveringRect(cand.Min, cand.Max)) + const bool debug_hovering = IsMouseHoveringRect(cand.Min, cand.Max); + const bool debug_tty = (g.IO.KeyCtrl && IsKeyPressed(ImGuiKey_Space)); + if (debug_hovering || debug_tty) { ImFormatString(buf, IM_ARRAYSIZE(buf), "d-box (%7.3f,%7.3f) -> %7.3f\nd-center (%7.3f,%7.3f) -> %7.3f\nd-axial (%7.3f,%7.3f) -> %7.3f\nnav %c, quadrant %c", - dbx, dby, dist_box, dcx, dcy, dist_center, dax, day, dist_axial, "WENS"[g.NavMoveDir], "WENS"[quadrant]); - ImDrawList* draw_list = GetForegroundDrawList(window); - draw_list->AddRect(curr.Min, curr.Max, IM_COL32(255,200,0,100)); - draw_list->AddRect(cand.Min, cand.Max, IM_COL32(255,255,0,200)); - draw_list->AddRectFilled(cand.Max - ImVec2(4, 4), cand.Max + CalcTextSize(buf) + ImVec2(4, 4), IM_COL32(40,0,0,200)); - draw_list->AddText(cand.Max, ~0U, buf); + dbx, dby, dist_box, dcx, dcy, dist_center, dax, day, dist_axial, "-WENS"[move_dir+1], "-WENS"[quadrant+1]); + if (debug_hovering) + { + ImDrawList* draw_list = GetForegroundDrawList(window); + draw_list->AddRect(curr.Min, curr.Max, IM_COL32(255, 200, 0, 100)); + draw_list->AddRect(cand.Min, cand.Max, IM_COL32(255, 255, 0, 200)); + draw_list->AddRectFilled(cand.Max - ImVec2(4, 4), cand.Max + CalcTextSize(buf) + ImVec2(4, 4), IM_COL32(40, 0, 0, 200)); + draw_list->AddText(cand.Max, ~0U, buf); + } + if (debug_tty) { IMGUI_DEBUG_LOG_NAV("id 0x%08X\n%s\n", g.LastItemData.ID, buf); } } #endif @@ -11322,11 +11343,11 @@ static void ImGui::NavUpdate() // [DEBUG] g.NavScoringDebugCount = 0; #if IMGUI_DEBUG_NAV_RECTS - if (g.NavWindow) + if (ImGuiWindow* debug_window = g.NavWindow) { - ImDrawList* draw_list = GetForegroundDrawList(g.NavWindow); - if (1) { for (int layer = 0; layer < 2; layer++) { ImRect r = WindowRectRelToAbs(g.NavWindow, g.NavWindow->NavRectRel[layer]); draw_list->AddRect(r.Min, r.Max, IM_COL32(255,200,0,255)); } } // [DEBUG] - if (1) { ImU32 col = (!g.NavWindow->Hidden) ? IM_COL32(255,0,255,255) : IM_COL32(255,0,0,255); ImVec2 p = NavCalcPreferredRefPos(); char buf[32]; ImFormatString(buf, 32, "%d", g.NavLayer); draw_list->AddCircleFilled(p, 3.0f, col); draw_list->AddText(NULL, 13.0f, p + ImVec2(8,-4), col, buf); } + ImDrawList* draw_list = GetForegroundDrawList(debug_window); + int layer = g.NavLayer; /* for (int layer = 0; layer < 2; layer++)*/ { ImRect r = WindowRectRelToAbs(debug_window, debug_window->NavRectRel[layer]); draw_list->AddRect(r.Min, r.Max, IM_COL32(255, 200, 0, 255)); } + //if (1) { ImU32 col = (!debug_window->Hidden) ? IM_COL32(255,0,255,255) : IM_COL32(255,0,0,255); ImVec2 p = NavCalcPreferredRefPos(); char buf[32]; ImFormatString(buf, 32, "%d", g.NavLayer); draw_list->AddCircleFilled(p, 3.0f, col); draw_list->AddText(NULL, 13.0f, p + ImVec2(8,-4), col, buf); } } #endif } @@ -11347,6 +11368,28 @@ void ImGui::NavInitRequestApplyResult() NavRestoreHighlightAfterMove(); } +// Bias scoring rect ahead of scoring + update preferred pos (if missing) using source position +static void NavBiasScoringRect(ImRect& r, ImVec2& preferred_pos_rel, ImGuiDir move_dir) +{ + // Bias initial rect + ImGuiContext& g = *GImGui; + const ImVec2 rel_to_abs_offset = g.NavWindow->DC.CursorStartPos; + + // Initialize bias on departure if we don't have any. So mouse-click + arrow will record bias. + // - We default to L/U bias, so moving down from a large source item into several columns will land on left-most column. + // - But each successful move sets new bias on one axis, only cleared when using mouse. + if (preferred_pos_rel.x == FLT_MAX) + preferred_pos_rel.x = ImMin(r.Min.x + 1.0f, r.Max.x) - rel_to_abs_offset.x; + if (preferred_pos_rel.y == FLT_MAX) + preferred_pos_rel.y = r.GetCenter().y - rel_to_abs_offset.y; + + // Apply general bias on the other axis + if (move_dir == ImGuiDir_Up || move_dir == ImGuiDir_Down) + r.Min.x = r.Max.x = preferred_pos_rel.x + rel_to_abs_offset.x; + else + r.Min.y = r.Max.y = preferred_pos_rel.y + rel_to_abs_offset.y; +} + void ImGui::NavUpdateCreateMoveRequest() { ImGuiContext& g = *GImGui; @@ -11453,8 +11496,8 @@ void ImGui::NavUpdateCreateMoveRequest() ImRect nav_rect_rel = !window->NavRectRel[g.NavLayer].IsInverted() ? window->NavRectRel[g.NavLayer] : ImRect(0, 0, 0, 0); scoring_rect = WindowRectRelToAbs(window, nav_rect_rel); scoring_rect.TranslateY(scoring_rect_offset_y); - scoring_rect.Min.x = ImMin(scoring_rect.Min.x + 1.0f, scoring_rect.Max.x); - scoring_rect.Max.x = scoring_rect.Min.x; + if (g.NavMoveSubmitted) + NavBiasScoringRect(scoring_rect, window->RootWindowForNav->NavPreferredScoringPosRel[g.NavLayer], g.NavMoveDir); IM_ASSERT(!scoring_rect.IsInverted()); // Ensure if we have a finite, non-inverted bounding box here will allow us to remove extraneous ImFabs() calls in NavScoreItem(). //GetForegroundDrawList()->AddRect(scoring_rect.Min, scoring_rect.Max, IM_COL32(255,200,0,255)); // [DEBUG] //if (!g.NavScoringNoClipRect.IsInverted()) { GetForegroundDrawList()->AddRect(g.NavScoringNoClipRect.Min, g.NavScoringNoClipRect.Max, IM_COL32(255, 200, 0, 255)); } // [DEBUG] @@ -11508,12 +11551,14 @@ void ImGui::NavMoveRequestApplyResult() result = &g.NavTabbingResultFirst; // In a situation when there are no results but NavId != 0, re-enable the Navigation highlight (because g.NavId is not considered as a possible result) + const ImGuiAxis axis = (g.NavMoveDir == ImGuiDir_Up || g.NavMoveDir == ImGuiDir_Down) ? ImGuiAxis_Y : ImGuiAxis_X; if (result == NULL) { if (g.NavMoveFlags & ImGuiNavMoveFlags_Tabbing) g.NavMoveFlags |= ImGuiNavMoveFlags_DontSetNavHighlight; if (g.NavId != 0 && (g.NavMoveFlags & ImGuiNavMoveFlags_DontSetNavHighlight) == 0) NavRestoreHighlightAfterMove(); + NavClearPreferredPosForAxis(axis); // On a failed move, clear preferred pos for this axis. IMGUI_DEBUG_LOG_NAV("[nav] NavMoveSubmitted but not led to a result!\n"); return; } @@ -11558,10 +11603,19 @@ void ImGui::NavMoveRequestApplyResult() g.NavJustMovedToKeyMods = g.NavMoveKeyMods; } - // Focus + // Apply new NavID/Focus IMGUI_DEBUG_LOG_NAV("[nav] NavMoveRequest: result NavID 0x%08X in Layer %d Window \"%s\"\n", result->ID, g.NavLayer, g.NavWindow->Name); + ImVec2 preferred_scoring_pos_rel = g.NavWindow->RootWindowForNav->NavPreferredScoringPosRel[g.NavLayer]; SetNavID(result->ID, g.NavLayer, result->FocusScopeId, result->RectRel); + // Restore last preferred position for current axis + // (storing in RootWindowForNav-> as the info is desirable at the beginning of a Move Request. In theory all storage should use RootWindowForNav..) + if ((g.NavMoveFlags & ImGuiNavMoveFlags_Tabbing) == 0) + { + preferred_scoring_pos_rel[axis] = result->RectRel.GetCenter()[axis]; + g.NavWindow->RootWindowForNav->NavPreferredScoringPosRel[g.NavLayer] = preferred_scoring_pos_rel; + } + // Tabbing: Activates Inputable or Focus non-Inputable if ((g.NavMoveFlags & ImGuiNavMoveFlags_Tabbing) && (result->InFlags & ImGuiItemFlags_Inputable)) { @@ -11775,6 +11829,8 @@ static void ImGui::NavUpdateCreateWrappingRequest() if (!do_forward) return; window->NavRectRel[g.NavLayer] = bb_rel; + NavClearPreferredPosForAxis(ImGuiAxis_X); + NavClearPreferredPosForAxis(ImGuiAxis_Y); NavMoveRequestForward(g.NavMoveDir, clip_dir, move_flags, g.NavMoveScrollFlags); } @@ -14285,6 +14341,9 @@ void ImGui::DebugNodeWindow(ImGuiWindow* window, const char* label) BulletText("NavLastIds[%d]: 0x%08X at +(%.1f,%.1f)(%.1f,%.1f)", layer, window->NavLastIds[layer], r.Min.x, r.Min.y, r.Max.x, r.Max.y); DebugLocateItemOnHover(window->NavLastIds[layer]); } + const ImVec2* pr = window->NavPreferredScoringPosRel; + for (int layer = 0; layer < ImGuiNavLayer_COUNT; layer++) + BulletText("NavPreferredScoringPosRel[%d] = {%.1f,%.1f)", layer, (pr[layer].x == FLT_MAX ? -99999.0f : pr[layer].x), (pr[layer].y == FLT_MAX ? -99999.0f : pr[layer].y)); // Display as 99999.0f so it looks neater. BulletText("NavLayersActiveMask: %X, NavLastChildNavWindow: %s", window->DC.NavLayersActiveMask, window->NavLastChildNavWindow ? window->NavLastChildNavWindow->Name : "NULL"); if (window->RootWindow != window) { DebugNodeWindow(window->RootWindow, "RootWindow"); } if (window->ParentWindow != NULL) { DebugNodeWindow(window->ParentWindow, "ParentWindow"); } diff --git a/imgui.h b/imgui.h index 2d71f8546..c2d7cdda0 100644 --- a/imgui.h +++ b/imgui.h @@ -23,7 +23,7 @@ // Library Version // (Integer encoded as XYYZZ for use in #if preprocessor conditionals, e.g. '#if IMGUI_VERSION_NUM > 12345') #define IMGUI_VERSION "1.89.6 WIP" -#define IMGUI_VERSION_NUM 18955 +#define IMGUI_VERSION_NUM 18956 #define IMGUI_HAS_TABLE /* diff --git a/imgui_internal.h b/imgui_internal.h index c6b9ee6fa..00c762ee5 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -2366,6 +2366,7 @@ struct IMGUI_API ImGuiWindow ImGuiWindow* NavLastChildNavWindow; // When going to the menu bar, we remember the child window we came from. (This could probably be made implicit if we kept g.Windows sorted by last focused including child window.) ImGuiID NavLastIds[ImGuiNavLayer_COUNT]; // Last known NavId for this window, per layer (0/1) ImRect NavRectRel[ImGuiNavLayer_COUNT]; // Reference rectangle, in window relative space + ImVec2 NavPreferredScoringPosRel[ImGuiNavLayer_COUNT]; // Preferred X/Y position updated when moving on a given axis, reset to FLT_MAX. ImGuiID NavRootFocusScopeId; // Focus Scope ID at the time of Begin() int MemoryDrawListIdxCapacity; // Backup of last idx/vtx count, so when waking up the window we can preallocate and avoid iterative alloc/copy @@ -2761,6 +2762,7 @@ namespace ImGui IMGUI_API void SetWindowHiddendAndSkipItemsForCurrentFrame(ImGuiWindow* window); inline ImRect WindowRectAbsToRel(ImGuiWindow* window, const ImRect& r) { ImVec2 off = window->DC.CursorStartPos; return ImRect(r.Min.x - off.x, r.Min.y - off.y, r.Max.x - off.x, r.Max.y - off.y); } inline ImRect WindowRectRelToAbs(ImGuiWindow* window, const ImRect& r) { ImVec2 off = window->DC.CursorStartPos; return ImRect(r.Min.x + off.x, r.Min.y + off.y, r.Max.x + off.x, r.Max.y + off.y); } + inline ImVec2 WindowPosRelToAbs(ImGuiWindow* window, const ImVec2& p) { ImVec2 off = window->DC.CursorStartPos; return ImVec2(p.x + off.x, p.y + off.y); } // Windows: Display Order and Focus Order IMGUI_API void FocusWindow(ImGuiWindow* window, ImGuiFocusRequestFlags flags = 0); @@ -2908,6 +2910,7 @@ namespace ImGui IMGUI_API void NavMoveRequestCancel(); IMGUI_API void NavMoveRequestApplyResult(); IMGUI_API void NavMoveRequestTryWrapping(ImGuiWindow* window, ImGuiNavMoveFlags move_flags); + IMGUI_API void NavClearPreferredPosForAxis(ImGuiAxis axis); IMGUI_API void NavUpdateCurrentWindowIsScrollPushableX(); IMGUI_API void ActivateItem(ImGuiID id); // Remotely activate a button, checkbox, tree node etc. given its unique ID. activation is queued and processed on the next frame when the item is encountered again. IMGUI_API void SetNavWindow(ImGuiWindow* window); diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index b7c5fca43..c451a5c82 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -6219,11 +6219,13 @@ bool ImGui::TreeNodeBehavior(ImGuiID id, ImGuiTreeNodeFlags flags, const char* l if (g.NavId == id && g.NavMoveDir == ImGuiDir_Left && is_open) { toggled = true; + NavClearPreferredPosForAxis(ImGuiAxis_X); NavMoveRequestCancel(); } if (g.NavId == id && g.NavMoveDir == ImGuiDir_Right && !is_open) // If there's something upcoming on the line we may want to give it the priority? { toggled = true; + NavClearPreferredPosForAxis(ImGuiAxis_X); NavMoveRequestCancel(); } From 0397321be09db6bc98db773af0572024e0ec506d Mon Sep 17 00:00:00 2001 From: ocornut Date: Tue, 9 May 2023 20:28:08 +0200 Subject: [PATCH 12/14] Debug Tools: Added 'io.ConfigDebugIgnoreFocusLoss' option. (#4388, #4921) --- docs/CHANGELOG.txt | 3 +++ imgui.cpp | 2 +- imgui.h | 12 ++++++++---- imgui_demo.cpp | 2 ++ 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 2745cf3f8..b840b8cf7 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -64,6 +64,9 @@ Other changes: - Misc: Added ImVec2 unary minus operator. (#6368) [@Koostosh] - Debug Tools: Debug Log: Fixed not parsing 0xXXXXXXXX values for geo-locating on mouse hover hover when the identifier is at the end of the line. (#5855) +- Debug Tools: Added 'io.ConfigDebugIgnoreFocusLoss' option to disable 'io.AddFocusEvent(false)' + handling. May facilitate interactions with a debugger when focus loss leads to clearing + inputs data. (#4388, #4921) - Backends: Clear bits sets io.BackendFlags on backend Shutdown(). (#6334, #6335] [@GereonV] Potentially this would facilitate switching runtime backend mid-session. - Backends: Win32: Added ImGui_ImplWin32_InitForOpenGL() to facilitate combining raw diff --git a/imgui.cpp b/imgui.cpp index 738dfb0ac..fe611f8a4 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -1540,7 +1540,7 @@ void ImGuiIO::AddFocusEvent(bool focused) // Filter duplicate const ImGuiInputEvent* latest_event = FindLatestInputEvent(&g, ImGuiInputEventType_Focus); const bool latest_focused = latest_event ? latest_event->AppFocused.Focused : !g.IO.AppFocusLost; - if (latest_focused == focused) + if (latest_focused == focused || (ConfigDebugIgnoreFocusLoss && !focused)) return; ImGuiInputEvent e; diff --git a/imgui.h b/imgui.h index c2d7cdda0..8bacf9f07 100644 --- a/imgui.h +++ b/imgui.h @@ -1952,11 +1952,15 @@ struct ImGuiIO // Debug options // - tools to test correct Begin/End and BeginChild/EndChild behaviors. - // - presently Begn()/End() and BeginChild()EndChild() needs to ALWAYS be called in tandem, regardless of return value of BeginXXX() + // - presently Begin()/End() and BeginChild()/EndChild() needs to ALWAYS be called in tandem, regardless of return value of BeginXXX() // this is inconsistent with other BeginXXX functions and create confusion for many users. - // - we expect to update the API eventually. In the meanwhile we provided tools to facilitate checking user-code behavior. - bool ConfigDebugBeginReturnValueOnce; // = false // First-time calls to Begin()/BeginChild() will return false. NEEDS TO BE SET AT APPLICATION BOOT TIME if you don't want to miss windows. - bool ConfigDebugBeginReturnValueLoop; // = false // Some calls to Begin()/BeginChild() will return false. Will cycle through window depths then repeat. Suggested use: add "io.ConfigDebugBeginReturnValue = io.KeyShift" in your main loop then occasionally press SHIFT. Windows should be flickering while running. + // - we expect to update the API eventually. In the meanwhile we provide tools to facilitate checking user-code behavior. + bool ConfigDebugBeginReturnValueOnce;// = false // First-time calls to Begin()/BeginChild() will return false. NEEDS TO BE SET AT APPLICATION BOOT TIME if you don't want to miss windows. + bool ConfigDebugBeginReturnValueLoop;// = false // Some calls to Begin()/BeginChild() will return false. Will cycle through window depths then repeat. Suggested use: add "io.ConfigDebugBeginReturnValue = io.KeyShift" in your main loop then occasionally press SHIFT. Windows should be flickering while running. + // - option to deactivate io.AddFocusEvent(false) handling. May facilitate interactions with a debugger when focus loss leads to clearing inputs data. + // - backends may have other side-effects on focus loss, so this will reduce side-effects but not necessary remove all of them. + // - consider using e.g. Win32's IsDebuggerPresent() as an additional filter (or see ImOsIsDebuggerPresent() in imgui_test_engine/imgui_te_utils.cpp for a Unix compatible version). + bool ConfigDebugIgnoreFocusLoss; // = false // Ignore io.AddFocusEvent(false), consequently not calling io.ClearInputKeys() in input processing. //------------------------------------------------------------------ // Platform Functions diff --git a/imgui_demo.cpp b/imgui_demo.cpp index 908381e7c..c35f99dbb 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -471,6 +471,8 @@ void ImGui::ShowDemoWindow(bool* p_open) ImGui::SameLine(); HelpMarker("First calls to Begin()/BeginChild() will return false.\n\nTHIS OPTION IS DISABLED because it needs to be set at application boot-time to make sense. Showing the disabled option is a way to make this feature easier to discover"); ImGui::Checkbox("io.ConfigDebugBeginReturnValueLoop", &io.ConfigDebugBeginReturnValueLoop); ImGui::SameLine(); HelpMarker("Some calls to Begin()/BeginChild() will return false.\n\nWill cycle through window depths then repeat. Windows should be flickering while running."); + ImGui::Checkbox("io.ConfigDebugIgnoreFocusLoss", &io.ConfigDebugIgnoreFocusLoss); + ImGui::SameLine(); HelpMarker("Option to deactivate io.AddFocusEvent(false) handling. May facilitate interactions with a debugger when focus loss leads to clearing inputs data."); ImGui::TreePop(); ImGui::Spacing(); From 513af1efc9080857bbd10000d98f98f2a0c96803 Mon Sep 17 00:00:00 2001 From: ocornut Date: Wed, 10 May 2023 12:34:11 +0200 Subject: [PATCH 13/14] Examples: Updated all Visual Studio project file to use /utf-8 option, so string literals are UTF-8 encoded by default. (Not to misake with "Character Set" "Use Unicode Character Set" "Use Multi-Byte Character Set" which is a VS/Windows SDK thing but not a compiler-encoding thing.) --- docs/CHANGELOG.txt | 1 + examples/example_allegro5/README.md | 2 +- .../example_allegro5/example_allegro5.vcxproj | 4 ++++ examples/example_glfw_opengl2/build_win32.bat | 2 +- .../example_glfw_opengl2.vcxproj | 4 ++++ examples/example_glfw_opengl3/build_win32.bat | 2 +- .../example_glfw_opengl3.vcxproj | 4 ++++ examples/example_glfw_vulkan/build_win32.bat | 4 ++-- examples/example_glfw_vulkan/build_win64.bat | 4 ++-- .../example_glfw_vulkan.vcxproj | 4 ++++ .../example_glut_opengl2.vcxproj | 4 ++++ examples/example_null/build_win32.bat | 2 +- .../example_sdl2_directx11/build_win32.bat | 2 +- .../example_sdl2_directx11.vcxproj | 4 ++++ examples/example_sdl2_opengl2/build_win32.bat | 2 +- .../example_sdl2_opengl2.vcxproj | 4 ++++ examples/example_sdl2_opengl3/README.md | 6 +++--- examples/example_sdl2_opengl3/build_win32.bat | 2 +- .../example_sdl2_opengl3.vcxproj | 4 ++++ examples/example_sdl2_sdlrenderer/README.md | 6 +++--- .../example_sdl2_sdlrenderer/build_win32.bat | 2 +- .../example_sdl2_sdlrenderer.vcxproj | 4 ++++ examples/example_sdl2_vulkan/build_win32.bat | 2 +- .../example_sdl2_vulkan.vcxproj | 4 ++++ examples/example_sdl3_opengl3/README.md | 6 +++--- examples/example_sdl3_opengl3/build_win32.bat | 2 +- .../example_sdl3_opengl3.vcxproj | 4 ++++ .../example_win32_directx10/build_win32.bat | 2 +- .../example_win32_directx10.vcxproj | 4 ++++ .../example_win32_directx11/build_win32.bat | 2 +- .../example_win32_directx11.vcxproj | 4 ++++ examples/example_win32_directx11/main.cpp | 19 ++++++++++++++++--- .../example_win32_directx12/build_win32.bat | 2 +- .../example_win32_directx12.vcxproj | 4 ++++ .../example_win32_directx9/build_win32.bat | 2 +- .../example_win32_directx9.vcxproj | 4 ++++ .../example_win32_opengl3/build_win32.bat | 2 +- .../example_win32_opengl3.vcxproj | 4 ++++ 38 files changed, 109 insertions(+), 31 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index b840b8cf7..c0637a057 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -80,6 +80,7 @@ Other changes: - Examples: Vulkan: Use integrated GPU if nothing else is available. (#6359) [@kimidaisuki22] - Examples: DX9, DX10, DX11: Queue framebuffer resize instead of processing in WM_SIZE, as some drivers tends to only cleanup after existing the native resize modal loop. (#6374) +- Examples: Updated all Visual Studio projects and batches to use /utf-8 argument. ----------------------------------------------------------------------- diff --git a/examples/example_allegro5/README.md b/examples/example_allegro5/README.md index c86179ccc..4af31f6f3 100644 --- a/examples/example_allegro5/README.md +++ b/examples/example_allegro5/README.md @@ -32,5 +32,5 @@ vcpkg integrate install ; register include / libs in Visual Studio Build: ``` set ALLEGRODIR=path_to_your_allegro5_folder -cl /Zi /MD /I %ALLEGRODIR%\include /DIMGUI_USER_CONFIG=\"examples/example_allegro5/imconfig_allegro5.h\" /I .. /I ..\.. /I ..\..\backends main.cpp ..\..\backends\imgui_impl_allegro5.cpp ..\..\imgui*.cpp /link /LIBPATH:%ALLEGRODIR%\lib allegro-5.0.10-monolith-md.lib user32.lib +cl /Zi /MD /utf-8 /I %ALLEGRODIR%\include /DIMGUI_USER_CONFIG=\"examples/example_allegro5/imconfig_allegro5.h\" /I .. /I ..\.. /I ..\..\backends main.cpp ..\..\backends\imgui_impl_allegro5.cpp ..\..\imgui*.cpp /link /LIBPATH:%ALLEGRODIR%\lib allegro-5.0.10-monolith-md.lib user32.lib ``` diff --git a/examples/example_allegro5/example_allegro5.vcxproj b/examples/example_allegro5/example_allegro5.vcxproj index 8c549b443..02f6a4741 100644 --- a/examples/example_allegro5/example_allegro5.vcxproj +++ b/examples/example_allegro5/example_allegro5.vcxproj @@ -91,6 +91,7 @@ Level4 Disabled ..\..;..\..\backends;%(AdditionalIncludeDirectories) + /utf-8 %(AdditionalOptions) true @@ -105,6 +106,7 @@ Level4 Disabled ..\..;..\..\backends;%(AdditionalIncludeDirectories) + /utf-8 %(AdditionalOptions) true @@ -122,6 +124,7 @@ true ..\..;..\..\backends;%(AdditionalIncludeDirectories) false + /utf-8 %(AdditionalOptions) true @@ -142,6 +145,7 @@ true ..\..;..\..\backends;%(AdditionalIncludeDirectories) false + /utf-8 %(AdditionalOptions) true diff --git a/examples/example_glfw_opengl2/build_win32.bat b/examples/example_glfw_opengl2/build_win32.bat index a0a75f906..24c0e08fd 100644 --- a/examples/example_glfw_opengl2/build_win32.bat +++ b/examples/example_glfw_opengl2/build_win32.bat @@ -5,4 +5,4 @@ @set SOURCES=main.cpp ..\..\backends\imgui_impl_opengl2.cpp ..\..\backends\imgui_impl_glfw.cpp ..\..\imgui*.cpp @set LIBS=/LIBPATH:..\libs\glfw\lib-vc2010-32 glfw3.lib opengl32.lib gdi32.lib shell32.lib mkdir %OUT_DIR% -cl /nologo /Zi /MD %INCLUDES% %SOURCES% /Fe%OUT_DIR%/%OUT_EXE%.exe /Fo%OUT_DIR%/ /link %LIBS% +cl /nologo /Zi /MD /utf-8 %INCLUDES% %SOURCES% /Fe%OUT_DIR%/%OUT_EXE%.exe /Fo%OUT_DIR%/ /link %LIBS% diff --git a/examples/example_glfw_opengl2/example_glfw_opengl2.vcxproj b/examples/example_glfw_opengl2/example_glfw_opengl2.vcxproj index 82bdac221..2aa25506e 100644 --- a/examples/example_glfw_opengl2/example_glfw_opengl2.vcxproj +++ b/examples/example_glfw_opengl2/example_glfw_opengl2.vcxproj @@ -91,6 +91,7 @@ Level4 Disabled ..\..;..\..\backends;..\libs\glfw\include;%(AdditionalIncludeDirectories) + /utf-8 %(AdditionalOptions) true @@ -105,6 +106,7 @@ Level4 Disabled ..\..;..\..\backends;..\libs\glfw\include;%(AdditionalIncludeDirectories) + /utf-8 %(AdditionalOptions) true @@ -122,6 +124,7 @@ true ..\..;..\..\backends;..\libs\glfw\include;%(AdditionalIncludeDirectories) false + /utf-8 %(AdditionalOptions) true @@ -142,6 +145,7 @@ true ..\..;..\..\backends;..\libs\glfw\include;%(AdditionalIncludeDirectories) false + /utf-8 %(AdditionalOptions) true diff --git a/examples/example_glfw_opengl3/build_win32.bat b/examples/example_glfw_opengl3/build_win32.bat index 4ba58d8c9..b5979ad49 100644 --- a/examples/example_glfw_opengl3/build_win32.bat +++ b/examples/example_glfw_opengl3/build_win32.bat @@ -5,4 +5,4 @@ @set SOURCES=main.cpp ..\..\backends\imgui_impl_glfw.cpp ..\..\backends\imgui_impl_opengl3.cpp ..\..\imgui*.cpp @set LIBS=/LIBPATH:..\libs\glfw\lib-vc2010-32 glfw3.lib opengl32.lib gdi32.lib shell32.lib mkdir %OUT_DIR% -cl /nologo /Zi /MD %INCLUDES% %SOURCES% /Fe%OUT_DIR%/%OUT_EXE%.exe /Fo%OUT_DIR%/ /link %LIBS% +cl /nologo /Zi /MD /utf-8 %INCLUDES% %SOURCES% /Fe%OUT_DIR%/%OUT_EXE%.exe /Fo%OUT_DIR%/ /link %LIBS% diff --git a/examples/example_glfw_opengl3/example_glfw_opengl3.vcxproj b/examples/example_glfw_opengl3/example_glfw_opengl3.vcxproj index 0a1c3d6be..4bd503afe 100644 --- a/examples/example_glfw_opengl3/example_glfw_opengl3.vcxproj +++ b/examples/example_glfw_opengl3/example_glfw_opengl3.vcxproj @@ -91,6 +91,7 @@ Level4 Disabled ..\..;..\..\backends;..\libs\glfw\include;%(AdditionalIncludeDirectories) + /utf-8 %(AdditionalOptions) true @@ -105,6 +106,7 @@ Level4 Disabled ..\..;..\..\backends;..\libs\glfw\include;%(AdditionalIncludeDirectories) + /utf-8 %(AdditionalOptions) true @@ -122,6 +124,7 @@ true ..\..;..\..\backends;..\libs\glfw\include;%(AdditionalIncludeDirectories) false + /utf-8 %(AdditionalOptions) true @@ -142,6 +145,7 @@ true ..\..;..\..\backends;..\libs\glfw\include;%(AdditionalIncludeDirectories) false + /utf-8 %(AdditionalOptions) true diff --git a/examples/example_glfw_vulkan/build_win32.bat b/examples/example_glfw_vulkan/build_win32.bat index 82f01112d..be9239816 100644 --- a/examples/example_glfw_vulkan/build_win32.bat +++ b/examples/example_glfw_vulkan/build_win32.bat @@ -7,8 +7,8 @@ @set OUT_DIR=Debug mkdir %OUT_DIR% -cl /nologo /Zi /MD %INCLUDES% /D ImTextureID=ImU64 %SOURCES% /Fe%OUT_DIR%/%OUT_EXE%.exe /Fo%OUT_DIR%/ /link %LIBS% +cl /nologo /Zi /MD /utf-8 %INCLUDES% /D ImTextureID=ImU64 %SOURCES% /Fe%OUT_DIR%/%OUT_EXE%.exe /Fo%OUT_DIR%/ /link %LIBS% @set OUT_DIR=Release mkdir %OUT_DIR% -cl /nologo /Zi /MD /Ox /Oi %INCLUDES% /D ImTextureID=ImU64 %SOURCES% /Fe%OUT_DIR%/%OUT_EXE%.exe /Fo%OUT_DIR%/ /link %LIBS% +cl /nologo /Zi /MD /utf-8 /Ox /Oi %INCLUDES% /D ImTextureID=ImU64 %SOURCES% /Fe%OUT_DIR%/%OUT_EXE%.exe /Fo%OUT_DIR%/ /link %LIBS% diff --git a/examples/example_glfw_vulkan/build_win64.bat b/examples/example_glfw_vulkan/build_win64.bat index 0bf7936c6..c60b02789 100644 --- a/examples/example_glfw_vulkan/build_win64.bat +++ b/examples/example_glfw_vulkan/build_win64.bat @@ -6,8 +6,8 @@ @set OUT_DIR=Debug mkdir %OUT_DIR% -cl /nologo /Zi /MD %INCLUDES% /D ImTextureID=ImU64 %SOURCES% /Fe%OUT_DIR%/%OUT_EXE%.exe /Fo%OUT_DIR%/ /link %LIBS% +cl /nologo /Zi /MD /utf-8 %INCLUDES% /D ImTextureID=ImU64 %SOURCES% /Fe%OUT_DIR%/%OUT_EXE%.exe /Fo%OUT_DIR%/ /link %LIBS% @set OUT_DIR=Release mkdir %OUT_DIR% -cl /nologo /Zi /MD /Ox /Oi %INCLUDES% /D ImTextureID=ImU64 %SOURCES% /Fe%OUT_DIR%/%OUT_EXE%.exe /Fo%OUT_DIR%/ /link %LIBS% +cl /nologo /Zi /MD /utf-8 /Ox /Oi %INCLUDES% /D ImTextureID=ImU64 %SOURCES% /Fe%OUT_DIR%/%OUT_EXE%.exe /Fo%OUT_DIR%/ /link %LIBS% diff --git a/examples/example_glfw_vulkan/example_glfw_vulkan.vcxproj b/examples/example_glfw_vulkan/example_glfw_vulkan.vcxproj index 4eb8b7ce6..d0d1c5f88 100644 --- a/examples/example_glfw_vulkan/example_glfw_vulkan.vcxproj +++ b/examples/example_glfw_vulkan/example_glfw_vulkan.vcxproj @@ -92,6 +92,7 @@ Disabled ..\..;..\..\backends;%VULKAN_SDK%\include;..\libs\glfw\include;%(AdditionalIncludeDirectories) ImTextureID=ImU64;_MBCS;%(PreprocessorDefinitions) + /utf-8 %(AdditionalOptions) true @@ -107,6 +108,7 @@ Disabled ..\..;..\..\backends;%VULKAN_SDK%\include;..\libs\glfw\include;%(AdditionalIncludeDirectories) ImTextureID=ImU64;_MBCS;%(PreprocessorDefinitions) + /utf-8 %(AdditionalOptions) true @@ -125,6 +127,7 @@ ..\..;..\..\backends;%VULKAN_SDK%\include;..\libs\glfw\include;%(AdditionalIncludeDirectories) false ImTextureID=ImU64;_MBCS;%(PreprocessorDefinitions) + /utf-8 %(AdditionalOptions) true @@ -146,6 +149,7 @@ ..\..;..\..\backends;%VULKAN_SDK%\include;..\libs\glfw\include;%(AdditionalIncludeDirectories) false ImTextureID=ImU64;_MBCS;%(PreprocessorDefinitions) + /utf-8 %(AdditionalOptions) true diff --git a/examples/example_glut_opengl2/example_glut_opengl2.vcxproj b/examples/example_glut_opengl2/example_glut_opengl2.vcxproj index 266ac04ed..c56452b26 100644 --- a/examples/example_glut_opengl2/example_glut_opengl2.vcxproj +++ b/examples/example_glut_opengl2/example_glut_opengl2.vcxproj @@ -91,6 +91,7 @@ Level4 Disabled $(GLUT_INCLUDE_DIR);..\..;..\..\backends;%(AdditionalIncludeDirectories) + /utf-8 %(AdditionalOptions) true @@ -105,6 +106,7 @@ Level4 Disabled $(GLUT_INCLUDE_DIR);..\..;..\..\backends;%(AdditionalIncludeDirectories) + /utf-8 %(AdditionalOptions) true @@ -122,6 +124,7 @@ true $(GLUT_INCLUDE_DIR);..\..;..\..\backends;%(AdditionalIncludeDirectories) false + /utf-8 %(AdditionalOptions) true @@ -142,6 +145,7 @@ true $(GLUT_INCLUDE_DIR);..\..;..\..\backends;%(AdditionalIncludeDirectories) false + /utf-8 %(AdditionalOptions) true diff --git a/examples/example_null/build_win32.bat b/examples/example_null/build_win32.bat index 0cdfdc93b..be81d8093 100644 --- a/examples/example_null/build_win32.bat +++ b/examples/example_null/build_win32.bat @@ -1,3 +1,3 @@ @REM Build for Visual Studio compiler. Run your copy of vcvars32.bat or vcvarsall.bat to setup command-line compiler. mkdir Debug -cl /nologo /Zi /MD /I ..\.. %* *.cpp ..\..\*.cpp /FeDebug/example_null.exe /FoDebug/ /link gdi32.lib shell32.lib imm32.lib +cl /nologo /Zi /MD /utf-8 /I ..\.. %* *.cpp ..\..\*.cpp /FeDebug/example_null.exe /FoDebug/ /link gdi32.lib shell32.lib imm32.lib diff --git a/examples/example_sdl2_directx11/build_win32.bat b/examples/example_sdl2_directx11/build_win32.bat index 54f30fc96..f0b485ca6 100644 --- a/examples/example_sdl2_directx11/build_win32.bat +++ b/examples/example_sdl2_directx11/build_win32.bat @@ -5,4 +5,4 @@ @set SOURCES=main.cpp ..\..\backends\imgui_impl_sdl2.cpp ..\..\backends\imgui_impl_dx11.cpp ..\..\imgui*.cpp @set LIBS=/LIBPATH:%SDL2_DIR%\lib\x86 SDL2.lib SDL2main.lib /LIBPATH:"%DXSDK_DIR%/Lib/x86" d3d11.lib d3dcompiler.lib shell32.lib mkdir %OUT_DIR% -cl /nologo /Zi /MD %INCLUDES% %SOURCES% /Fe%OUT_DIR%/%OUT_EXE%.exe /Fo%OUT_DIR%/ /link %LIBS% /subsystem:console +cl /nologo /Zi /MD /utf-8 %INCLUDES% %SOURCES% /Fe%OUT_DIR%/%OUT_EXE%.exe /Fo%OUT_DIR%/ /link %LIBS% /subsystem:console diff --git a/examples/example_sdl2_directx11/example_sdl2_directx11.vcxproj b/examples/example_sdl2_directx11/example_sdl2_directx11.vcxproj index e6a57f6cd..c23800c9e 100644 --- a/examples/example_sdl2_directx11/example_sdl2_directx11.vcxproj +++ b/examples/example_sdl2_directx11/example_sdl2_directx11.vcxproj @@ -92,6 +92,7 @@ Level4 Disabled ..\..;..\..\backends;%SDL2_DIR%\include;$(VcpkgCurrentInstalledDir)include\SDL2;%(AdditionalIncludeDirectories) + /utf-8 %(AdditionalOptions) true @@ -106,6 +107,7 @@ Level4 Disabled ..\..;..\..\backends;%SDL2_DIR%\include;$(VcpkgCurrentInstalledDir)include\SDL2;%(AdditionalIncludeDirectories) + /utf-8 %(AdditionalOptions) true @@ -123,6 +125,7 @@ true ..\..;..\..\backends;%SDL2_DIR%\include;$(VcpkgCurrentInstalledDir)include\SDL2;%(AdditionalIncludeDirectories) false + /utf-8 %(AdditionalOptions) true @@ -143,6 +146,7 @@ true ..\..;..\..\backends;%SDL2_DIR%\include;$(VcpkgCurrentInstalledDir)include\SDL2;%(AdditionalIncludeDirectories) false + /utf-8 %(AdditionalOptions) true diff --git a/examples/example_sdl2_opengl2/build_win32.bat b/examples/example_sdl2_opengl2/build_win32.bat index 287a418b7..7543edafc 100644 --- a/examples/example_sdl2_opengl2/build_win32.bat +++ b/examples/example_sdl2_opengl2/build_win32.bat @@ -5,4 +5,4 @@ @set SOURCES=main.cpp ..\..\backends\imgui_impl_sdl2.cpp ..\..\backends\imgui_impl_opengl2.cpp ..\..\imgui*.cpp @set LIBS=/LIBPATH:%SDL2_DIR%\lib\x86 SDL2.lib SDL2main.lib opengl32.lib shell32.lib mkdir %OUT_DIR% -cl /nologo /Zi /MD %INCLUDES% %SOURCES% /Fe%OUT_DIR%/%OUT_EXE%.exe /Fo%OUT_DIR%/ /link %LIBS% /subsystem:console +cl /nologo /Zi /MD /utf-8 %INCLUDES% %SOURCES% /Fe%OUT_DIR%/%OUT_EXE%.exe /Fo%OUT_DIR%/ /link %LIBS% /subsystem:console diff --git a/examples/example_sdl2_opengl2/example_sdl2_opengl2.vcxproj b/examples/example_sdl2_opengl2/example_sdl2_opengl2.vcxproj index 08a6df9b9..036463f96 100644 --- a/examples/example_sdl2_opengl2/example_sdl2_opengl2.vcxproj +++ b/examples/example_sdl2_opengl2/example_sdl2_opengl2.vcxproj @@ -91,6 +91,7 @@ Level4 Disabled ..\..;..\..\backends;%SDL2_DIR%\include;$(VcpkgCurrentInstalledDir)include\SDL2;%(AdditionalIncludeDirectories) + /utf-8 %(AdditionalOptions) true @@ -105,6 +106,7 @@ Level4 Disabled ..\..;..\..\backends;%SDL2_DIR%\include;$(VcpkgCurrentInstalledDir)include\SDL2;%(AdditionalIncludeDirectories) + /utf-8 %(AdditionalOptions) true @@ -122,6 +124,7 @@ true ..\..;..\..\backends;%SDL2_DIR%\include;$(VcpkgCurrentInstalledDir)include\SDL2;%(AdditionalIncludeDirectories) false + /utf-8 %(AdditionalOptions) true @@ -142,6 +145,7 @@ true ..\..;..\..\backends;%SDL2_DIR%\include;$(VcpkgCurrentInstalledDir)include\SDL2;%(AdditionalIncludeDirectories) false + /utf-8 %(AdditionalOptions) true diff --git a/examples/example_sdl2_opengl3/README.md b/examples/example_sdl2_opengl3/README.md index 9ecb9e90a..81fd9fe7b 100644 --- a/examples/example_sdl2_opengl3/README.md +++ b/examples/example_sdl2_opengl3/README.md @@ -10,10 +10,10 @@ Use the provided project file (.vcxproj). Add to solution (imgui_examples.sln) i Use build_win32.bat or directly: ``` set SDL2_DIR=path_to_your_sdl2_folder -cl /Zi /MD /I.. /I..\.. /I%SDL2_DIR%\include main.cpp ..\..\backends\imgui_impl_sdl2.cpp ..\..\backends\imgui_impl_opengl3.cpp ..\..\imgui*.cpp /FeDebug/example_sdl2_opengl3.exe /FoDebug/ /link /libpath:%SDL2_DIR%\lib\x86 SDL2.lib SDL2main.lib opengl32.lib /subsystem:console -# ^^ include paths ^^ source files ^^ output exe ^^ output dir ^^ libraries +cl /Zi /MD /utf-8 /I.. /I..\.. /I%SDL2_DIR%\include main.cpp ..\..\backends\imgui_impl_sdl2.cpp ..\..\backends\imgui_impl_opengl3.cpp ..\..\imgui*.cpp /FeDebug/example_sdl2_opengl3.exe /FoDebug/ /link /libpath:%SDL2_DIR%\lib\x86 SDL2.lib SDL2main.lib opengl32.lib /subsystem:console +# ^^ include paths ^^ source files ^^ output exe ^^ output dir ^^ libraries # or for 64-bit: -cl /Zi /MD /I.. /I..\.. /I%SDL2_DIR%\include main.cpp ..\..\backends\imgui_impl_sdl2.cpp ..\..\backends\imgui_impl_opengl3.cpp ..\..\imgui*.cpp /FeDebug/example_sdl2_opengl3.exe /FoDebug/ /link /libpath:%SDL2_DIR%\lib\x64 SDL2.lib SDL2main.lib opengl32.lib /subsystem:console +cl /Zi /MD /utf-8 /I.. /I..\.. /I%SDL2_DIR%\include main.cpp ..\..\backends\imgui_impl_sdl2.cpp ..\..\backends\imgui_impl_opengl3.cpp ..\..\imgui*.cpp /FeDebug/example_sdl2_opengl3.exe /FoDebug/ /link /libpath:%SDL2_DIR%\lib\x64 SDL2.lib SDL2main.lib opengl32.lib /subsystem:console ``` ## Linux and similar Unixes diff --git a/examples/example_sdl2_opengl3/build_win32.bat b/examples/example_sdl2_opengl3/build_win32.bat index abbf3c78b..7b2fac922 100644 --- a/examples/example_sdl2_opengl3/build_win32.bat +++ b/examples/example_sdl2_opengl3/build_win32.bat @@ -5,4 +5,4 @@ @set SOURCES=main.cpp ..\..\backends\imgui_impl_sdl2.cpp ..\..\backends\imgui_impl_opengl3.cpp ..\..\imgui*.cpp @set LIBS=/LIBPATH:%SDL2_DIR%\lib\x86 SDL2.lib SDL2main.lib opengl32.lib shell32.lib mkdir %OUT_DIR% -cl /nologo /Zi /MD %INCLUDES% %SOURCES% /Fe%OUT_DIR%/%OUT_EXE%.exe /Fo%OUT_DIR%/ /link %LIBS% /subsystem:console +cl /nologo /Zi /MD /utf-8 %INCLUDES% %SOURCES% /Fe%OUT_DIR%/%OUT_EXE%.exe /Fo%OUT_DIR%/ /link %LIBS% /subsystem:console diff --git a/examples/example_sdl2_opengl3/example_sdl2_opengl3.vcxproj b/examples/example_sdl2_opengl3/example_sdl2_opengl3.vcxproj index 21ce0693d..6a81c6770 100644 --- a/examples/example_sdl2_opengl3/example_sdl2_opengl3.vcxproj +++ b/examples/example_sdl2_opengl3/example_sdl2_opengl3.vcxproj @@ -91,6 +91,7 @@ Level4 Disabled ..\..;..\..\backends;%SDL2_DIR%\include;$(VcpkgCurrentInstalledDir)include\SDL2;%(AdditionalIncludeDirectories) + /utf-8 %(AdditionalOptions) true @@ -105,6 +106,7 @@ Level4 Disabled ..\..;..\..\backends;%SDL2_DIR%\include;$(VcpkgCurrentInstalledDir)include\SDL2;%(AdditionalIncludeDirectories) + /utf-8 %(AdditionalOptions) true @@ -122,6 +124,7 @@ true ..\..;..\..\backends;%SDL2_DIR%\include;$(VcpkgCurrentInstalledDir)include\SDL2;%(AdditionalIncludeDirectories) false + /utf-8 %(AdditionalOptions) true @@ -142,6 +145,7 @@ true ..\..;..\..\backends;%SDL2_DIR%\include;$(VcpkgCurrentInstalledDir)include\SDL2;%(AdditionalIncludeDirectories) false + /utf-8 %(AdditionalOptions) true diff --git a/examples/example_sdl2_sdlrenderer/README.md b/examples/example_sdl2_sdlrenderer/README.md index 4fa37433c..0445bc4d9 100644 --- a/examples/example_sdl2_sdlrenderer/README.md +++ b/examples/example_sdl2_sdlrenderer/README.md @@ -5,10 +5,10 @@ ``` set SDL2_DIR=path_to_your_sdl2_folder -cl /Zi /MD /I.. /I..\.. /I%SDL2_DIR%\include main.cpp ..\..\backends\imgui_impl_sdl2.cpp ..\..\backends\imgui_impl_sdlrenderer.cpp ..\..\imgui*.cpp /FeDebug/example_sdl2_sdlrenderer.exe /FoDebug/ /link /libpath:%SDL2_DIR%\lib\x86 SDL2.lib SDL2main.lib /subsystem:console -# ^^ include paths ^^ source files ^^ output exe ^^ output dir ^^ libraries +cl /Zi /MD /utf-8 /I.. /I..\.. /I%SDL2_DIR%\include main.cpp ..\..\backends\imgui_impl_sdl2.cpp ..\..\backends\imgui_impl_sdlrenderer.cpp ..\..\imgui*.cpp /FeDebug/example_sdl2_sdlrenderer.exe /FoDebug/ /link /libpath:%SDL2_DIR%\lib\x86 SDL2.lib SDL2main.lib /subsystem:console +# ^^ include paths ^^ source files ^^ output exe ^^ output dir ^^ libraries # or for 64-bit: -cl /Zi /MD /I.. /I..\.. /I%SDL2_DIR%\include main.cpp ..\..\backends\imgui_impl_sdl2.cpp ..\..\backends\imgui_impl_sdlrenderer.cpp ..\..\imgui*.cpp /FeDebug/example_sdl2_sdlrenderer.exe /FoDebug/ /link /libpath:%SDL2_DIR%\lib\x64 SDL2.lib SDL2main.lib /subsystem:console +cl /Zi /MD /utf-8 /I.. /I..\.. /I%SDL2_DIR%\include main.cpp ..\..\backends\imgui_impl_sdl2.cpp ..\..\backends\imgui_impl_sdlrenderer.cpp ..\..\imgui*.cpp /FeDebug/example_sdl2_sdlrenderer.exe /FoDebug/ /link /libpath:%SDL2_DIR%\lib\x64 SDL2.lib SDL2main.lib /subsystem:console ``` - On Linux and similar Unixes diff --git a/examples/example_sdl2_sdlrenderer/build_win32.bat b/examples/example_sdl2_sdlrenderer/build_win32.bat index 1bae121bb..ca3f650cc 100644 --- a/examples/example_sdl2_sdlrenderer/build_win32.bat +++ b/examples/example_sdl2_sdlrenderer/build_win32.bat @@ -5,4 +5,4 @@ @set SOURCES=main.cpp ..\..\backends\imgui_impl_sdl2.cpp ..\..\backends\imgui_impl_sdlrenderer.cpp ..\..\imgui*.cpp @set LIBS=/LIBPATH:%SDL2_DIR%\lib\x86 SDL2.lib SDL2main.lib mkdir %OUT_DIR% -cl /nologo /Zi /MD %INCLUDES% %SOURCES% /Fe%OUT_DIR%/%OUT_EXE%.exe /Fo%OUT_DIR%/ /link %LIBS% /subsystem:console +cl /nologo /Zi /MD /utf-8 %INCLUDES% %SOURCES% /Fe%OUT_DIR%/%OUT_EXE%.exe /Fo%OUT_DIR%/ /link %LIBS% /subsystem:console diff --git a/examples/example_sdl2_sdlrenderer/example_sdl2_sdlrenderer.vcxproj b/examples/example_sdl2_sdlrenderer/example_sdl2_sdlrenderer.vcxproj index 35bcfe2ed..fdc85d8c3 100644 --- a/examples/example_sdl2_sdlrenderer/example_sdl2_sdlrenderer.vcxproj +++ b/examples/example_sdl2_sdlrenderer/example_sdl2_sdlrenderer.vcxproj @@ -91,6 +91,7 @@ Level4 Disabled ..\..;..\..\backends;%SDL2_DIR%\include;%(AdditionalIncludeDirectories) + /utf-8 %(AdditionalOptions) true @@ -105,6 +106,7 @@ Level4 Disabled ..\..;..\..\backends;%SDL2_DIR%\include;%(AdditionalIncludeDirectories) + /utf-8 %(AdditionalOptions) true @@ -122,6 +124,7 @@ true ..\..;..\..\backends;%SDL2_DIR%\include;%(AdditionalIncludeDirectories) false + /utf-8 %(AdditionalOptions) true @@ -142,6 +145,7 @@ true ..\..;..\..\backends;%SDL2_DIR%\include;%(AdditionalIncludeDirectories) false + /utf-8 %(AdditionalOptions) true diff --git a/examples/example_sdl2_vulkan/build_win32.bat b/examples/example_sdl2_vulkan/build_win32.bat index 5bc519856..8a4aefc22 100644 --- a/examples/example_sdl2_vulkan/build_win32.bat +++ b/examples/example_sdl2_vulkan/build_win32.bat @@ -7,4 +7,4 @@ @set OUT_DIR=Debug mkdir %OUT_DIR% -cl /nologo /Zi /MD %INCLUDES% /D ImTextureID=ImU64 %SOURCES% /Fe%OUT_DIR%/%OUT_EXE%.exe /Fo%OUT_DIR%/ /link %LIBS% /subsystem:console +cl /nologo /Zi /MD /utf-8 %INCLUDES% /D ImTextureID=ImU64 %SOURCES% /Fe%OUT_DIR%/%OUT_EXE%.exe /Fo%OUT_DIR%/ /link %LIBS% /subsystem:console diff --git a/examples/example_sdl2_vulkan/example_sdl2_vulkan.vcxproj b/examples/example_sdl2_vulkan/example_sdl2_vulkan.vcxproj index e5cbdc363..ba6afaf72 100644 --- a/examples/example_sdl2_vulkan/example_sdl2_vulkan.vcxproj +++ b/examples/example_sdl2_vulkan/example_sdl2_vulkan.vcxproj @@ -92,6 +92,7 @@ Disabled ..\..;..\..\backends;%VULKAN_SDK%\include;%SDL2_DIR%\include;$(VcpkgCurrentInstalledDir)include\SDL2;%(AdditionalIncludeDirectories) ImTextureID=ImU64;_MBCS;%(PreprocessorDefinitions) + /utf-8 %(AdditionalOptions) true @@ -107,6 +108,7 @@ Disabled ..\..;..\..\backends;%VULKAN_SDK%\include;%SDL2_DIR%\include;$(VcpkgCurrentInstalledDir)include\SDL2;%(AdditionalIncludeDirectories) ImTextureID=ImU64;_MBCS;%(PreprocessorDefinitions) + /utf-8 %(AdditionalOptions) true @@ -125,6 +127,7 @@ ..\..;..\..\backends;%VULKAN_SDK%\include;%SDL2_DIR%\include;$(VcpkgCurrentInstalledDir)include\SDL2;%(AdditionalIncludeDirectories) false ImTextureID=ImU64;_MBCS;%(PreprocessorDefinitions) + /utf-8 %(AdditionalOptions) true @@ -146,6 +149,7 @@ ..\..;..\..\backends;%VULKAN_SDK%\include;%SDL2_DIR%\include;$(VcpkgCurrentInstalledDir)include\SDL2;%(AdditionalIncludeDirectories) false ImTextureID=ImU64;_MBCS;%(PreprocessorDefinitions) + /utf-8 %(AdditionalOptions) true diff --git a/examples/example_sdl3_opengl3/README.md b/examples/example_sdl3_opengl3/README.md index 8b137b166..ab7f8e995 100644 --- a/examples/example_sdl3_opengl3/README.md +++ b/examples/example_sdl3_opengl3/README.md @@ -10,10 +10,10 @@ Use the provided project file (.vcxproj). Add to solution (imgui_examples.sln) i Use build_win32.bat or directly: ``` set SDL2_DIR=path_to_your_sdl3_folder -cl /Zi /MD /I.. /I..\.. /I%SDL2_DIR%\include main.cpp ..\..\backends\imgui_impl_sdl3.cpp ..\..\backends\imgui_impl_opengl3.cpp ..\..\imgui*.cpp /FeDebug/example_sdl3_opengl3.exe /FoDebug/ /link /libpath:%SDL2_DIR%\lib\x86 SDL3.lib opengl32.lib /subsystem:console -# ^^ include paths ^^ source files ^^ output exe ^^ output dir ^^ libraries +cl /Zi /MD /utf-8 /I.. /I..\.. /I%SDL2_DIR%\include main.cpp ..\..\backends\imgui_impl_sdl3.cpp ..\..\backends\imgui_impl_opengl3.cpp ..\..\imgui*.cpp /FeDebug/example_sdl3_opengl3.exe /FoDebug/ /link /libpath:%SDL2_DIR%\lib\x86 SDL3.lib opengl32.lib /subsystem:console +# ^^ include paths ^^ source files ^^ output exe ^^ output dir ^^ libraries # or for 64-bit: -cl /Zi /MD /I.. /I..\.. /I%SDL2_DIR%\include main.cpp ..\..\backends\imgui_impl_sdl3.cpp ..\..\backends\imgui_impl_opengl3.cpp ..\..\imgui*.cpp /FeDebug/example_sdl3_opengl3.exe /FoDebug/ /link /libpath:%SDL2_DIR%\lib\x64 SDL3.lib SDL2mainopengl32.lib /subsystem:console +cl /Zi /MD /utf-8 /I.. /I..\.. /I%SDL2_DIR%\include main.cpp ..\..\backends\imgui_impl_sdl3.cpp ..\..\backends\imgui_impl_opengl3.cpp ..\..\imgui*.cpp /FeDebug/example_sdl3_opengl3.exe /FoDebug/ /link /libpath:%SDL2_DIR%\lib\x64 SDL3.lib SDL2mainopengl32.lib /subsystem:console ``` ## Linux and similar Unixes diff --git a/examples/example_sdl3_opengl3/build_win32.bat b/examples/example_sdl3_opengl3/build_win32.bat index ba7d25bcc..5b8d5f871 100644 --- a/examples/example_sdl3_opengl3/build_win32.bat +++ b/examples/example_sdl3_opengl3/build_win32.bat @@ -5,4 +5,4 @@ @set SOURCES=main.cpp ..\..\backends\imgui_impl_sdl3.cpp ..\..\backends\imgui_impl_opengl3.cpp ..\..\imgui*.cpp @set LIBS=/LIBPATH:%SDL3_DIR%\lib\x86 SDL3.lib opengl32.lib shell32.lib mkdir %OUT_DIR% -cl /nologo /Zi /MD %INCLUDES% %SOURCES% /Fe%OUT_DIR%/%OUT_EXE%.exe /Fo%OUT_DIR%/ /link %LIBS% /subsystem:console +cl /nologo /Zi /MD /utf-8 %INCLUDES% %SOURCES% /Fe%OUT_DIR%/%OUT_EXE%.exe /Fo%OUT_DIR%/ /link %LIBS% /subsystem:console diff --git a/examples/example_sdl3_opengl3/example_sdl3_opengl3.vcxproj b/examples/example_sdl3_opengl3/example_sdl3_opengl3.vcxproj index a29e3afd2..051f87d76 100644 --- a/examples/example_sdl3_opengl3/example_sdl3_opengl3.vcxproj +++ b/examples/example_sdl3_opengl3/example_sdl3_opengl3.vcxproj @@ -91,6 +91,7 @@ Level4 Disabled ..\..;..\..\backends;%SDL3_DIR%\include;$(VcpkgCurrentInstalledDir)include\SDL3;%(AdditionalIncludeDirectories) + /utf-8 %(AdditionalOptions) true @@ -105,6 +106,7 @@ Level4 Disabled ..\..;..\..\backends;%SDL3_DIR%\include;$(VcpkgCurrentInstalledDir)include\SDL3;%(AdditionalIncludeDirectories) + /utf-8 %(AdditionalOptions) true @@ -122,6 +124,7 @@ true ..\..;..\..\backends;%SDL3_DIR%\include;$(VcpkgCurrentInstalledDir)include\SDL3;%(AdditionalIncludeDirectories) false + /utf-8 %(AdditionalOptions) true @@ -142,6 +145,7 @@ true ..\..;..\..\backends;%SDL3_DIR%\include;$(VcpkgCurrentInstalledDir)include\SDL3;%(AdditionalIncludeDirectories) false + /utf-8 %(AdditionalOptions) true diff --git a/examples/example_win32_directx10/build_win32.bat b/examples/example_win32_directx10/build_win32.bat index fd742239c..78a6e374d 100644 --- a/examples/example_win32_directx10/build_win32.bat +++ b/examples/example_win32_directx10/build_win32.bat @@ -5,4 +5,4 @@ @set SOURCES=main.cpp ..\..\backends\imgui_impl_win32.cpp ..\..\backends\imgui_impl_dx10.cpp ..\..\imgui*.cpp @set LIBS=/LIBPATH:"%DXSDK_DIR%/Lib/x86" d3d10.lib d3dcompiler.lib mkdir %OUT_DIR% -cl /nologo /Zi /MD %INCLUDES% /D UNICODE /D _UNICODE %SOURCES% /Fe%OUT_DIR%/%OUT_EXE%.exe /Fo%OUT_DIR%/ /link %LIBS% +cl /nologo /Zi /MD /utf-8 %INCLUDES% /D UNICODE /D _UNICODE %SOURCES% /Fe%OUT_DIR%/%OUT_EXE%.exe /Fo%OUT_DIR%/ /link %LIBS% diff --git a/examples/example_win32_directx10/example_win32_directx10.vcxproj b/examples/example_win32_directx10/example_win32_directx10.vcxproj index 2dc2333e0..d11aed883 100644 --- a/examples/example_win32_directx10/example_win32_directx10.vcxproj +++ b/examples/example_win32_directx10/example_win32_directx10.vcxproj @@ -87,6 +87,7 @@ Level4 Disabled ..\..;..\..\backends;%(AdditionalIncludeDirectories); + /utf-8 %(AdditionalOptions) true @@ -100,6 +101,7 @@ Level4 Disabled ..\..;..\..\backends;%(AdditionalIncludeDirectories); + /utf-8 %(AdditionalOptions) true @@ -116,6 +118,7 @@ true ..\..;..\..\backends;%(AdditionalIncludeDirectories); false + /utf-8 %(AdditionalOptions) true @@ -134,6 +137,7 @@ true ..\..;..\..\backends;%(AdditionalIncludeDirectories); false + /utf-8 %(AdditionalOptions) true diff --git a/examples/example_win32_directx11/build_win32.bat b/examples/example_win32_directx11/build_win32.bat index b1cf7d1cb..c9a717c60 100644 --- a/examples/example_win32_directx11/build_win32.bat +++ b/examples/example_win32_directx11/build_win32.bat @@ -5,5 +5,5 @@ @set SOURCES=main.cpp ..\..\backends\imgui_impl_dx11.cpp ..\..\backends\imgui_impl_win32.cpp ..\..\imgui*.cpp @set LIBS=/LIBPATH:"%DXSDK_DIR%/Lib/x86" d3d11.lib d3dcompiler.lib mkdir %OUT_DIR% -cl /nologo /Zi /MD %INCLUDES% /D UNICODE /D _UNICODE %SOURCES% /Fe%OUT_DIR%/%OUT_EXE%.exe /Fo%OUT_DIR%/ /link %LIBS% +cl /nologo /Zi /MD /utf-8 %INCLUDES% /D UNICODE /D _UNICODE %SOURCES% /Fe%OUT_DIR%/%OUT_EXE%.exe /Fo%OUT_DIR%/ /link %LIBS% diff --git a/examples/example_win32_directx11/example_win32_directx11.vcxproj b/examples/example_win32_directx11/example_win32_directx11.vcxproj index 3264f5095..bace6a2c8 100644 --- a/examples/example_win32_directx11/example_win32_directx11.vcxproj +++ b/examples/example_win32_directx11/example_win32_directx11.vcxproj @@ -86,6 +86,7 @@ Level4 Disabled ..\..;..\..\backends;%(AdditionalIncludeDirectories); + /utf-8 %(AdditionalOptions) true @@ -99,6 +100,7 @@ Level4 Disabled ..\..;..\..\backends;%(AdditionalIncludeDirectories); + /utf-8 %(AdditionalOptions) true @@ -115,6 +117,7 @@ true ..\..;..\..\backends;%(AdditionalIncludeDirectories); false + /utf-8 %(AdditionalOptions) true @@ -133,6 +136,7 @@ true ..\..;..\..\backends;%(AdditionalIncludeDirectories); false + /utf-8 %(AdditionalOptions) true diff --git a/examples/example_win32_directx11/main.cpp b/examples/example_win32_directx11/main.cpp index c242a4ccb..d4d330575 100644 --- a/examples/example_win32_directx11/main.cpp +++ b/examples/example_win32_directx11/main.cpp @@ -1,4 +1,4 @@ -// Dear ImGui: standalone example application for DirectX 11 +// Dear ImGui: standalone example application for DirectX 11 // If you are new to Dear ImGui, read documentation from the docs/ folder + read the top of imgui.cpp. // Read online: https://github.com/ocornut/imgui/tree/master/docs @@ -26,7 +26,7 @@ LRESULT WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); int main(int, char**) { // Create application window - //ImGui_ImplWin32_EnableDpiAwareness(); + ImGui_ImplWin32_EnableDpiAwareness(); WNDCLASSEXW wc = { sizeof(wc), CS_CLASSDC, WndProc, 0L, 0L, GetModuleHandle(nullptr), nullptr, nullptr, nullptr, nullptr, L"ImGui Example", nullptr }; ::RegisterClassExW(&wc); HWND hwnd = ::CreateWindowW(wc.lpszClassName, L"Dear ImGui DirectX11 Example", WS_OVERLAPPEDWINDOW, 100, 100, 1280, 800, nullptr, nullptr, wc.hInstance, nullptr); @@ -71,7 +71,7 @@ int main(int, char**) //io.Fonts->AddFontFromFileTTF("../../misc/fonts/DroidSans.ttf", 16.0f); //io.Fonts->AddFontFromFileTTF("../../misc/fonts/Roboto-Medium.ttf", 16.0f); //io.Fonts->AddFontFromFileTTF("../../misc/fonts/Cousine-Regular.ttf", 15.0f); - //ImFont* font = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, nullptr, io.Fonts->GetGlyphRangesJapanese()); + ImFont* font = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, nullptr, io.Fonts->GetGlyphRangesJapanese()); //IM_ASSERT(font != nullptr); // Our state @@ -114,6 +114,12 @@ int main(int, char**) if (show_demo_window) ImGui::ShowDemoWindow(&show_demo_window); + ImGui::SeparatorText("CORRECT"); + ImGui::DebugTextEncoding(u8"こんにちは"); + + ImGui::SeparatorText("INCORRECT"); + ImGui::DebugTextEncoding("こんにちは"); + // 2. Show a simple window that we create ourselves. We use a Begin/End pair to create a named window. { static float f = 0.0f; @@ -121,6 +127,13 @@ int main(int, char**) ImGui::Begin("Hello, world!"); // Create a window called "Hello, world!" and append into it. +#define U8(_S) (const char*)u8##_S + ImGui::Text(U8("こんにちは")); + +//#pragma execution_character_set("utf-8") + + ImGui::Text("日本語"); + ImGui::Text("This is some useful text."); // Display some text (you can use a format strings too) ImGui::Checkbox("Demo Window", &show_demo_window); // Edit bools storing our window open/close state ImGui::Checkbox("Another Window", &show_another_window); diff --git a/examples/example_win32_directx12/build_win32.bat b/examples/example_win32_directx12/build_win32.bat index 48dadb299..68e3c921e 100644 --- a/examples/example_win32_directx12/build_win32.bat +++ b/examples/example_win32_directx12/build_win32.bat @@ -6,4 +6,4 @@ @set SOURCES=main.cpp ..\..\backends\imgui_impl_dx12.cpp ..\..\backends\imgui_impl_win32.cpp ..\..\imgui*.cpp @set LIBS=d3d12.lib d3dcompiler.lib dxgi.lib mkdir Debug -cl /nologo /Zi /MD %INCLUDES% /D ImTextureID=ImU64 /D UNICODE /D _UNICODE %SOURCES% /Fe%OUT_DIR%/%OUT_EXE%.exe /Fo%OUT_DIR%/ /link %LIBS% +cl /nologo /Zi /MD /utf-8 %INCLUDES% /D ImTextureID=ImU64 /D UNICODE /D _UNICODE %SOURCES% /Fe%OUT_DIR%/%OUT_EXE%.exe /Fo%OUT_DIR%/ /link %LIBS% diff --git a/examples/example_win32_directx12/example_win32_directx12.vcxproj b/examples/example_win32_directx12/example_win32_directx12.vcxproj index 9e0737747..7b64371ef 100644 --- a/examples/example_win32_directx12/example_win32_directx12.vcxproj +++ b/examples/example_win32_directx12/example_win32_directx12.vcxproj @@ -88,6 +88,7 @@ Disabled ..\..;..\..\backends;%(AdditionalIncludeDirectories) ImTextureID=ImU64;_UNICODE;UNICODE;%(PreprocessorDefinitions) + /utf-8 %(AdditionalOptions) true @@ -102,6 +103,7 @@ Disabled ..\..;..\..\backends;%(AdditionalIncludeDirectories) ImTextureID=ImU64;_UNICODE;UNICODE;%(PreprocessorDefinitions) + /utf-8 %(AdditionalOptions) true @@ -118,6 +120,7 @@ true ..\..;..\..\backends;%(AdditionalIncludeDirectories) ImTextureID=ImU64;_UNICODE;UNICODE;%(PreprocessorDefinitions) + /utf-8 %(AdditionalOptions) true @@ -136,6 +139,7 @@ true ..\..;..\..\backends;%(AdditionalIncludeDirectories) ImTextureID=ImU64;_UNICODE;UNICODE;%(PreprocessorDefinitions) + /utf-8 %(AdditionalOptions) true diff --git a/examples/example_win32_directx9/build_win32.bat b/examples/example_win32_directx9/build_win32.bat index bbd4b13ca..ece5ea1ba 100644 --- a/examples/example_win32_directx9/build_win32.bat +++ b/examples/example_win32_directx9/build_win32.bat @@ -5,4 +5,4 @@ @set SOURCES=main.cpp ..\..\backends\imgui_impl_dx9.cpp ..\..\backends\imgui_impl_win32.cpp ..\..\imgui*.cpp @set LIBS=/LIBPATH:"%DXSDK_DIR%/Lib/x86" d3d9.lib mkdir %OUT_DIR% -cl /nologo /Zi /MD %INCLUDES% /D UNICODE /D _UNICODE %SOURCES% /Fe%OUT_DIR%/%OUT_EXE%.exe /Fo%OUT_DIR%/ /link %LIBS% +cl /nologo /Zi /MD /utf-8 %INCLUDES% /D UNICODE /D _UNICODE %SOURCES% /Fe%OUT_DIR%/%OUT_EXE%.exe /Fo%OUT_DIR%/ /link %LIBS% diff --git a/examples/example_win32_directx9/example_win32_directx9.vcxproj b/examples/example_win32_directx9/example_win32_directx9.vcxproj index 44be2247b..8c3f99589 100644 --- a/examples/example_win32_directx9/example_win32_directx9.vcxproj +++ b/examples/example_win32_directx9/example_win32_directx9.vcxproj @@ -87,6 +87,7 @@ Level4 Disabled ..\..;..\..\backends;%(AdditionalIncludeDirectories);$(DXSDK_DIR)Include; + /utf-8 %(AdditionalOptions) true @@ -100,6 +101,7 @@ Level4 Disabled ..\..;..\..\backends;%(AdditionalIncludeDirectories);$(DXSDK_DIR)Include; + /utf-8 %(AdditionalOptions) true @@ -116,6 +118,7 @@ true ..\..;..\..\backends;%(AdditionalIncludeDirectories);$(DXSDK_DIR)Include; false + /utf-8 %(AdditionalOptions) true @@ -134,6 +137,7 @@ true ..\..;..\..\backends;%(AdditionalIncludeDirectories);$(DXSDK_DIR)Include; false + /utf-8 %(AdditionalOptions) true diff --git a/examples/example_win32_opengl3/build_win32.bat b/examples/example_win32_opengl3/build_win32.bat index 91cc6bec0..48df08087 100644 --- a/examples/example_win32_opengl3/build_win32.bat +++ b/examples/example_win32_opengl3/build_win32.bat @@ -5,4 +5,4 @@ @set SOURCES=main.cpp ..\..\backends\imgui_impl_opengl3.cpp ..\..\backends\imgui_impl_win32.cpp ..\..\imgui*.cpp @set LIBS=opengl32.lib mkdir %OUT_DIR% -cl /nologo /Zi /MD %INCLUDES% /D UNICODE /D _UNICODE %SOURCES% /Fe%OUT_DIR%/%OUT_EXE%.exe /Fo%OUT_DIR%/ /link %LIBS% +cl /nologo /Zi /MD /utf-8 %INCLUDES% /D UNICODE /D _UNICODE %SOURCES% /Fe%OUT_DIR%/%OUT_EXE%.exe /Fo%OUT_DIR%/ /link %LIBS% diff --git a/examples/example_win32_opengl3/example_win32_opengl3.vcxproj b/examples/example_win32_opengl3/example_win32_opengl3.vcxproj index 49023e3dc..98fc38fd3 100644 --- a/examples/example_win32_opengl3/example_win32_opengl3.vcxproj +++ b/examples/example_win32_opengl3/example_win32_opengl3.vcxproj @@ -87,6 +87,7 @@ Level4 Disabled ..\..;..\..\backends; + /utf-8 %(AdditionalOptions) true @@ -100,6 +101,7 @@ Level4 Disabled ..\..;..\..\backends; + /utf-8 %(AdditionalOptions) true @@ -116,6 +118,7 @@ true ..\..;..\..\backends; false + /utf-8 %(AdditionalOptions) true @@ -134,6 +137,7 @@ true ..\..;..\..\backends; false + /utf-8 %(AdditionalOptions) true From 430c05991c15eb1501ee293fbc8f43ee13843b68 Mon Sep 17 00:00:00 2001 From: ocornut Date: Wed, 10 May 2023 12:54:51 +0200 Subject: [PATCH 14/14] Docs: added more detailed information about UTF-8 encoding. + Revert mistakenly committed Win32+DX11 main.cpp from last commit. --- docs/FAQ.md | 9 +- docs/FONTS.md | 135 +++++++++++++++------- examples/example_win32_directx11/main.cpp | 19 +-- imgui.cpp | 2 +- imgui.h | 3 +- 5 files changed, 104 insertions(+), 64 deletions(-) diff --git a/docs/FAQ.md b/docs/FAQ.md index 20aa9a732..7e6ad7b57 100644 --- a/docs/FAQ.md +++ b/docs/FAQ.md @@ -628,10 +628,11 @@ builder.BuildRanges(&ranges); // Build the final result io.Fonts->AddFontFromFileTTF("myfontfile.ttf", 16.0f, nullptr, ranges.Data); ``` -All your strings need to use UTF-8 encoding. In C++11 you can encode a string literal in UTF-8 -by using the u8"hello" syntax. Specifying literal in your source code using a local code page -(such as CP-923 for Japanese or CP-1251 for Cyrillic) will NOT work! -Otherwise, you can convert yourself to UTF-8 or load text data from a file already saved as UTF-8. +All your strings need to use UTF-8 encoding. +You need to tell your compiler to use UTF-8, or in C++11 you can encode a string literal in UTF-8 by using the u8"hello" syntax. +Specifying literal in your source code using a local code page (such as CP-923 for Japanese or CP-1251 for Cyrillic) will NOT work! +See [About UTF-8 Encoding](https://github.com/ocornut/imgui/blob/master/docs/FONTS.md#about-utf-8-encoding) section +of [FONTS.md](https://github.com/ocornut/imgui/blob/master/docs/FONTS.md) for details about UTF-8 Encoding. Text input: it is up to your application to pass the right character code by calling `io.AddInputCharacter()`. The applications in examples/ are doing that. diff --git a/docs/FONTS.md b/docs/FONTS.md index ff62733b2..6049fb48f 100644 --- a/docs/FONTS.md +++ b/docs/FONTS.md @@ -12,41 +12,118 @@ In the [misc/fonts/](https://github.com/ocornut/imgui/tree/master/misc/fonts) fo ## Index - [Readme First](#readme-first) +- [About Filenames](#about-filenames) +- [About UTF-8 Encoding](#about-utf-8-encoding) +- [Debug Tools](#debug-tools) - [How should I handle DPI in my application?](#how-should-i-handle-dpi-in-my-application) -- [Fonts Loading Instructions](#font-loading-instructions) +- [Fonts Loading Instructions](#fonts-loading-instructions) - [Using Icon Fonts](#using-icon-fonts) - [Using FreeType Rasterizer (imgui_freetype)](#using-freetype-rasterizer-imgui_freetype) - [Using Colorful Glyphs/Emojis](#using-colorful-glyphsemojis) - [Using Custom Glyph Ranges](#using-custom-glyph-ranges) - [Using Custom Colorful Icons](#using-custom-colorful-icons) - [Using Font Data Embedded In Source Code](#using-font-data-embedded-in-source-code) -- [About filenames](#about-filenames) - [Credits/Licenses For Fonts Included In Repository](#creditslicenses-for-fonts-included-in-repository) - [Font Links](#font-links) --------------------------------------- - ## Readme First -- You can use the `Metrics/Debugger` window (available in `Demo>Tools`) to browse your fonts and understand what's going on if you have an issue. You can also reach it in `Demo->Tools->Style Editor->Fonts`. The same information are also available in the Style Editor under Fonts. +## Readme First + +**A vast majority of font and text related issues encountered comes from 3 things:** +- Invalid filename due to use of `\` or unexpected working directory. See [About Filenames](#about-filenames). AddFontXXX functions should assert if the filename is incorrect. +- Invalid UTF-8 encoding of your non-ASCII strings. See [About UTF-8 Encoding](#about-utf-8-encoding). Use the encoding viewer to confirm yours is correct. +- You need to load a font with explicit glyph ranges if you want to use non-ASCII characters. See [Fonts Loading Instructions](#fonts-loading-instructions). Use Metrics/Debugger->Fonts to confirm loaded fonts and loaded glyph ranges. + +The third point is a current constraint of Dear ImGui (which we will lift in the future): when loading a font you need to specify which characters glyphs to load. +All loaded fonts glyphs are rendered into a single texture atlas ahead of time. Calling either of `io.Fonts->GetTexDataAsAlpha8()`, `io.Fonts->GetTexDataAsRGBA32()` or `io.Fonts->Build()` will build the atlas. This is generally called by the Renderer backend, e.g. `ImGui_ImplDX11_NewFrame()` calls it. + +**If you use custom glyphs ranges, make sure the array is persistent** and available during the calls to `GetTexDataAsAlpha8()/GetTexDataAsRGBA32()/Build()`. + +##### [Return to Index](#index) + +## About Filenames + +**Please note that many new C/C++ users have issues loading their files _because the filename they provide is wrong_ due to incorrect assumption of what is the current directory.** + +Two things to watch for: + +(1) In C/C++ and most programming languages if you want to use a backslash `\` within a string literal, you need to write it double backslash `\\`. At it happens, Windows uses backslashes as a path separator, so be mindful. +```cpp +io.Fonts->AddFontFromFileTTF("MyFiles\MyImage01.jpg", ...); // This is INCORRECT!! +io.Fonts->AddFontFromFileTTF("MyFiles\\MyImage01.jpg", ...); // This is CORRECT +``` +In some situations, you may also use `/` path separator under Windows. + +(2) Make sure your IDE/debugger settings starts your executable from the right working (current) directory. In Visual Studio you can change your working directory in project `Properties > General > Debugging > Working Directory`. People assume that their execution will start from the root folder of the project, where by default it often starts from the folder where object or executable files are stored. +```cpp +io.Fonts->AddFontFromFileTTF("MyImage01.jpg", ...); // Relative filename depends on your Working Directory when running your program! +io.Fonts->AddFontFromFileTTF("../MyImage01.jpg", ...); // Load from the parent folder of your Working Directory +``` +##### [Return to Index](#index) + + +## About UTF-8 Encoding + +**For non-ASCII characters display, a common user issue is not passing correctly UTF-8 encoded strings.** + +(1) We provide a function `ImGui::DebugTextEncoding(const char* text)` which you can call to verify the content of your UTF-8 strings. +This is a convenient way to confirm that your encoding is correct. + +```cpp +ImGui::SeparatorText("CORRECT"); +ImGui::DebugTextEncoding(u8"こんにちは"); + +ImGui::SeparatorText("INCORRECT"); +ImGui::DebugTextEncoding("こんにちは"); +``` +![UTF-8 Encoding viewer](https://github.com/ocornut/imgui/assets/8225057/61c1696a-9a94-46c5-9627-cf91211111f0) + +You can also find this tool under `Metrics/Debuggers->Tools->UTF-8 Encoding viewer` if you want to paste from clipboard, but this won't validate the UTF-8 encoding done by your compiler. + +(2) To encode in UTF-8: + +There are also compiler-specific ways to enforce UTF-8 encoding by default: + +- Visual Studio compiler: `/utf-8` command-line flag. +- Visual Studio compiler: `#pragma execution_character_set("utf-8")` inside your code. +- Since May 2023 we have changed the Visual Studio projects of all our examples to use `/utf-8` ([see commit](https://github.com/ocornut/imgui/commit/513af1efc9080857bbd10000d98f98f2a0c96803)). + +Or, since C++11, you can use the `u8"my text"` syntax to encode literal strings as UTF-8. e.g.: +```cpp +ImGui::Text(u8"hello"); +ImGui::Text(u8"こんにちは"); // this will always be encoded as UTF-8 +ImGui::Text("こんにちは"); // the encoding of this is depending on compiler settings/flags and may be incorrect. +``` + +Since C++20, because the C++ committee hate its users, they decided to change the `u8""` syntax to not return `const char*` but a new type `const char_t*` which doesn't cast to `const char*`. +Because of type usage of `u8""` in C++20 is a little more tedious: +```cpp +ImGui::Text((const char*)u8"こんにちは"); +``` +We suggest using a macro in your codebase: +```cpp +#define U8(_S) (const char*)u8##_S +ImGui::Text(U8("こんにちは")); +``` +##### [Return to Index](#index) + + +## Debug Tools + +#### Metrics/Debugger->Fonts +You can use the `Metrics/Debugger` window (available in `Demo>Tools`) to browse your fonts and understand what's going on if you have an issue. You can also reach it in `Demo->Tools->Style Editor->Fonts`. The same information are also available in the Style Editor under Fonts. ![Fonts debugging](https://user-images.githubusercontent.com/8225057/135429892-0e41ef8d-33c5-4991-bcf6-f997a0bcfd6b.png) -- You can use the `UTF-8 Encoding viewer` in `Metrics/Debugger` to verify the content of your UTF-8 strings. From C/C++ code, you can call `ImGui::DebugTextEncoding("my string");` function to verify that your UTF-8 encoding is correct. +#### UTF-8 Encoding Viewer** +You can use the `UTF-8 Encoding viewer` in `Metrics/Debugger` to verify the content of your UTF-8 strings. From C/C++ code, you can call `ImGui::DebugTextEncoding("my string");` function to verify that your UTF-8 encoding is correct. ![UTF-8 Encoding viewer](https://user-images.githubusercontent.com/8225057/166505963-8a0d7899-8ee8-4558-abb2-1ae523dc02f9.png) -- All loaded fonts glyphs are rendered into a single texture atlas ahead of time. Calling either of `io.Fonts->GetTexDataAsAlpha8()`, `io.Fonts->GetTexDataAsRGBA32()` or `io.Fonts->Build()` will build the atlas. - -- Make sure your font ranges data are persistent (available during the calls to `GetTexDataAsAlpha8()`/`GetTexDataAsRGBA32()/`Build()`. - -- Use C++11 u8"my text" syntax to encode literal strings as UTF-8. e.g.: -```cpp -u8"hello" -u8"こんにちは" // this will be encoded as UTF-8 -``` - ##### [Return to Index](#index) + ## How should I handle DPI in my application? See [FAQ entry](https://github.com/ocornut/imgui/blob/master/docs/FAQ.md#q-how-should-i-handle-dpi-in-my-application). @@ -54,7 +131,7 @@ See [FAQ entry](https://github.com/ocornut/imgui/blob/master/docs/FAQ.md#q-how-s ##### [Return to Index](#index) -## Font Loading Instructions +## Fonts Loading Instructions **Load default font:** ```cpp @@ -62,7 +139,6 @@ ImGuiIO& io = ImGui::GetIO(); io.Fonts->AddFontDefault(); ``` - **Load .TTF/.OTF file with:** ```cpp ImGuiIO& io = ImGui::GetIO(); @@ -70,7 +146,6 @@ io.Fonts->AddFontFromFileTTF("font.ttf", size_pixels); ``` If you get an assert stating "Could not load font file!", your font filename is likely incorrect. Read "[About filenames](#about-filenames)" carefully. - **Load multiple fonts:** ```cpp // Init @@ -86,7 +161,6 @@ ImGui::Text("Hello with another font"); ImGui::PopFont(); ``` - **For advanced options create a ImFontConfig structure and pass it to the AddFont() function (it will be copied internally):** ```cpp ImFontConfig config; @@ -96,7 +170,6 @@ config.GlyphExtraSpacing.x = 1.0f; ImFont* font = io.Fonts->AddFontFromFileTTF("font.ttf", size_pixels, &config); ``` - **Combine multiple fonts into one:** ```cpp // Load a first font @@ -311,28 +384,6 @@ ImFont* font = io.Fonts->AddFontFromMemoryCompressedBase85TTF(compressed_data_ba ##### [Return to Index](#index) -## About filenames - -**Please note that many new C/C++ users have issues loading their files _because the filename they provide is wrong_.** - -Two things to watch for: -- Make sure your IDE/debugger settings starts your executable from the right working directory. In Visual Studio you can change your working directory in project `Properties > General > Debugging > Working Directory`. People assume that their execution will start from the root folder of the project, where by default it often starts from the folder where object or executable files are stored. -```cpp -// Relative filename depends on your Working Directory when running your program! -io.Fonts->AddFontFromFileTTF("MyImage01.jpg", ...); - -// Load from the parent folder of your Working Directory -io.Fonts->AddFontFromFileTTF("../MyImage01.jpg", ...); -``` -- In C/C++ and most programming languages if you want to use a backslash `\` within a string literal, you need to write it double backslash `\\`. At it happens, Windows uses backslashes as a path separator, so be mindful. -```cpp -io.Fonts->AddFontFromFileTTF("MyFiles\MyImage01.jpg", ...); // This is INCORRECT!! -io.Fonts->AddFontFromFileTTF("MyFiles\\MyImage01.jpg", ...); // This is CORRECT -``` -In some situations, you may also use `/` path separator under Windows. - -##### [Return to Index](#index) - ## Credits/Licenses For Fonts Included In Repository Some fonts files are available in the `misc/fonts/` folder: diff --git a/examples/example_win32_directx11/main.cpp b/examples/example_win32_directx11/main.cpp index d4d330575..c242a4ccb 100644 --- a/examples/example_win32_directx11/main.cpp +++ b/examples/example_win32_directx11/main.cpp @@ -1,4 +1,4 @@ -// Dear ImGui: standalone example application for DirectX 11 +// Dear ImGui: standalone example application for DirectX 11 // If you are new to Dear ImGui, read documentation from the docs/ folder + read the top of imgui.cpp. // Read online: https://github.com/ocornut/imgui/tree/master/docs @@ -26,7 +26,7 @@ LRESULT WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); int main(int, char**) { // Create application window - ImGui_ImplWin32_EnableDpiAwareness(); + //ImGui_ImplWin32_EnableDpiAwareness(); WNDCLASSEXW wc = { sizeof(wc), CS_CLASSDC, WndProc, 0L, 0L, GetModuleHandle(nullptr), nullptr, nullptr, nullptr, nullptr, L"ImGui Example", nullptr }; ::RegisterClassExW(&wc); HWND hwnd = ::CreateWindowW(wc.lpszClassName, L"Dear ImGui DirectX11 Example", WS_OVERLAPPEDWINDOW, 100, 100, 1280, 800, nullptr, nullptr, wc.hInstance, nullptr); @@ -71,7 +71,7 @@ int main(int, char**) //io.Fonts->AddFontFromFileTTF("../../misc/fonts/DroidSans.ttf", 16.0f); //io.Fonts->AddFontFromFileTTF("../../misc/fonts/Roboto-Medium.ttf", 16.0f); //io.Fonts->AddFontFromFileTTF("../../misc/fonts/Cousine-Regular.ttf", 15.0f); - ImFont* font = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, nullptr, io.Fonts->GetGlyphRangesJapanese()); + //ImFont* font = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, nullptr, io.Fonts->GetGlyphRangesJapanese()); //IM_ASSERT(font != nullptr); // Our state @@ -114,12 +114,6 @@ int main(int, char**) if (show_demo_window) ImGui::ShowDemoWindow(&show_demo_window); - ImGui::SeparatorText("CORRECT"); - ImGui::DebugTextEncoding(u8"こんにちは"); - - ImGui::SeparatorText("INCORRECT"); - ImGui::DebugTextEncoding("こんにちは"); - // 2. Show a simple window that we create ourselves. We use a Begin/End pair to create a named window. { static float f = 0.0f; @@ -127,13 +121,6 @@ int main(int, char**) ImGui::Begin("Hello, world!"); // Create a window called "Hello, world!" and append into it. -#define U8(_S) (const char*)u8##_S - ImGui::Text(U8("こんにちは")); - -//#pragma execution_character_set("utf-8") - - ImGui::Text("日本語"); - ImGui::Text("This is some useful text."); // Display some text (you can use a format strings too) ImGui::Checkbox("Demo Window", &show_demo_window); // Edit bools storing our window open/close state ImGui::Checkbox("Another Window", &show_another_window); diff --git a/imgui.cpp b/imgui.cpp index fe611f8a4..35dc532db 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -13394,7 +13394,7 @@ void ImGui::DebugRenderKeyboardPreview(ImDrawList* draw_list) void ImGui::DebugTextEncoding(const char* str) { Text("Text: \"%s\"", str); - if (!BeginTable("list", 4, ImGuiTableFlags_Borders | ImGuiTableFlags_RowBg | ImGuiTableFlags_SizingFixedFit)) + if (!BeginTable("##DebugTextEncoding", 4, ImGuiTableFlags_Borders | ImGuiTableFlags_RowBg | ImGuiTableFlags_SizingFixedFit | ImGuiTableFlags_Resizable)) return; TableSetupColumn("Offset"); TableSetupColumn("UTF-8"); diff --git a/imgui.h b/imgui.h index 8bacf9f07..672f841c0 100644 --- a/imgui.h +++ b/imgui.h @@ -2832,7 +2832,8 @@ struct ImFontAtlas //------------------------------------------- // Helpers to retrieve list of common Unicode ranges (2 value per range, values are inclusive, zero-terminated list) - // NB: Make sure that your string are UTF-8 and NOT in your local code page. In C++11, you can create UTF-8 string literal using the u8"Hello world" syntax. See FAQ for details. + // NB: Make sure that your string are UTF-8 and NOT in your local code page. + // Read https://github.com/ocornut/imgui/blob/master/docs/FONTS.md/#about-utf-8-encoding for details. // NB: Consider using ImFontGlyphRangesBuilder to build glyph ranges from textual data. IMGUI_API const ImWchar* GetGlyphRangesDefault(); // Basic Latin, Extended Latin IMGUI_API const ImWchar* GetGlyphRangesGreek(); // Default + Greek and Coptic