diff --git a/examples/example_apple_metal/example_apple_metal.xcodeproj/project.pbxproj b/examples/example_apple_metal/example_apple_metal.xcodeproj/project.pbxproj index 5f7c211b6..55a33c4ea 100644 --- a/examples/example_apple_metal/example_apple_metal.xcodeproj/project.pbxproj +++ b/examples/example_apple_metal/example_apple_metal.xcodeproj/project.pbxproj @@ -8,10 +8,8 @@ /* Begin PBXBuildFile section */ 05318E0F274C397200A8DE2E /* GameController.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 05318E0E274C397200A8DE2E /* GameController.framework */; }; - A1I18N00000000000000001A /* imgui_i18n.cpp in Sources (iOS) */ = {isa = PBXBuildFile; fileRef = A1I18N00000000000000F001 /* imgui_i18n.cpp */; }; - A1I18N00000000000000001B /* imgui_i18n.cpp in Sources (macOS) */ = {isa = PBXBuildFile; fileRef = A1I18N00000000000000F001 /* imgui_i18n.cpp */; }; - A1I18N00000000000000002A /* zh_CN.cpp in Sources (iOS) */ = {isa = PBXBuildFile; fileRef = A1I18N00000000000000F002 /* zh_CN.cpp */; }; - A1I18N00000000000000002B /* zh_CN.cpp in Sources (macOS) */ = {isa = PBXBuildFile; fileRef = A1I18N00000000000000F002 /* zh_CN.cpp */; }; + A1I18N00000000000000001B /* imgui_i18n.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A1I18N00000000000000F001 /* imgui_i18n.cpp */; }; + A1I18N00000000000000002B /* zh_CN.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A1I18N00000000000000F002 /* zh_CN.cpp */; }; 07A82ED82139413D0078D120 /* imgui_widgets.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 07A82ED72139413C0078D120 /* imgui_widgets.cpp */; }; 07A82ED92139418F0078D120 /* imgui_widgets.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 07A82ED72139413C0078D120 /* imgui_widgets.cpp */; }; 5079822E257677DB0038A28D /* imgui_tables.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5079822D257677DB0038A28D /* imgui_tables.cpp */; }; @@ -281,8 +279,6 @@ 5079822E257677DB0038A28D /* imgui_tables.cpp in Sources */, 07A82ED82139413D0078D120 /* imgui_widgets.cpp in Sources */, 8309BDA5253CCC070045E2A1 /* main.mm in Sources */, - A1I18N00000000000000001A /* imgui_i18n.cpp in Sources (iOS) */, - A1I18N00000000000000002A /* zh_CN.cpp in Sources (iOS) */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -421,10 +417,6 @@ CODE_SIGN_IDENTITY = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; DEVELOPMENT_TEAM = ""; - GCC_PREPROCESSOR_DEFINITIONS = ( - "IMGUI_DEMO_ENABLE_I18N=1", - "$(inherited)", - ); INFOPLIST_FILE = "$(SRCROOT)/iOS/Info-iOS.plist"; IPHONEOS_DEPLOYMENT_TARGET = 12.0; LD_RUNPATH_SEARCH_PATHS = ( @@ -445,10 +437,6 @@ CODE_SIGN_IDENTITY = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; DEVELOPMENT_TEAM = ""; - GCC_PREPROCESSOR_DEFINITIONS = ( - "IMGUI_DEMO_ENABLE_I18N=1", - "$(inherited)", - ); INFOPLIST_FILE = "$(SRCROOT)/iOS/Info-iOS.plist"; IPHONEOS_DEPLOYMENT_TARGET = 12.0; LD_RUNPATH_SEARCH_PATHS = ( diff --git a/examples/example_apple_metal/main.mm b/examples/example_apple_metal/main.mm index 01038716b..02bcecf54 100644 --- a/examples/example_apple_metal/main.mm +++ b/examples/example_apple_metal/main.mm @@ -18,8 +18,12 @@ #import #include "imgui.h" +// i18n support: include unconditionally — when IMGUI_DEMO_ENABLE_I18N is not defined +// the header provides a no-op Tr(s) stub with zero overhead. #include "imgui_i18n.h" +#ifdef IMGUI_DEMO_ENABLE_I18N #include +#endif #include "imgui_impl_metal.h" #if TARGET_OS_OSX #include "imgui_impl_osx.h" @@ -40,6 +44,7 @@ // AppViewController //----------------------------------------------------------------------------------- +#ifdef IMGUI_DEMO_ENABLE_I18N bool g_need_font_rebuild = false; static void RebuildFonts() @@ -76,6 +81,7 @@ static void RebuildFonts() } io.Fonts->Build(); } +#endif // IMGUI_DEMO_ENABLE_I18N @implementation AppViewController @@ -150,8 +156,10 @@ static void RebuildFonts() [NSApp activateIgnoringOtherApps:YES]; #endif +#ifdef IMGUI_DEMO_ENABLE_I18N // Build initial font atlas with CJK glyphs so the Language menu renders correctly from the start. RebuildFonts(); +#endif } -(void)drawInMTKView:(MTKView*)view @@ -176,11 +184,13 @@ static void RebuildFonts() return; } - // 语言切换后重建字体 Atlas(必须在 NewFrame 之前,避免当帧纹理 use-after-free) +#ifdef IMGUI_DEMO_ENABLE_I18N + // Rebuild font atlas after language switch (must be before NewFrame to avoid use-after-free). if (g_need_font_rebuild) { g_need_font_rebuild = false; RebuildFonts(); } +#endif // Start the Dear ImGui frame ImGui_ImplMetal_NewFrame(renderPassDescriptor);