Added IM_UNICODE_MAX_CODEPOINT. Changed specs of ImFontAtlas::AddCustomRectRegular() (breaking change).
diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt
index 719e598..f1f3ac5 100644
--- a/docs/CHANGELOG.txt
+++ b/docs/CHANGELOG.txt
@@ -50,6 +50,8 @@
Effectively it made io.KeyRepeatRate behave like it was set to (io.KeyRepeatRate + io.KeyRepeatDelay).
Fixed the code and altered default io.KeyRepeatRate,Delay from 0.250,0.050 to 0.300,0.050 to compensate.
If you never altered io.KeyRepeatRate nor used GetKeyPressedAmount() this won't affect you.
+- Fonts: ImFontAtlas::AddCustomRectRegular() now requires an ID larger than 0x110000 (instead of 0x10000) to
+ conform with supporting Unicode planes 1-16 in a future update. ID below 0x110000 will now assert.
- Backends: DX12: Added extra ID3D12DescriptorHeap parameter to ImGui_ImplDX12_Init() function.
The value is unused in master branch but will be used by the multi-viewport feature. (#2851) [@obfuscate]
diff --git a/imgui.cpp b/imgui.cpp
index 2fdfb94..dcfe6f3 100644
--- a/imgui.cpp
+++ b/imgui.cpp
@@ -351,6 +351,7 @@
When you are not sure about a old symbol or function name, try using the Search/Find function of your IDE to look for comments or references in all imgui files.
You can read releases logs https://github.com/ocornut/imgui/releases for more details.
+ - 2019/10/29 (1.74) - ImFontAtlas::AddCustomRectRegular() now requires an ID larger than 0x110000 (instead of 0x10000) to conform with supporting Unicode planes 1-16 in a future update. ID below 0x110000 will now assert.
- 2019/10/22 (1.74) - removed redirecting functions/enums that were marked obsolete in 1.52 (October 2017): Begin() (5 arguments signature), IsRootWindowOrAnyChildHovered(), AlignFirstTextHeightToWidgets(), SetNextWindowPosCenter(), ImFont::Glyph. Grep this log for details and new names, or see how they were implemented until 1.73.
- 2019/10/14 (1.74) - inputs: Fixed a miscalculation in the keyboard/mouse "typematic" repeat delay/rate calculation, used by keys and e.g. repeating mouse buttons as well as the GetKeyPressedAmount() function.
if you were using a non-default value for io.KeyRepeatRate (previous default was 0.250), you can add +io.KeyRepeatDelay to it to compensate for the fix.
diff --git a/imgui.h b/imgui.h
index 841506f..7ab1792 100644
--- a/imgui.h
+++ b/imgui.h
@@ -80,6 +80,7 @@
#else
#define IM_OFFSETOF(_TYPE,_MEMBER) ((size_t)&(((_TYPE*)0)->_MEMBER)) // Offset of _MEMBER within _TYPE. Old style macro.
#endif
+#define IM_UNICODE_MAX_CODEPOINT (0x10000)
// Warnings
#if defined(__clang__)
@@ -2042,7 +2043,7 @@
ImVector<ImU32> UsedChars; // Store 1-bit per Unicode code point (0=unused, 1=used)
ImFontGlyphRangesBuilder() { Clear(); }
- inline void Clear() { int size_in_bytes = 0x10000 / 8; UsedChars.resize(size_in_bytes / (int)sizeof(ImU32)); memset(UsedChars.Data, 0, (size_t)size_in_bytes); }
+ inline void Clear() { int size_in_bytes = IM_UNICODE_MAX_CODEPOINT / 8; UsedChars.resize(size_in_bytes / (int)sizeof(ImU32)); memset(UsedChars.Data, 0, (size_t)size_in_bytes); }
inline bool GetBit(int n) const { int off = (n >> 5); ImU32 mask = 1u << (n & 31); return (UsedChars[off] & mask) != 0; } // Get bit n in the array
inline void SetBit(int n) { int off = (n >> 5); ImU32 mask = 1u << (n & 31); UsedChars[off] |= mask; } // Set bit n in the array
inline void AddChar(ImWchar c) { SetBit(c); } // Add character
@@ -2054,12 +2055,12 @@
// See ImFontAtlas::AddCustomRectXXX functions.
struct ImFontAtlasCustomRect
{
- unsigned int ID; // Input // User ID. Use <0x10000 to map into a font glyph, >=0x10000 for other/internal/custom texture data.
+ unsigned int ID; // Input // User ID. Use <0x110000 to map into a font glyph, >=0x110000 for other/internal/custom texture data.
unsigned short Width, Height; // Input // Desired rectangle dimension
unsigned short X, Y; // Output // Packed position in Atlas
- float GlyphAdvanceX; // Input // For custom font glyphs only (ID<0x10000): glyph xadvance
- ImVec2 GlyphOffset; // Input // For custom font glyphs only (ID<0x10000): glyph display offset
- ImFont* Font; // Input // For custom font glyphs only (ID<0x10000): target font
+ float GlyphAdvanceX; // Input // For custom font glyphs only (ID < 0x110000): glyph xadvance
+ ImVec2 GlyphOffset; // Input // For custom font glyphs only (ID < 0x110000): glyph display offset
+ ImFont* Font; // Input // For custom font glyphs only (ID < 0x110000): target font
ImFontAtlasCustomRect() { ID = 0xFFFFFFFF; Width = Height = 0; X = Y = 0xFFFF; GlyphAdvanceX = 0.0f; GlyphOffset = ImVec2(0,0); Font = NULL; }
bool IsPacked() const { return X != 0xFFFF; }
};
@@ -2139,8 +2140,8 @@
// You can also request your rectangles to be mapped as font glyph (given a font + Unicode point),
// so you can render e.g. custom colorful icons and use them as regular glyphs.
// Read misc/fonts/README.txt for more details about using colorful icons.
- IMGUI_API int AddCustomRectRegular(unsigned int id, int width, int height); // Id needs to be >= 0x10000. Id >= 0x80000000 are reserved for ImGui and ImDrawList
- IMGUI_API int AddCustomRectFontGlyph(ImFont* font, ImWchar id, int width, int height, float advance_x, const ImVec2& offset = ImVec2(0,0)); // Id needs to be < 0x10000 to register a rectangle to map into a specific font.
+ IMGUI_API int AddCustomRectRegular(unsigned int id, int width, int height); // Id needs to be >= 0x110000. Id >= 0x80000000 are reserved for ImGui and ImDrawList
+ IMGUI_API int AddCustomRectFontGlyph(ImFont* font, ImWchar id, int width, int height, float advance_x, const ImVec2& offset = ImVec2(0,0)); // Id needs to be < 0x110000 to register a rectangle to map into a specific font.
const ImFontAtlasCustomRect*GetCustomRectByIndex(int index) const { if (index < 0) return NULL; return &CustomRects[index]; }
// [Internal]
diff --git a/imgui_demo.cpp b/imgui_demo.cpp
index 3eedda4..17d2927 100644
--- a/imgui_demo.cpp
+++ b/imgui_demo.cpp
@@ -3401,7 +3401,7 @@
if (ImGui::TreeNode("Glyphs", "Glyphs (%d)", font->Glyphs.Size))
{
// Display all glyphs of the fonts in separate pages of 256 characters
- for (int base = 0; base < 0x10000; base += 256)
+ for (int base = 0; base < IM_UNICODE_MAX_CODEPOINT; base += 256)
{
int count = 0;
for (int n = 0; n < 256; n++)
diff --git a/imgui_draw.cpp b/imgui_draw.cpp
index f73e0e3..ad3cf1f 100644
--- a/imgui_draw.cpp
+++ b/imgui_draw.cpp
@@ -1725,7 +1725,8 @@
int ImFontAtlas::AddCustomRectRegular(unsigned int id, int width, int height)
{
- IM_ASSERT(id >= 0x10000);
+ // Breaking change on 2019/10/29 (1.74) - ImFontAtlas::AddCustomRectRegular() now requires an ID larger than 0x110000 (instead of larger than 0x10000)
+ IM_ASSERT(id >= 0x110000);
IM_ASSERT(width > 0 && width <= 0xFFFF);
IM_ASSERT(height > 0 && height <= 0xFFFF);
ImFontAtlasCustomRect r;
@@ -2189,7 +2190,7 @@
for (int i = 0; i < atlas->CustomRects.Size; i++)
{
const ImFontAtlasCustomRect& r = atlas->CustomRects[i];
- if (r.Font == NULL || r.ID > 0x10000)
+ if (r.Font == NULL || r.ID >= IM_UNICODE_MAX_CODEPOINT)
continue;
IM_ASSERT(r.Font->ContainerAtlas == atlas);
@@ -2467,7 +2468,7 @@
void ImFontGlyphRangesBuilder::BuildRanges(ImVector<ImWchar>* out_ranges)
{
- int max_codepoint = 0x10000;
+ const int max_codepoint = IM_UNICODE_MAX_CODEPOINT;
for (int n = 0; n < max_codepoint; n++)
if (GetBit(n))
{
diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp
index 1a82f29..ab0f466 100644
--- a/imgui_widgets.cpp
+++ b/imgui_widgets.cpp
@@ -3157,7 +3157,7 @@
static int STB_TEXTEDIT_STRINGLEN(const STB_TEXTEDIT_STRING* obj) { return obj->CurLenW; }
static ImWchar STB_TEXTEDIT_GETCHAR(const STB_TEXTEDIT_STRING* obj, int idx) { return obj->TextW[idx]; }
static float STB_TEXTEDIT_GETWIDTH(STB_TEXTEDIT_STRING* obj, int line_start_idx, int char_idx) { ImWchar c = obj->TextW[line_start_idx + char_idx]; if (c == '\n') return STB_TEXTEDIT_GETWIDTH_NEWLINE; ImGuiContext& g = *GImGui; return g.Font->GetCharAdvance(c) * (g.FontSize / g.Font->FontSize); }
-static int STB_TEXTEDIT_KEYTOTEXT(int key) { return key >= 0x10000 ? 0 : key; }
+static int STB_TEXTEDIT_KEYTOTEXT(int key) { return key >= 0x200000 ? 0 : key; }
static ImWchar STB_TEXTEDIT_NEWLINE = '\n';
static void STB_TEXTEDIT_LAYOUTROW(StbTexteditRow* r, STB_TEXTEDIT_STRING* obj, int line_start_idx)
{
@@ -3340,6 +3340,10 @@
if (c >= 0xE000 && c <= 0xF8FF)
return false;
+ // Filter Unicode ranges we are not handling in this build.
+ if (c >= IM_UNICODE_MAX_CODEPOINT)
+ return false;
+
// Generic named filters
if (flags & (ImGuiInputTextFlags_CharsDecimal | ImGuiInputTextFlags_CharsHexadecimal | ImGuiInputTextFlags_CharsUppercase | ImGuiInputTextFlags_CharsNoBlank | ImGuiInputTextFlags_CharsScientific))
{
@@ -3763,7 +3767,7 @@
s += ImTextCharFromUtf8(&c, s, NULL);
if (c == 0)
break;
- if (c >= 0x10000 || !InputTextFilterCharacter(&c, flags, callback, callback_user_data))
+ if (!InputTextFilterCharacter(&c, flags, callback, callback_user_data))
continue;
clipboard_filtered[clipboard_filtered_len++] = (ImWchar)c;
}