From a0b3eceec7854be4a32e19ff21397738c06517fe Mon Sep 17 00:00:00 2001 From: ocornut Date: Thu, 12 Jun 2025 11:02:32 +0200 Subject: [PATCH] Fixed using IMGUI_DISABLE_DEMO_WINDOWS without IMGUI_DISABLE_DEBUG_TOOLS and without linking with imgui_demo.cpp --- docs/CHANGELOG.txt | 2 ++ imgui.cpp | 36 +++++++++++++++++++++++++++++++++++- imgui_demo.cpp | 39 +++------------------------------------ 3 files changed, 40 insertions(+), 37 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 8a49b9a04..7cda2db6c 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -290,6 +290,8 @@ Other changes: to be a valid low-level texture identifier. - Debug Tools: Fonts section: add font preview, add "Remove" button, add "Load all glyphs" button, add selection to change font backend when both are compiled in. +- Special thanks for fonts/texture related feedback to: @thedmd, @ShironekoBen, @rodrigorc, + @pathogendavid, @itamago, @rokups, @DucaRii, @Aarkham, @cyfewlp. - IO: variations in analog-only components of gamepad events do not interfere with trickling of mouse position events (#4921, #8508) diff --git a/imgui.cpp b/imgui.cpp index 74c135ddf..90f9ecd2d 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -15921,7 +15921,7 @@ void ImGui::ShowFontAtlas(ImFontAtlas* atlas) if (loader_current == loader_freetype) { unsigned int loader_flags = atlas->FontLoaderFlags; - Text("Shared FreeType Loader Flags: 0x%08", loader_flags); + Text("Shared FreeType Loader Flags: 0x%08X", loader_flags); if (ImGuiFreeType::DebugEditFontLoaderFlags(&loader_flags)) { for (ImFont* font : atlas->Fonts) @@ -17726,6 +17726,40 @@ void ImGui::DebugHookIdInfo(ImGuiID, ImGuiDataType, const void*, const void*) {} #endif // #ifndef IMGUI_DISABLE_DEBUG_TOOLS +#if !defined(IMGUI_DISABLE_DEMO_WINDOWS) || !defined(IMGUI_DISABLE_DEBUG_TOOLS) +// Demo helper function to select among loaded fonts. +// Here we use the regular BeginCombo()/EndCombo() api which is the more flexible one. +void ImGui::ShowFontSelector(const char* label) +{ + ImGuiIO& io = GetIO(); + ImFont* font_current = GetFont(); + if (BeginCombo(label, font_current->GetDebugName())) + { + for (ImFont* font : io.Fonts->Fonts) + { + PushID((void*)font); + if (Selectable(font->GetDebugName(), font == font_current)) + io.FontDefault = font; + if (font == font_current) + SetItemDefaultFocus(); + PopID(); + } + EndCombo(); + } + SameLine(); + if (io.BackendFlags & ImGuiBackendFlags_RendererHasTextures) + MetricsHelpMarker( + "- Load additional fonts with io.Fonts->AddFontXXX() functions.\n" + "- Read FAQ and docs/FONTS.md for more details."); + else + MetricsHelpMarker( + "- Load additional fonts with io.Fonts->AddFontXXX() functions.\n" + "- The font atlas is built when calling io.Fonts->GetTexDataAsXXXX() or io.Fonts->Build().\n" + "- Read FAQ and docs/FONTS.md for more details.\n" + "- If you need to add/remove fonts at runtime (e.g. for DPI change), do it before calling NewFrame()."); +} +#endif // #if !defined(IMGUI_DISABLE_DEMO_WINDOWS) || !defined(IMGUI_DISABLE_DEBUG_TOOLS) + //----------------------------------------------------------------------------- // Include imgui_user.inl at the end of imgui.cpp to access private data/functions that aren't exposed. diff --git a/imgui_demo.cpp b/imgui_demo.cpp index cd48ee0ff..0b7c45aca 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -8171,43 +8171,10 @@ void ImGui::ShowAboutWindow(bool* p_open) //----------------------------------------------------------------------------- // [SECTION] Style Editor / ShowStyleEditor() //----------------------------------------------------------------------------- -// - ShowFontSelector() // - ShowStyleSelector() // - ShowStyleEditor() //----------------------------------------------------------------------------- -// Demo helper function to select among loaded fonts. -// Here we use the regular BeginCombo()/EndCombo() api which is the more flexible one. -void ImGui::ShowFontSelector(const char* label) -{ - ImGuiIO& io = ImGui::GetIO(); - ImFont* font_current = ImGui::GetFont(); - if (ImGui::BeginCombo(label, font_current->GetDebugName())) - { - for (ImFont* font : io.Fonts->Fonts) - { - ImGui::PushID((void*)font); - if (ImGui::Selectable(font->GetDebugName(), font == font_current)) - io.FontDefault = font; - if (font == font_current) - ImGui::SetItemDefaultFocus(); - ImGui::PopID(); - } - ImGui::EndCombo(); - } - ImGui::SameLine(); - if (io.BackendFlags & ImGuiBackendFlags_RendererHasTextures) - HelpMarker( - "- Load additional fonts with io.Fonts->AddFontXXX() functions.\n" - "- Read FAQ and docs/FONTS.md for more details."); - else - HelpMarker( - "- Load additional fonts with io.Fonts->AddFontXXX() functions.\n" - "- The font atlas is built when calling io.Fonts->GetTexDataAsXXXX() or io.Fonts->Build().\n" - "- Read FAQ and docs/FONTS.md for more details.\n" - "- If you need to add/remove fonts at runtime (e.g. for DPI change), do it before calling NewFrame()."); -} - // Demo helper function to select among default colors. See ShowStyleEditor() for more advanced options. // Here we use the simplified Combo() api that packs items into a single literal string. // Useful for quick combo boxes where the choices are known locally. @@ -10808,9 +10775,9 @@ void ImGui::ShowAboutWindow(bool*) {} void ImGui::ShowDemoWindow(bool*) {} void ImGui::ShowUserGuide() {} void ImGui::ShowStyleEditor(ImGuiStyle*) {} -bool ImGui::ShowStyleSelector(const char* label) { return false; } -void ImGui::ShowFontSelector(const char* label) {} +bool ImGui::ShowStyleSelector(const char*) { return false; } +void ImGui::ShowFontSelector(const char*) {} -#endif +#endif // #ifndef IMGUI_DISABLE_DEMO_WINDOWS #endif // #ifndef IMGUI_DISABLE