mirror of
https://github.com/ocornut/imgui.git
synced 2026-11-07 06:55:53 +01:00
i18n: guard i18n code in main.mm with IMGUI_DEMO_ENABLE_I18N; iOS target opt-out
- Wrap RebuildFonts(), g_need_font_rebuild, and font rebuild calls in #ifdef IMGUI_DEMO_ENABLE_I18N so main.mm compiles cleanly without i18n - Include imgui_i18n.h unconditionally (provides no-op Tr() stub when IMGUI_DEMO_ENABLE_I18N is not defined, enabling Tr() in the demo window) - Remove IMGUI_DEMO_ENABLE_I18N and i18n sources from iOS Xcode target (untested on iOS; macOS-only system font paths would not work on device)
This commit is contained in:
parent
86e272318f
commit
d497a70fca
@ -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 = (
|
||||
|
||||
@ -18,8 +18,12 @@
|
||||
#import <MetalKit/MetalKit.h>
|
||||
|
||||
#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 <unistd.h>
|
||||
#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);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user