mirror of
https://github.com/Drezil/imgui.git
synced 2024-11-21 19:37:01 +00:00
Renamed ImFont::GlyphRangesBuilder to ImFontGlyphRangesBuilder. Keep redirection typedef (will obsolete).
This commit is contained in:
parent
1353c74dcf
commit
5cb7ce2085
@ -39,6 +39,7 @@ Breaking Changes:
|
||||
The addition of new configuration options in the Docking branch is pushing for a little reorganization of those names.
|
||||
- Made it illegal to call Begin("") with an empty string. This somehow accidentally worked before but had various
|
||||
undesirable side-effect as the window would have ID zero. In particular it is causing problems in viewport/docking branches.
|
||||
- Renamed ImFontAtlas::GlyphRangesBuilder to ImFontGlyphRangesBuilder. Keep redirection typedef (will obsolete).
|
||||
|
||||
Other Changes:
|
||||
- Added BETA api for Tab Bar/Tabs widgets: (#261, #351)
|
||||
@ -734,6 +735,7 @@ Breaking Changes:
|
||||
- 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)
|
||||
- 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)
|
||||
- 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.
|
||||
- Renamed ImFont::Glyph to ImFontGlyph. Keep redirection typedef (will obsolete).
|
||||
|
||||
Other Changes:
|
||||
|
||||
|
@ -363,7 +363,8 @@ CODE
|
||||
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/01/04 (1.67) - renamed io.InputCharacters[], marked internal as was always intended. Please don't access directly, and use AddInputCharacter() instead!
|
||||
- 2019/01/06 (1.67) - renamed io.InputCharacters[], marked internal as was always intended. Please don't access directly, and use AddInputCharacter() instead!
|
||||
- 2019/01/06 (1.67) - renamed ImFontAtlas::GlyphRangesBuilder to ImFontGlyphRangesBuilder. Keep redirection typedef (will obsolete).
|
||||
- 2018/12/10 (1.67) - renamed io.ConfigResizeWindowsFromEdges to io.ConfigWindowsResizeFromEdges as we are doing a large pass on configuration flags.
|
||||
- 2018/10/12 (1.66) - renamed misc/stl/imgui_stl.* to misc/cpp/imgui_stdlib.* in prevision for other C++ helper files.
|
||||
- 2018/09/28 (1.66) - renamed SetScrollHere() to SetScrollHereY(). Kept redirection function (will obsolete).
|
||||
@ -431,6 +432,7 @@ CODE
|
||||
removed the IsItemRectHovered()/IsWindowRectHovered() names introduced in 1.51 since they were merely more consistent names for the two functions we are now obsoleting.
|
||||
- 2017/10/17 (1.52) - marked the old 5-parameters version of Begin() as obsolete (still available). Use SetNextWindowSize()+Begin() instead!
|
||||
- 2017/10/11 (1.52) - renamed AlignFirstTextHeightToWidgets() to AlignTextToFramePadding(). Kept inline redirection function (will obsolete).
|
||||
- 2017/09/26 (1.52) - renamed ImFont::Glyph to ImFontGlyph. Keep redirection typedef (will obsolete).
|
||||
- 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).
|
||||
- 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)".
|
||||
- 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
|
||||
|
||||
// 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)
|
||||
ImVector<ImWchar> ranges;
|
||||
ImFontAtlas::GlyphRangesBuilder builder;
|
||||
ImFontGlyphRangesBuilder builder;
|
||||
builder.AddText("Hello world"); // Add a string (here "Hello world" contains 7 unique characters)
|
||||
builder.AddChar(0x7262); // Add a specific character
|
||||
builder.AddRanges(io.Fonts->GetGlyphRangesJapanese()); // Add one of the default ranges
|
||||
|
46
imgui.h
46
imgui.h
@ -86,15 +86,17 @@ Index of this file:
|
||||
// Forward declarations and basic types
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
struct ImDrawChannel; // Temporary storage for outputting drawing commands out of order, used by ImDrawList::ChannelsSplit()
|
||||
struct ImDrawCmd; // A single draw command within a parent ImDrawList (generally maps to 1 GPU draw call)
|
||||
struct ImDrawData; // All draw command lists required to render the frame
|
||||
struct ImDrawChannel; // Temporary storage for ImDrawList ot output draw commands out of order, used by ImDrawList::ChannelsSplit()
|
||||
struct ImDrawCmd; // A single draw command within a parent ImDrawList (generally maps to 1 GPU draw call, unless it is a callback)
|
||||
struct ImDrawData; // All draw command lists required to render the frame + pos/size coordinates to use for the projection matrix.
|
||||
struct ImDrawList; // A single draw command list (generally one per window, conceptually you may see this as a dynamic "mesh" builder)
|
||||
struct ImDrawListSharedData; // Data shared among multiple draw lists (typically owned by parent ImGui context, but you may create one yourself)
|
||||
struct ImDrawVert; // A single vertex (20 bytes by default, override layout with IMGUI_OVERRIDE_DRAWVERT_STRUCT_LAYOUT)
|
||||
struct ImDrawVert; // A single vertex (pos + uv + col = 20 bytes by default. Override layout with IMGUI_OVERRIDE_DRAWVERT_STRUCT_LAYOUT)
|
||||
struct ImFont; // Runtime data for a single font within a parent ImFontAtlas
|
||||
struct ImFontAtlas; // Runtime data for multiple fonts, bake multiple fonts into a single texture, TTF/OTF font loader
|
||||
struct ImFontConfig; // Configuration data when adding a font or merging fonts
|
||||
struct ImFontGlyph; // A single font glyph (code point + coordinates within in ImFontAtlas + offset)
|
||||
struct ImFontGlyphRangesBuilder; // Helper to build glyph ranges from text/string data
|
||||
struct ImColor; // Helper functions to create a color that can be converted to either u32 or float4 (*OBSOLETE* please avoid using)
|
||||
#ifndef ImTextureID
|
||||
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
|
||||
struct ImGuiSizeCallbackData; // Callback data when using SetNextWindowSizeConstraints() (rare/advanced use)
|
||||
struct ImGuiStorage; // Helper for key->value storage
|
||||
struct ImGuiStyle; // Runtime data for styling/colors
|
||||
struct ImGuiTextFilter; // Helper to parse and apply text filters (e.g. "aaaaa[,bbbb][,ccccc]")
|
||||
struct ImGuiTextBuffer; // Helper to hold and append into a text buffer (~string builder)
|
||||
struct ImGuiTextFilter; // Helper to parse and apply text filters (e.g. "aaaaa[,bbbb][,ccccc]")
|
||||
|
||||
// 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)
|
||||
// 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
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Font API (ImFontConfig, ImFontGlyph, ImFontAtlasFlags, ImFontAtlas, ImFont)
|
||||
// Font API (ImFontConfig, ImFontGlyph, ImFontAtlasFlags, ImFontAtlas, ImFontGlyphRangesBuilder, ImFont)
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
struct ImFontConfig
|
||||
@ -1939,6 +1941,19 @@ struct ImFontGlyph
|
||||
float U0, V0, U1, V1; // Texture coordinates
|
||||
};
|
||||
|
||||
// Helper to build glyph ranges from text/string data. Feed your application strings/characters to it then call BuildRanges().
|
||||
struct ImFontGlyphRangesBuilder
|
||||
{
|
||||
ImVector<unsigned char> UsedChars; // Store 1-bit per Unicode code point (0=unused, 1=used)
|
||||
ImFontGlyphRangesBuilder() { UsedChars.resize(0x10000 / 8); memset(UsedChars.Data, 0, 0x10000 / 8); }
|
||||
bool GetBit(int n) const { return (UsedChars[n >> 3] & (1 << (n & 7))) != 0; }
|
||||
void SetBit(int n) { UsedChars[n >> 3] |= 1 << (n & 7); } // Set bit 'c' in the array
|
||||
void AddChar(ImWchar c) { SetBit(c); } // Add character
|
||||
IMGUI_API void AddText(const char* text, const char* text_end = NULL); // Add string (each character of the UTF-8 string are added)
|
||||
IMGUI_API void AddRanges(const ImWchar* ranges); // Add ranges, e.g. builder.AddRanges(ImFontAtlas::GetGlyphRangesDefault()) to force add all of ASCII/Latin+Ext
|
||||
IMGUI_API void BuildRanges(ImVector<ImWchar>* out_ranges); // Output new ranges
|
||||
};
|
||||
|
||||
enum ImFontAtlasFlags_
|
||||
{
|
||||
ImFontAtlasFlags_None = 0,
|
||||
@ -1995,7 +2010,7 @@ struct ImFontAtlas
|
||||
|
||||
// Helpers to retrieve list of common Unicode ranges (2 value per range, values are inclusive, zero-terminated list)
|
||||
// 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.
|
||||
// NB: Consider using GlyphRangesBuilder to build glyph ranges from textual data.
|
||||
// NB: Consider using ImFontGlyphRangesBuilder to build glyph ranges from textual data.
|
||||
IMGUI_API const ImWchar* GetGlyphRangesDefault(); // Basic Latin, Extended Latin
|
||||
IMGUI_API const ImWchar* GetGlyphRangesKorean(); // Default + Korean characters
|
||||
IMGUI_API const ImWchar* GetGlyphRangesJapanese(); // Default + Hiragana, Katakana, Half-Width, Selection of 1946 Ideographs
|
||||
@ -2004,19 +2019,6 @@ struct ImFontAtlas
|
||||
IMGUI_API const ImWchar* GetGlyphRangesCyrillic(); // Default + about 400 Cyrillic characters
|
||||
IMGUI_API const ImWchar* GetGlyphRangesThai(); // Default + Thai characters
|
||||
|
||||
// Helpers to build glyph ranges from text data. Feed your application strings/characters to it then call BuildRanges().
|
||||
struct GlyphRangesBuilder
|
||||
{
|
||||
ImVector<unsigned char> UsedChars; // Store 1-bit per Unicode code point (0=unused, 1=used)
|
||||
GlyphRangesBuilder() { UsedChars.resize(0x10000 / 8); memset(UsedChars.Data, 0, 0x10000 / 8); }
|
||||
bool GetBit(int n) const { return (UsedChars[n >> 3] & (1 << (n & 7))) != 0; }
|
||||
void SetBit(int n) { UsedChars[n >> 3] |= 1 << (n & 7); } // Set bit 'c' in the array
|
||||
void AddChar(ImWchar c) { SetBit(c); } // Add character
|
||||
IMGUI_API void AddText(const char* text, const char* text_end = NULL); // Add string (each character of the UTF-8 string are added)
|
||||
IMGUI_API void AddRanges(const ImWchar* ranges); // Add ranges, e.g. builder.AddRanges(ImFontAtlas::GetGlyphRangesDefault()) to force add all of ASCII/Latin+Ext
|
||||
IMGUI_API void BuildRanges(ImVector<ImWchar>* out_ranges); // Output new ranges
|
||||
};
|
||||
|
||||
//-------------------------------------------
|
||||
// Custom Rectangles/Glyphs API
|
||||
//-------------------------------------------
|
||||
@ -2065,6 +2067,10 @@ struct ImFontAtlas
|
||||
ImVector<CustomRect> CustomRects; // Rectangles for packing custom texture data into the atlas.
|
||||
ImVector<ImFontConfig> ConfigData; // Internal data
|
||||
int CustomRectIds[1]; // Identifiers of custom texture rectangle used by ImFontAtlas/ImDrawList
|
||||
|
||||
#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS
|
||||
typedef ImFontGlyphRangesBuilder GlyphRangesBuilder; // OBSOLETE 1.67+
|
||||
#endif
|
||||
};
|
||||
|
||||
// Font runtime data and rendering
|
||||
|
@ -12,7 +12,8 @@ Index of this file:
|
||||
// [SECTION] Helpers ShadeVertsXXX functions
|
||||
// [SECTION] ImFontConfig
|
||||
// [SECTION] ImFontAtlas
|
||||
// [SECTION] ImFontAtlas glyph ranges helpers + GlyphRangesBuilder
|
||||
// [SECTION] ImFontAtlas glyph ranges helpers
|
||||
// [SECTION] ImFontGlyphRangesBuilder
|
||||
// [SECTION] ImFont
|
||||
// [SECTION] Internal Render Helpers
|
||||
// [SECTION] Decompression code
|
||||
@ -2092,7 +2093,7 @@ static void UnpackAccumulativeOffsetsIntoRanges(int base_codepoint, const short*
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
// [SECTION] ImFontAtlas glyph ranges helpers + GlyphRangesBuilder
|
||||
// [SECTION] ImFontAtlas glyph ranges helpers
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
const ImWchar* ImFontAtlas::GetGlyphRangesChineseSimplifiedCommon()
|
||||
@ -2100,7 +2101,7 @@ const ImWchar* ImFontAtlas::GetGlyphRangesChineseSimplifiedCommon()
|
||||
// Store 2500 regularly used characters for Simplified Chinese.
|
||||
// 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
|
||||
// This table covers 97.97% of all characters used during the month in July, 1987.
|
||||
// You can use ImFontAtlas::GlyphRangesBuilder to create your own ranges derived from this, by merging existing ranges or adding new characters.
|
||||
// You can use ImFontGlyphRangesBuilder to create your own ranges derived from this, by merging existing ranges or adding new characters.
|
||||
// (Stored as accumulative offsets from the initial unicode codepoint 0x4E00. This encoding is designed to helps us compact the source code size.)
|
||||
static const short accumulative_offsets_from_0x4E00[] =
|
||||
{
|
||||
@ -2166,7 +2167,7 @@ const ImWchar* ImFontAtlas::GetGlyphRangesJapanese()
|
||||
// 1946 common ideograms code points for Japanese
|
||||
// Sourced from http://theinstructionlimit.com/common-kanji-character-ranges-for-xna-spritefont-rendering
|
||||
// FIXME: Source a list of the revised 2136 Joyo Kanji list from 2010 and rebuild this.
|
||||
// You can use ImFontAtlas::GlyphRangesBuilder to create your own ranges derived from this, by merging existing ranges or adding new characters.
|
||||
// You can use ImFontGlyphRangesBuilder to create your own ranges derived from this, by merging existing ranges or adding new characters.
|
||||
// (Stored as accumulative offsets from the initial unicode codepoint 0x4E00. This encoding is designed to helps us compact the source code size.)
|
||||
static const short accumulative_offsets_from_0x4E00[] =
|
||||
{
|
||||
@ -2244,7 +2245,11 @@ const ImWchar* ImFontAtlas::GetGlyphRangesThai()
|
||||
return &ranges[0];
|
||||
}
|
||||
|
||||
void ImFontAtlas::GlyphRangesBuilder::AddText(const char* text, const char* text_end)
|
||||
//-----------------------------------------------------------------------------
|
||||
// [SECTION] ImFontGlyphRangesBuilder
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void ImFontGlyphRangesBuilder::AddText(const char* text, const char* text_end)
|
||||
{
|
||||
while (text_end ? (text < text_end) : *text)
|
||||
{
|
||||
@ -2258,14 +2263,14 @@ void ImFontAtlas::GlyphRangesBuilder::AddText(const char* text, const char* text
|
||||
}
|
||||
}
|
||||
|
||||
void ImFontAtlas::GlyphRangesBuilder::AddRanges(const ImWchar* ranges)
|
||||
void ImFontGlyphRangesBuilder::AddRanges(const ImWchar* ranges)
|
||||
{
|
||||
for (; ranges[0]; ranges += 2)
|
||||
for (ImWchar c = ranges[0]; c <= ranges[1]; c++)
|
||||
AddChar(c);
|
||||
}
|
||||
|
||||
void ImFontAtlas::GlyphRangesBuilder::BuildRanges(ImVector<ImWchar>* out_ranges)
|
||||
void ImFontGlyphRangesBuilder::BuildRanges(ImVector<ImWchar>* out_ranges)
|
||||
{
|
||||
for (int n = 0; n < 0x10000; n++)
|
||||
if (GetBit(n))
|
||||
|
@ -119,8 +119,8 @@ Mind the fact that some graphics drivers have texture size limitation.
|
||||
If you are building a PC application, mind the fact that your users may use hardware with lower limitations than yours.
|
||||
Some solutions:
|
||||
|
||||
- 1) Reduce glyphs ranges by calculating them from source localization data. You can use ImFont::GlyphRangesBuilder for this purpose,
|
||||
this will be the biggest win.
|
||||
- 1) Reduce glyphs ranges by calculating them from source localization data.
|
||||
You can use ImFontGlyphRangesBuilder for this purpose, this will be the biggest win!
|
||||
- 2) You may reduce oversampling, e.g. config.OversampleH = config.OversampleV = 1, this will largely reduce your texture size.
|
||||
- 3) Set io.Fonts.TexDesiredWidth to specify a texture width to minimize texture height (see comment in ImFontAtlas::Build function).
|
||||
- 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
|
||||
BUILDING CUSTOM GLYPH RANGES
|
||||
---------------------------------------
|
||||
|
||||
You can use the ImFontAtlas::GlyphRangesBuilder helper to create glyph ranges based on text input.
|
||||
You can use the ImFontGlyphRangesBuilder helper to create glyph ranges based on text input.
|
||||
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.
|
||||
|
||||
ImVector<ImWchar> ranges;
|
||||
ImFontAtlas::GlyphRangesBuilder builder;
|
||||
ImFontGlyphRangesBuilder builder;
|
||||
builder.AddText("Hello world"); // Add a string (here "Hello world" contains 7 unique characters)
|
||||
builder.AddChar(0x7262); // Add a specific character
|
||||
builder.AddRanges(io.Fonts->GetGlyphRangesJapanese()); // Add one of the default ranges
|
||||
|
Loading…
Reference in New Issue
Block a user