ImFont: Renamed ImFont::Glyph to ImFontGlyph (for consistency and so ImFontAtlas types can use it without ordering half of the file). Left a redirection type.

This commit is contained in:
omar 2017-09-26 19:54:30 +02:00
parent 072d6d8cb5
commit 10bb9524eb
4 changed files with 24 additions and 20 deletions

View File

@ -7847,7 +7847,7 @@ bool ImGui::InputTextEx(const char* label, char* buf, int buf_size, const ImVec2
// Password pushes a temporary font with only a fallback glyph
if (is_password)
{
const ImFont::Glyph* glyph = g.Font->FindGlyph('*');
const ImFontGlyph* glyph = g.Font->FindGlyph('*');
ImFont* password_font = &g.InputTextPasswordFont;
password_font->FontSize = g.Font->FontSize;
password_font->Scale = g.Font->Scale;

28
imgui.h
View File

@ -1332,7 +1332,7 @@ struct ImFontConfig
float SizePixels; // // Size in pixels for rasterizer.
int OversampleH, OversampleV; // 3, 1 // Rasterize at higher quality for sub-pixel positioning. We don't use sub-pixel positions on the Y axis.
bool PixelSnapH; // false // Align every glyph to pixel boundary. Useful e.g. if you are merging a non-pixel aligned font with the default font. If enabled, you can set OversampleH/V to 1.
ImVec2 GlyphExtraSpacing; // 0, 0 // Extra spacing (in pixels) between glyphs. Only X axis is supported for now.
ImVec2 GlyphExtraSpacing; // 1, 0 // Extra spacing (in pixels) between glyphs. Only X axis is supported for now.
ImVec2 GlyphOffset; // 0, 0 // Offset all glyphs from this font input.
const ImWchar* GlyphRanges; // NULL // Pointer to a user-provided list of Unicode range (2 value per range, values are inclusive, zero-terminated list). THE ARRAY DATA NEEDS TO PERSIST AS LONG AS THE FONT IS ALIVE.
bool MergeMode; // false // Merge into previous ImFont, so you can combine multiple inputs font into one ImFont (e.g. ASCII font + icons + Japanese glyphs). You may want to use GlyphOffset.y when merge font of different heights.
@ -1346,6 +1346,14 @@ struct ImFontConfig
IMGUI_API ImFontConfig();
};
struct ImFontGlyph
{
ImWchar Codepoint; // 0x0000..0xFFFF
float XAdvance; // Distance to next character (= data from font + ImFontConfig::GlyphExtraSpacing.x baked in)
float X0, Y0, X1, Y1; // Glyph corners
float U0, V0, U1, V1; // Texture coordinates
};
// Load and rasterize multiple TTF/OTF fonts into a same texture.
// Sharing a texture for multiple fonts allows us to reduce the number of draw calls during rendering.
// We also add custom graphic data into the texture that serves for ImGui.
@ -1444,22 +1452,14 @@ struct ImFontAtlas
// ImFontAtlas automatically loads a default embedded font for you when you call GetTexDataAsAlpha8() or GetTexDataAsRGBA32().
struct ImFont
{
struct Glyph
{
ImWchar Codepoint;
float XAdvance;
float X0, Y0, X1, Y1; // Glyph corners
float U0, V0, U1, V1; // Texture coordinates
};
// Members: Hot ~62/78 bytes
float FontSize; // <user set> // Height of characters, set during loading (don't change after loading)
float Scale; // = 1.f // Base font scale, multiplied by the per-window font scale which you can adjust with SetFontScale()
ImVec2 DisplayOffset; // = (0.f,1.f) // Offset font rendering by xx pixels
ImVector<Glyph> Glyphs; // // All glyphs.
ImVector<ImFontGlyph> Glyphs; // // All glyphs.
ImVector<float> IndexXAdvance; // // Sparse. Glyphs->XAdvance 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.
const Glyph* FallbackGlyph; // == FindGlyph(FontFallbackChar)
const ImFontGlyph* FallbackGlyph; // == FindGlyph(FontFallbackChar)
float FallbackXAdvance; // == FallbackGlyph->XAdvance
ImWchar FallbackChar; // = '?' // Replacement glyph if one isn't found. Only set via SetFallbackChar()
@ -1475,7 +1475,7 @@ struct ImFont
IMGUI_API ~ImFont();
IMGUI_API void Clear();
IMGUI_API void BuildLookupTable();
IMGUI_API const Glyph* FindGlyph(ImWchar c) const;
IMGUI_API const ImFontGlyph*FindGlyph(ImWchar c) const;
IMGUI_API void SetFallbackChar(ImWchar c);
float GetCharAdvance(ImWchar c) const { return ((int)c < IndexXAdvance.Size) ? IndexXAdvance[(int)c] : FallbackXAdvance; }
bool IsLoaded() const { return ContainerAtlas != NULL; }
@ -1491,6 +1491,10 @@ struct ImFont
IMGUI_API void GrowIndex(int new_size);
IMGUI_API void AddGlyph(ImWchar c, float x0, float y0, float x1, float y1, float u0, float v0, float u1, float v1, float x_advance);
IMGUI_API void AddRemapChar(ImWchar dst, ImWchar src, bool overwrite_dst = true); // Makes 'dst' character/glyph points to 'src' character/glyph. Currently needs to be called AFTER fonts have been built.
#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS
typedef ImFontGlyph Glyph; // OBSOLETE 1.52+
#endif
};
#if defined(__clang__)

View File

@ -1926,7 +1926,7 @@ void ImGui::ShowStyleEditor(ImGuiStyle* ref)
if (ImGui::TreeNode("Glyphs", "Glyphs (%d)", font->Glyphs.Size))
{
// Display all glyphs of the fonts in separate pages of 256 characters
const ImFont::Glyph* glyph_fallback = font->FallbackGlyph; // Forcefully/dodgily make FindGlyph() return NULL on fallback, which isn't the default behavior.
const ImFontGlyph* glyph_fallback = font->FallbackGlyph; // Forcefully/dodgily make FindGlyph() return NULL on fallback, which isn't the default behavior.
font->FallbackGlyph = NULL;
for (int base = 0; base < 0x10000; base += 256)
{
@ -1943,7 +1943,7 @@ void ImGui::ShowStyleEditor(ImGuiStyle* ref)
{
ImVec2 cell_p1(base_pos.x + (n % 16) * (cell_size.x + cell_spacing), base_pos.y + (n / 16) * (cell_size.y + cell_spacing));
ImVec2 cell_p2(cell_p1.x + cell_size.x, cell_p1.y + cell_size.y);
const ImFont::Glyph* glyph = font->FindGlyph((ImWchar)(base+n));;
const ImFontGlyph* glyph = font->FindGlyph((ImWchar)(base+n));;
draw_list->AddRect(cell_p1, cell_p2, glyph ? IM_COL32(255,255,255,100) : IM_COL32(255,255,255,50));
font->RenderChar(draw_list, cell_size.x, cell_p1, ImGui::GetColorU32(ImGuiCol_Text), (ImWchar)(base+n)); // We use ImFont::RenderChar as a shortcut because we don't have UTF-8 conversion functions available to generate a string.
if (glyph && ImGui::IsMouseHoveringRect(cell_p1, cell_p2))

View File

@ -1885,7 +1885,7 @@ void ImFont::BuildLookupTable()
{
if (Glyphs.back().Codepoint != '\t') // So we can call this function multiple times
Glyphs.resize(Glyphs.Size + 1);
ImFont::Glyph& tab_glyph = Glyphs.back();
ImFontGlyph& tab_glyph = Glyphs.back();
tab_glyph = *FindGlyph((unsigned short)' ');
tab_glyph.Codepoint = '\t';
tab_glyph.XAdvance *= 4;
@ -1919,7 +1919,7 @@ void ImFont::GrowIndex(int new_size)
void ImFont::AddGlyph(ImWchar codepoint, float x0, float y0, float x1, float y1, float u0, float v0, float u1, float v1, float x_advance)
{
Glyphs.resize(Glyphs.Size + 1);
ImFont::Glyph& glyph = Glyphs.back();
ImFontGlyph& glyph = Glyphs.back();
glyph.Codepoint = (ImWchar)codepoint;
glyph.X0 = x0;
glyph.Y0 = y0;
@ -1953,7 +1953,7 @@ void ImFont::AddRemapChar(ImWchar dst, ImWchar src, bool overwrite_dst)
IndexXAdvance[dst] = (src < index_size) ? IndexXAdvance.Data[src] : 1.0f;
}
const ImFont::Glyph* ImFont::FindGlyph(unsigned short c) const
const ImFontGlyph* ImFont::FindGlyph(unsigned short c) const
{
if (c < IndexLookup.Size)
{
@ -2161,7 +2161,7 @@ void ImFont::RenderChar(ImDrawList* draw_list, float size, ImVec2 pos, ImU32 col
{
if (c == ' ' || c == '\t' || c == '\n' || c == '\r') // Match behavior of RenderText(), those 4 codepoints are hard-coded.
return;
if (const Glyph* glyph = FindGlyph(c))
if (const ImFontGlyph* glyph = FindGlyph(c))
{
float scale = (size >= 0.0f) ? (size / FontSize) : 1.0f;
pos.x = (float)(int)pos.x + DisplayOffset.x;
@ -2265,7 +2265,7 @@ void ImFont::RenderText(ImDrawList* draw_list, float size, ImVec2 pos, ImU32 col
}
float char_width = 0.0f;
if (const Glyph* glyph = FindGlyph((unsigned short)c))
if (const ImFontGlyph* glyph = FindGlyph((unsigned short)c))
{
char_width = glyph->XAdvance * scale;