Skip to content

Commit 5cb7ce2

Browse files
committed
Renamed ImFont::GlyphRangesBuilder to ImFontGlyphRangesBuilder. Keep redirection typedef (will obsolete).
1 parent 1353c74 commit 5cb7ce2

File tree

5 files changed

+48
-33
lines changed

5 files changed

+48
-33
lines changed

docs/CHANGELOG.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ Breaking Changes:
3939
The addition of new configuration options in the Docking branch is pushing for a little reorganization of those names.
4040
- Made it illegal to call Begin("") with an empty string. This somehow accidentally worked before but had various
4141
undesirable side-effect as the window would have ID zero. In particular it is causing problems in viewport/docking branches.
42+
- Renamed ImFontAtlas::GlyphRangesBuilder to ImFontGlyphRangesBuilder. Keep redirection typedef (will obsolete).
4243

4344
Other Changes:
4445
- Added BETA api for Tab Bar/Tabs widgets: (#261, #351)
@@ -734,6 +735,7 @@ Breaking Changes:
734735
- Removed `IsItemRectHovered()`, `IsWindowRectHovered()` recently introduced in 1.51 which were merely the more consistent/correct names for the above functions which are now obsolete anyway. (#1382)
735736
- Changed `IsWindowHovered()` default parameters behavior to return false if an item is active in another window (e.g. click-dragging item from another window to this window). You can use the newly introduced IsWindowHovered() flags to requests this specific behavior if you need it. (#1382)
736737
- Renamed imconfig.h's `IMGUI_DISABLE_WIN32_DEFAULT_CLIPBOARD_FUNCS`/`IMGUI_DISABLE_WIN32_DEFAULT_IME_FUNCS` to `IMGUI_DISABLE_WIN32_DEFAULT_CLIPBOARD_FUNCTIONS`/`IMGUI_DISABLE_WIN32_DEFAULT_IME_FUNCTIONS` for consistency.
738+
- Renamed ImFont::Glyph to ImFontGlyph. Keep redirection typedef (will obsolete).
737739

738740
Other Changes:
739741

imgui.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,8 @@ CODE
363363
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.
364364
You can read releases logs https://github.com/ocornut/imgui/releases for more details.
365365
366-
- 2019/01/04 (1.67) - renamed io.InputCharacters[], marked internal as was always intended. Please don't access directly, and use AddInputCharacter() instead!
366+
- 2019/01/06 (1.67) - renamed io.InputCharacters[], marked internal as was always intended. Please don't access directly, and use AddInputCharacter() instead!
367+
- 2019/01/06 (1.67) - renamed ImFontAtlas::GlyphRangesBuilder to ImFontGlyphRangesBuilder. Keep redirection typedef (will obsolete).
367368
- 2018/12/10 (1.67) - renamed io.ConfigResizeWindowsFromEdges to io.ConfigWindowsResizeFromEdges as we are doing a large pass on configuration flags.
368369
- 2018/10/12 (1.66) - renamed misc/stl/imgui_stl.* to misc/cpp/imgui_stdlib.* in prevision for other C++ helper files.
369370
- 2018/09/28 (1.66) - renamed SetScrollHere() to SetScrollHereY(). Kept redirection function (will obsolete).
@@ -431,6 +432,7 @@ CODE
431432
removed the IsItemRectHovered()/IsWindowRectHovered() names introduced in 1.51 since they were merely more consistent names for the two functions we are now obsoleting.
432433
- 2017/10/17 (1.52) - marked the old 5-parameters version of Begin() as obsolete (still available). Use SetNextWindowSize()+Begin() instead!
433434
- 2017/10/11 (1.52) - renamed AlignFirstTextHeightToWidgets() to AlignTextToFramePadding(). Kept inline redirection function (will obsolete).
435+
- 2017/09/26 (1.52) - renamed ImFont::Glyph to ImFontGlyph. Keep redirection typedef (will obsolete).
434436
- 2017/09/25 (1.52) - removed SetNextWindowPosCenter() because SetNextWindowPos() now has the optional pivot information to do the same and more. Kept redirection function (will obsolete).
435437
- 2017/08/25 (1.52) - io.MousePos needs to be set to ImVec2(-FLT_MAX,-FLT_MAX) when mouse is unavailable/missing. Previously ImVec2(-1,-1) was enough but we now accept negative mouse coordinates. In your binding if you need to support unavailable mouse, make sure to replace "io.MousePos = ImVec2(-1,-1)" with "io.MousePos = ImVec2(-FLT_MAX,-FLT_MAX)".
436438
- 2017/08/22 (1.51) - renamed IsItemHoveredRect() to IsItemRectHovered(). Kept inline redirection function (will obsolete). -> (1.52) use IsItemHovered(ImGuiHoveredFlags_RectOnly)!
@@ -822,7 +824,7 @@ CODE
822824
823825
// Or create your own custom ranges (e.g. for a game you can feed your entire game script and only build the characters the game need)
824826
ImVector<ImWchar> ranges;
825-
ImFontAtlas::GlyphRangesBuilder builder;
827+
ImFontGlyphRangesBuilder builder;
826828
builder.AddText("Hello world"); // Add a string (here "Hello world" contains 7 unique characters)
827829
builder.AddChar(0x7262); // Add a specific character
828830
builder.AddRanges(io.Fonts->GetGlyphRangesJapanese()); // Add one of the default ranges

imgui.h

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,17 @@ Index of this file:
8686
// Forward declarations and basic types
8787
//-----------------------------------------------------------------------------
8888

89-
struct ImDrawChannel; // Temporary storage for outputting drawing commands out of order, used by ImDrawList::ChannelsSplit()
90-
struct ImDrawCmd; // A single draw command within a parent ImDrawList (generally maps to 1 GPU draw call)
91-
struct ImDrawData; // All draw command lists required to render the frame
89+
struct ImDrawChannel; // Temporary storage for ImDrawList ot output draw commands out of order, used by ImDrawList::ChannelsSplit()
90+
struct ImDrawCmd; // A single draw command within a parent ImDrawList (generally maps to 1 GPU draw call, unless it is a callback)
91+
struct ImDrawData; // All draw command lists required to render the frame + pos/size coordinates to use for the projection matrix.
9292
struct ImDrawList; // A single draw command list (generally one per window, conceptually you may see this as a dynamic "mesh" builder)
9393
struct ImDrawListSharedData; // Data shared among multiple draw lists (typically owned by parent ImGui context, but you may create one yourself)
94-
struct ImDrawVert; // A single vertex (20 bytes by default, override layout with IMGUI_OVERRIDE_DRAWVERT_STRUCT_LAYOUT)
94+
struct ImDrawVert; // A single vertex (pos + uv + col = 20 bytes by default. Override layout with IMGUI_OVERRIDE_DRAWVERT_STRUCT_LAYOUT)
9595
struct ImFont; // Runtime data for a single font within a parent ImFontAtlas
9696
struct ImFontAtlas; // Runtime data for multiple fonts, bake multiple fonts into a single texture, TTF/OTF font loader
9797
struct ImFontConfig; // Configuration data when adding a font or merging fonts
98+
struct ImFontGlyph; // A single font glyph (code point + coordinates within in ImFontAtlas + offset)
99+
struct ImFontGlyphRangesBuilder; // Helper to build glyph ranges from text/string data
98100
struct ImColor; // Helper functions to create a color that can be converted to either u32 or float4 (*OBSOLETE* please avoid using)
99101
#ifndef ImTextureID
100102
typedef void* ImTextureID; // User data to identify a texture (this is whatever to you want it to be! read the FAQ about ImTextureID in imgui.cpp)
@@ -108,8 +110,8 @@ struct ImGuiPayload; // User data payload for drag and drop opera
108110
struct ImGuiSizeCallbackData; // Callback data when using SetNextWindowSizeConstraints() (rare/advanced use)
109111
struct ImGuiStorage; // Helper for key->value storage
110112
struct ImGuiStyle; // Runtime data for styling/colors
111-
struct ImGuiTextFilter; // Helper to parse and apply text filters (e.g. "aaaaa[,bbbb][,ccccc]")
112113
struct ImGuiTextBuffer; // Helper to hold and append into a text buffer (~string builder)
114+
struct ImGuiTextFilter; // Helper to parse and apply text filters (e.g. "aaaaa[,bbbb][,ccccc]")
113115

114116
// Typedefs and Enums/Flags (declared as int for compatibility with old C++, to allow using as flags and to not pollute the top of this file)
115117
// Use your programming IDE "Go to definition" facility on the names of the center columns to find the actual flags/enum lists.
@@ -1902,7 +1904,7 @@ struct ImDrawData
19021904
};
19031905

19041906
//-----------------------------------------------------------------------------
1905-
// Font API (ImFontConfig, ImFontGlyph, ImFontAtlasFlags, ImFontAtlas, ImFont)
1907+
// Font API (ImFontConfig, ImFontGlyph, ImFontAtlasFlags, ImFontAtlas, ImFontGlyphRangesBuilder, ImFont)
19061908
//-----------------------------------------------------------------------------
19071909

19081910
struct ImFontConfig
@@ -1939,6 +1941,19 @@ struct ImFontGlyph
19391941
float U0, V0, U1, V1; // Texture coordinates
19401942
};
19411943

1944+
// Helper to build glyph ranges from text/string data. Feed your application strings/characters to it then call BuildRanges().
1945+
struct ImFontGlyphRangesBuilder
1946+
{
1947+
ImVector<unsigned char> UsedChars; // Store 1-bit per Unicode code point (0=unused, 1=used)
1948+
ImFontGlyphRangesBuilder() { UsedChars.resize(0x10000 / 8); memset(UsedChars.Data, 0, 0x10000 / 8); }
1949+
bool GetBit(int n) const { return (UsedChars[n >> 3] & (1 << (n & 7))) != 0; }
1950+
void SetBit(int n) { UsedChars[n >> 3] |= 1 << (n & 7); } // Set bit 'c' in the array
1951+
void AddChar(ImWchar c) { SetBit(c); } // Add character
1952+
IMGUI_API void AddText(const char* text, const char* text_end = NULL); // Add string (each character of the UTF-8 string are added)
1953+
IMGUI_API void AddRanges(const ImWchar* ranges); // Add ranges, e.g. builder.AddRanges(ImFontAtlas::GetGlyphRangesDefault()) to force add all of ASCII/Latin+Ext
1954+
IMGUI_API void BuildRanges(ImVector<ImWchar>* out_ranges); // Output new ranges
1955+
};
1956+
19421957
enum ImFontAtlasFlags_
19431958
{
19441959
ImFontAtlasFlags_None = 0,
@@ -1995,7 +2010,7 @@ struct ImFontAtlas
19952010

19962011
// Helpers to retrieve list of common Unicode ranges (2 value per range, values are inclusive, zero-terminated list)
19972012
// NB: Make sure that your string are UTF-8 and NOT in your local code page. In C++11, you can create UTF-8 string literal using the u8"Hello world" syntax. See FAQ for details.
1998-
// NB: Consider using GlyphRangesBuilder to build glyph ranges from textual data.
2013+
// NB: Consider using ImFontGlyphRangesBuilder to build glyph ranges from textual data.
19992014
IMGUI_API const ImWchar* GetGlyphRangesDefault(); // Basic Latin, Extended Latin
20002015
IMGUI_API const ImWchar* GetGlyphRangesKorean(); // Default + Korean characters
20012016
IMGUI_API const ImWchar* GetGlyphRangesJapanese(); // Default + Hiragana, Katakana, Half-Width, Selection of 1946 Ideographs
@@ -2004,19 +2019,6 @@ struct ImFontAtlas
20042019
IMGUI_API const ImWchar* GetGlyphRangesCyrillic(); // Default + about 400 Cyrillic characters
20052020
IMGUI_API const ImWchar* GetGlyphRangesThai(); // Default + Thai characters
20062021

2007-
// Helpers to build glyph ranges from text data. Feed your application strings/characters to it then call BuildRanges().
2008-
struct GlyphRangesBuilder
2009-
{
2010-
ImVector<unsigned char> UsedChars; // Store 1-bit per Unicode code point (0=unused, 1=used)
2011-
GlyphRangesBuilder() { UsedChars.resize(0x10000 / 8); memset(UsedChars.Data, 0, 0x10000 / 8); }
2012-
bool GetBit(int n) const { return (UsedChars[n >> 3] & (1 << (n & 7))) != 0; }
2013-
void SetBit(int n) { UsedChars[n >> 3] |= 1 << (n & 7); } // Set bit 'c' in the array
2014-
void AddChar(ImWchar c) { SetBit(c); } // Add character
2015-
IMGUI_API void AddText(const char* text, const char* text_end = NULL); // Add string (each character of the UTF-8 string are added)
2016-
IMGUI_API void AddRanges(const ImWchar* ranges); // Add ranges, e.g. builder.AddRanges(ImFontAtlas::GetGlyphRangesDefault()) to force add all of ASCII/Latin+Ext
2017-
IMGUI_API void BuildRanges(ImVector<ImWchar>* out_ranges); // Output new ranges
2018-
};
2019-
20202022
//-------------------------------------------
20212023
// Custom Rectangles/Glyphs API
20222024
//-------------------------------------------
@@ -2065,6 +2067,10 @@ struct ImFontAtlas
20652067
ImVector<CustomRect> CustomRects; // Rectangles for packing custom texture data into the atlas.
20662068
ImVector<ImFontConfig> ConfigData; // Internal data
20672069
int CustomRectIds[1]; // Identifiers of custom texture rectangle used by ImFontAtlas/ImDrawList
2070+
2071+
#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS
2072+
typedef ImFontGlyphRangesBuilder GlyphRangesBuilder; // OBSOLETE 1.67+
2073+
#endif
20682074
};
20692075

20702076
// Font runtime data and rendering

imgui_draw.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ Index of this file:
1212
// [SECTION] Helpers ShadeVertsXXX functions
1313
// [SECTION] ImFontConfig
1414
// [SECTION] ImFontAtlas
15-
// [SECTION] ImFontAtlas glyph ranges helpers + GlyphRangesBuilder
15+
// [SECTION] ImFontAtlas glyph ranges helpers
16+
// [SECTION] ImFontGlyphRangesBuilder
1617
// [SECTION] ImFont
1718
// [SECTION] Internal Render Helpers
1819
// [SECTION] Decompression code
@@ -2092,15 +2093,15 @@ static void UnpackAccumulativeOffsetsIntoRanges(int base_codepoint, const short*
20922093
}
20932094

20942095
//-------------------------------------------------------------------------
2095-
// [SECTION] ImFontAtlas glyph ranges helpers + GlyphRangesBuilder
2096+
// [SECTION] ImFontAtlas glyph ranges helpers
20962097
//-------------------------------------------------------------------------
20972098

20982099
const ImWchar* ImFontAtlas::GetGlyphRangesChineseSimplifiedCommon()
20992100
{
21002101
// Store 2500 regularly used characters for Simplified Chinese.
21012102
// Sourced from https://zh.wiktionary.org/wiki/%E9%99%84%E5%BD%95:%E7%8E%B0%E4%BB%A3%E6%B1%89%E8%AF%AD%E5%B8%B8%E7%94%A8%E5%AD%97%E8%A1%A8
21022103
// This table covers 97.97% of all characters used during the month in July, 1987.
2103-
// You can use ImFontAtlas::GlyphRangesBuilder to create your own ranges derived from this, by merging existing ranges or adding new characters.
2104+
// You can use ImFontGlyphRangesBuilder to create your own ranges derived from this, by merging existing ranges or adding new characters.
21042105
// (Stored as accumulative offsets from the initial unicode codepoint 0x4E00. This encoding is designed to helps us compact the source code size.)
21052106
static const short accumulative_offsets_from_0x4E00[] =
21062107
{
@@ -2166,7 +2167,7 @@ const ImWchar* ImFontAtlas::GetGlyphRangesJapanese()
21662167
// 1946 common ideograms code points for Japanese
21672168
// Sourced from http://theinstructionlimit.com/common-kanji-character-ranges-for-xna-spritefont-rendering
21682169
// FIXME: Source a list of the revised 2136 Joyo Kanji list from 2010 and rebuild this.
2169-
// You can use ImFontAtlas::GlyphRangesBuilder to create your own ranges derived from this, by merging existing ranges or adding new characters.
2170+
// You can use ImFontGlyphRangesBuilder to create your own ranges derived from this, by merging existing ranges or adding new characters.
21702171
// (Stored as accumulative offsets from the initial unicode codepoint 0x4E00. This encoding is designed to helps us compact the source code size.)
21712172
static const short accumulative_offsets_from_0x4E00[] =
21722173
{
@@ -2244,7 +2245,11 @@ const ImWchar* ImFontAtlas::GetGlyphRangesThai()
22442245
return &ranges[0];
22452246
}
22462247

2247-
void ImFontAtlas::GlyphRangesBuilder::AddText(const char* text, const char* text_end)
2248+
//-----------------------------------------------------------------------------
2249+
// [SECTION] ImFontGlyphRangesBuilder
2250+
//-----------------------------------------------------------------------------
2251+
2252+
void ImFontGlyphRangesBuilder::AddText(const char* text, const char* text_end)
22482253
{
22492254
while (text_end ? (text < text_end) : *text)
22502255
{
@@ -2258,14 +2263,14 @@ void ImFontAtlas::GlyphRangesBuilder::AddText(const char* text, const char* text
22582263
}
22592264
}
22602265

2261-
void ImFontAtlas::GlyphRangesBuilder::AddRanges(const ImWchar* ranges)
2266+
void ImFontGlyphRangesBuilder::AddRanges(const ImWchar* ranges)
22622267
{
22632268
for (; ranges[0]; ranges += 2)
22642269
for (ImWchar c = ranges[0]; c <= ranges[1]; c++)
22652270
AddChar(c);
22662271
}
22672272

2268-
void ImFontAtlas::GlyphRangesBuilder::BuildRanges(ImVector<ImWchar>* out_ranges)
2273+
void ImFontGlyphRangesBuilder::BuildRanges(ImVector<ImWchar>* out_ranges)
22692274
{
22702275
for (int n = 0; n < 0x10000; n++)
22712276
if (GetBit(n))

misc/fonts/README.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ Mind the fact that some graphics drivers have texture size limitation.
119119
If you are building a PC application, mind the fact that your users may use hardware with lower limitations than yours.
120120
Some solutions:
121121

122-
- 1) Reduce glyphs ranges by calculating them from source localization data. You can use ImFont::GlyphRangesBuilder for this purpose,
123-
this will be the biggest win.
122+
- 1) Reduce glyphs ranges by calculating them from source localization data.
123+
You can use ImFontGlyphRangesBuilder for this purpose, this will be the biggest win!
124124
- 2) You may reduce oversampling, e.g. config.OversampleH = config.OversampleV = 1, this will largely reduce your texture size.
125125
- 3) Set io.Fonts.TexDesiredWidth to specify a texture width to minimize texture height (see comment in ImFontAtlas::Build function).
126126
- 4) Set io.Fonts.Flags |= ImFontAtlasFlags_NoPowerOfTwoHeight; to disable rounding the texture height to the next power of two.
@@ -177,11 +177,11 @@ Also note that correct sRGB space blending will have an important effect on your
177177
BUILDING CUSTOM GLYPH RANGES
178178
---------------------------------------
179179

180-
You can use the ImFontAtlas::GlyphRangesBuilder helper to create glyph ranges based on text input.
180+
You can use the ImFontGlyphRangesBuilder helper to create glyph ranges based on text input.
181181
For example: for a game where your script is known, if you can feed your entire script to it and only build the characters the game needs.
182182

183183
ImVector<ImWchar> ranges;
184-
ImFontAtlas::GlyphRangesBuilder builder;
184+
ImFontGlyphRangesBuilder builder;
185185
builder.AddText("Hello world"); // Add a string (here "Hello world" contains 7 unique characters)
186186
builder.AddChar(0x7262); // Add a specific character
187187
builder.AddRanges(io.Fonts->GetGlyphRangesJapanese()); // Add one of the default ranges

0 commit comments

Comments
 (0)