Skip to content

Commit 670367e

Browse files
committed
Added IMGUI_USE_WCHAR32 instead of "#define ImWchar ImWchar32" to faclitate C-binding. (ocornut#2538, ocornut#2541, ocornut#2815)
1 parent f2b01c3 commit 670367e

File tree

5 files changed

+19
-13
lines changed

5 files changed

+19
-13
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ jobs:
202202
203203
- name: Build example_null (with ImWchar32)
204204
run: |
205-
echo '#define ImWchar ImWchar32' > example_single_file.cpp
205+
echo '#define IMGUI_USE_WCHAR32' > example_single_file.cpp
206206
echo '#define IMGUI_IMPLEMENTATION' >> example_single_file.cpp
207207
echo '#include "misc/single_file/imgui_single_file.h"' >> example_single_file.cpp
208208
echo '#include "examples/example_null/main.cpp"' >> example_single_file.cpp

docs/CHANGELOG.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ Other Changes:
4949
cursor position. This would often get fixed after the fix item submission, but using the
5050
ImGuiListClipper as the first thing after Begin() could largely break size calculations. (#3073)
5151
- Added optional support for Unicode plane 1-16 (#2538, #2541, #2815) [@cloudwu, @samhocevar]
52-
- Compile-time enable with '#define ImWchar ImWchar32' in imconfig.h.
52+
- Compile-time enable with '#define IMGUI_USE_WCHAR32' in imconfig.h.
5353
- Generally more consistent support for unsupported codepoints (0xFFFD), in particular when
5454
using the default, non-fitting characters will be turned into 0xFFFD instead of being ignored.
5555
- Surrogate pairs are supported when submitting UTF-16 data via io.AddInputCharacterUTF16(),

imconfig.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@
4848
//---- Pack colors to BGRA8 instead of RGBA8 (to avoid converting from one to another)
4949
//#define IMGUI_USE_BGRA_PACKED_COLOR
5050

51+
//---- Use 32-bit for ImWchar (default is 16-bit) to support full unicode code points.
52+
//#define IMGUI_USE_WCHAR32
53+
5154
//---- Avoid multiple STB libraries implementations, or redefine path/filenames to prioritize another version
5255
// By default the embedded implementations are declared static and not available outside of imgui cpp files.
5356
//#define IMGUI_STB_TRUETYPE_FILENAME "my_folder/stb_truetype.h"
@@ -77,9 +80,6 @@
7780
// Read about ImGuiBackendFlags_RendererHasVtxOffset for details.
7881
//#define ImDrawIdx unsigned int
7982

80-
//---- Use 32-bit for ImWchar (default is 16-bit) to support full unicode code points.
81-
//#define ImWchar ImWchar32
82-
8383
//---- Override ImDrawCallback signature (will need to modify renderer back-ends accordingly)
8484
//struct ImDrawList;
8585
//struct ImDrawCmd;

imgui.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
// - Read FAQ at http://dearimgui.org/faq
66
// - Newcomers, read 'Programmer guide' below for notes on how to setup Dear ImGui in your codebase.
77
// - Call and read ImGui::ShowDemoWindow() in imgui_demo.cpp for demo code. All applications in examples/ are doing that.
8+
// Read imgui.cpp for details, links and comments.
89

910
// Resources:
1011
// - FAQ http://dearimgui.org/faq

imgui.h

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// - Read FAQ at http://dearimgui.org/faq
66
// - Newcomers, read 'Programmer guide' in imgui.cpp for notes on how to setup Dear ImGui in your codebase.
77
// - Call and read ImGui::ShowDemoWindow() in imgui_demo.cpp for demo code. All applications in examples/ are doing that.
8-
// Read imgui.cpp for more details, documentation and comments.
8+
// Read imgui.cpp for details, links and comments.
99

1010
// Resources:
1111
// - FAQ http://dearimgui.org/faq
@@ -65,7 +65,7 @@ Index of this file:
6565

6666
// Define attributes of all API symbols declarations (e.g. for DLL under Windows)
6767
// IMGUI_API is used for core imgui functions, IMGUI_IMPL_API is used for the default bindings files (imgui_impl_xxx.h)
68-
// Using dear imgui via a shared library is not recommended, because of function call overhead and because we don't guarantee backward nor forward ABI compatibility.
68+
// Using dear imgui via a shared library is not recommended, because we don't guarantee backward nor forward ABI compatibility (also function call overhead, as dear imgui is a call-heavy API)
6969
#ifndef IMGUI_API
7070
#define IMGUI_API
7171
#endif
@@ -170,18 +170,23 @@ typedef int ImGuiTreeNodeFlags; // -> enum ImGuiTreeNodeFlags_ // Flags: f
170170
typedef int ImGuiWindowFlags; // -> enum ImGuiWindowFlags_ // Flags: for Begin(), BeginChild()
171171

172172
// Other types
173-
#ifndef ImTextureID // ImTextureID [configurable type: override in imconfig.h]
173+
#ifndef ImTextureID // ImTextureID [configurable type: override in imconfig.h with '#define ImTextureID xxx']
174174
typedef void* ImTextureID; // User data for rendering back-end to identify a texture. This is whatever to you want it to be! read the FAQ about ImTextureID for details.
175175
#endif
176-
#ifndef ImWchar // ImWchar [configurable type: override in imconfig.h]
177-
#define ImWchar ImWchar16 // Storage for a single decoded character/code point, default to 16-bit. Set to ImWchar32 to support larger Unicode planes. Note that we generally support UTF-8 encoded string, this is storage for a decoded character.
178-
#endif
179176
typedef unsigned int ImGuiID; // A unique ID used by widgets, typically hashed from a stack of string.
180-
typedef unsigned short ImWchar16; // A single decoded U16 character/code point for keyboard input/display. We encode them as multi bytes UTF-8 when used in strings.
181-
typedef unsigned int ImWchar32; // A single decoded U32 character/code point for keyboard input/display. To enable, use '#define ImWchar ImWchar32' in imconfig.h.
182177
typedef int (*ImGuiInputTextCallback)(ImGuiInputTextCallbackData *data);
183178
typedef void (*ImGuiSizeCallback)(ImGuiSizeCallbackData* data);
184179

180+
// Decoded character types
181+
// (we generally use UTF-8 encoded string in the API. This is storage specifically for a decoded character used for keyboard input and display)
182+
typedef unsigned short ImWchar16; // A single decoded U16 character/code point. We encode them as multi bytes UTF-8 when used in strings.
183+
typedef unsigned int ImWchar32; // A single decoded U32 character/code point. We encode them as multi bytes UTF-8 when used in strings.
184+
#ifdef IMGUI_USE_WCHAR32 // ImWchar [configurable type: override in imconfig.h with '#define IMGUI_USE_WCHAR32' to support Unicode planes 1-16]
185+
typedef ImWchar32 ImWchar;
186+
#else
187+
typedef ImWchar16 ImWchar;
188+
#endif
189+
185190
// Basic scalar data types
186191
typedef signed char ImS8; // 8-bit signed integer
187192
typedef unsigned char ImU8; // 8-bit unsigned integer

0 commit comments

Comments
 (0)