mirror of
https://github.com/Drezil/imgui.git
synced 2024-11-22 03:47:00 +00:00
Internals: Replace unsigned short with ImWchar when dealing with character storage. (#2078)
This commit is contained in:
parent
d014d0285a
commit
201fcfd2e5
4
imgui.h
4
imgui.h
@ -1920,7 +1920,7 @@ struct ImFont
|
||||
ImVec2 DisplayOffset; // = (0.f,0.f) // Offset font rendering by xx pixels
|
||||
ImVector<ImFontGlyph> Glyphs; // // All glyphs.
|
||||
ImVector<float> IndexAdvanceX; // // Sparse. Glyphs->AdvanceX in a directly indexable way (more cache-friendly, for CalcTextSize functions which are often bottleneck in large UI).
|
||||
ImVector<unsigned short> IndexLookup; // // Sparse. Index glyphs by Unicode code-point.
|
||||
ImVector<ImWchar> IndexLookup; // // Sparse. Index glyphs by Unicode code-point.
|
||||
const ImFontGlyph* FallbackGlyph; // == FindGlyph(FontFallbackChar)
|
||||
float FallbackAdvanceX; // == FallbackGlyph->AdvanceX
|
||||
ImWchar FallbackChar; // = '?' // Replacement glyph if one isn't found. Only set via SetFallbackChar()
|
||||
@ -1949,7 +1949,7 @@ struct ImFont
|
||||
// 'wrap_width' enable automatic word-wrapping across multiple lines to fit into given width. 0.0f to disable.
|
||||
IMGUI_API ImVec2 CalcTextSizeA(float size, float max_width, float wrap_width, const char* text_begin, const char* text_end = NULL, const char** remaining = NULL) const; // utf8
|
||||
IMGUI_API const char* CalcWordWrapPositionA(float scale, const char* text, const char* text_end, float wrap_width) const;
|
||||
IMGUI_API void RenderChar(ImDrawList* draw_list, float size, ImVec2 pos, ImU32 col, unsigned short c) const;
|
||||
IMGUI_API void RenderChar(ImDrawList* draw_list, float size, ImVec2 pos, ImU32 col, ImWchar c) const;
|
||||
IMGUI_API void RenderText(ImDrawList* draw_list, float size, ImVec2 pos, ImU32 col, const ImVec4& clip_rect, const char* text_begin, const char* text_end, float wrap_width = 0.0f, bool cpu_fine_clip = false) const;
|
||||
|
||||
// [Internal]
|
||||
|
@ -1894,7 +1894,7 @@ bool ImFontAtlasBuildWithStbTruetype(ImFontAtlas* atlas)
|
||||
continue;
|
||||
|
||||
const int codepoint = range.first_unicode_codepoint_in_range + char_idx;
|
||||
if (cfg.MergeMode && dst_font->FindGlyphNoFallback((unsigned short)codepoint))
|
||||
if (cfg.MergeMode && dst_font->FindGlyphNoFallback((ImWchar)codepoint))
|
||||
continue;
|
||||
|
||||
float char_advance_x_org = pc.xadvance;
|
||||
@ -2316,21 +2316,21 @@ void ImFont::BuildLookupTable()
|
||||
{
|
||||
int codepoint = (int)Glyphs[i].Codepoint;
|
||||
IndexAdvanceX[codepoint] = Glyphs[i].AdvanceX;
|
||||
IndexLookup[codepoint] = (unsigned short)i;
|
||||
IndexLookup[codepoint] = (ImWchar)i;
|
||||
}
|
||||
|
||||
// Create a glyph to handle TAB
|
||||
// FIXME: Needs proper TAB handling but it needs to be contextualized (or we could arbitrary say that each string starts at "column 0" ?)
|
||||
if (FindGlyph((unsigned short)' '))
|
||||
if (FindGlyph((ImWchar)' '))
|
||||
{
|
||||
if (Glyphs.back().Codepoint != '\t') // So we can call this function multiple times
|
||||
Glyphs.resize(Glyphs.Size + 1);
|
||||
ImFontGlyph& tab_glyph = Glyphs.back();
|
||||
tab_glyph = *FindGlyph((unsigned short)' ');
|
||||
tab_glyph = *FindGlyph((ImWchar)' ');
|
||||
tab_glyph.Codepoint = '\t';
|
||||
tab_glyph.AdvanceX *= 4;
|
||||
IndexAdvanceX[(int)tab_glyph.Codepoint] = (float)tab_glyph.AdvanceX;
|
||||
IndexLookup[(int)tab_glyph.Codepoint] = (unsigned short)(Glyphs.Size-1);
|
||||
IndexLookup[(int)tab_glyph.Codepoint] = (ImWchar)(Glyphs.Size-1);
|
||||
}
|
||||
|
||||
FallbackGlyph = FindGlyphNoFallback(FallbackChar);
|
||||
@ -2352,7 +2352,7 @@ void ImFont::GrowIndex(int new_size)
|
||||
if (new_size <= IndexLookup.Size)
|
||||
return;
|
||||
IndexAdvanceX.resize(new_size, -1.0f);
|
||||
IndexLookup.resize(new_size, (unsigned short)-1);
|
||||
IndexLookup.resize(new_size, (ImWchar)-1);
|
||||
}
|
||||
|
||||
// x0/y0/x1/y1 are offset from the character upper-left layout position, in pixels. Therefore x0/y0 are often fairly close to zero.
|
||||
@ -2385,13 +2385,13 @@ void ImFont::AddRemapChar(ImWchar dst, ImWchar src, bool overwrite_dst)
|
||||
IM_ASSERT(IndexLookup.Size > 0); // Currently this can only be called AFTER the font has been built, aka after calling ImFontAtlas::GetTexDataAs*() function.
|
||||
int index_size = IndexLookup.Size;
|
||||
|
||||
if (dst < index_size && IndexLookup.Data[dst] == (unsigned short)-1 && !overwrite_dst) // 'dst' already exists
|
||||
if (dst < index_size && IndexLookup.Data[dst] == (ImWchar)-1 && !overwrite_dst) // 'dst' already exists
|
||||
return;
|
||||
if (src >= index_size && dst >= index_size) // both 'dst' and 'src' don't exist -> no-op
|
||||
return;
|
||||
|
||||
GrowIndex(dst + 1);
|
||||
IndexLookup[dst] = (src < index_size) ? IndexLookup.Data[src] : (unsigned short)-1;
|
||||
IndexLookup[dst] = (src < index_size) ? IndexLookup.Data[src] : (ImWchar)-1;
|
||||
IndexAdvanceX[dst] = (src < index_size) ? IndexAdvanceX.Data[src] : 1.0f;
|
||||
}
|
||||
|
||||
@ -2399,8 +2399,8 @@ const ImFontGlyph* ImFont::FindGlyph(ImWchar c) const
|
||||
{
|
||||
if (c >= IndexLookup.Size)
|
||||
return FallbackGlyph;
|
||||
const unsigned short i = IndexLookup[c];
|
||||
if (i == (unsigned short)-1)
|
||||
const ImWchar i = IndexLookup[c];
|
||||
if (i == (ImWchar)-1)
|
||||
return FallbackGlyph;
|
||||
return &Glyphs.Data[i];
|
||||
}
|
||||
@ -2409,8 +2409,8 @@ const ImFontGlyph* ImFont::FindGlyphNoFallback(ImWchar c) const
|
||||
{
|
||||
if (c >= IndexLookup.Size)
|
||||
return NULL;
|
||||
const unsigned short i = IndexLookup[c];
|
||||
if (i == (unsigned short)-1)
|
||||
const ImWchar i = IndexLookup[c];
|
||||
if (i == (ImWchar)-1)
|
||||
return NULL;
|
||||
return &Glyphs.Data[i];
|
||||
}
|
||||
@ -2608,7 +2608,7 @@ ImVec2 ImFont::CalcTextSizeA(float size, float max_width, float wrap_width, cons
|
||||
return text_size;
|
||||
}
|
||||
|
||||
void ImFont::RenderChar(ImDrawList* draw_list, float size, ImVec2 pos, ImU32 col, unsigned short c) const
|
||||
void ImFont::RenderChar(ImDrawList* draw_list, float size, ImVec2 pos, ImU32 col, ImWchar c) const
|
||||
{
|
||||
if (c == ' ' || c == '\t' || c == '\n' || c == '\r') // Match behavior of RenderText(), those 4 codepoints are hard-coded.
|
||||
return;
|
||||
@ -2733,7 +2733,7 @@ void ImFont::RenderText(ImDrawList* draw_list, float size, ImVec2 pos, ImU32 col
|
||||
}
|
||||
|
||||
float char_width = 0.0f;
|
||||
if (const ImFontGlyph* glyph = FindGlyph((unsigned short)c))
|
||||
if (const ImFontGlyph* glyph = FindGlyph((ImWchar)c))
|
||||
{
|
||||
char_width = glyph->AdvanceX * scale;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user