mirror of
https://github.com/Drezil/imgui.git
synced 2024-11-15 01:17:00 +00:00
ImFont: comments, minor bits
This commit is contained in:
parent
c02f9b58ef
commit
6ae8062ca0
17
imgui.cpp
17
imgui.cpp
@ -9762,8 +9762,7 @@ ImFont* ImFontAtlas::AddFontDefault()
|
|||||||
unsigned int ttf_compressed_size;
|
unsigned int ttf_compressed_size;
|
||||||
const void* ttf_compressed;
|
const void* ttf_compressed;
|
||||||
GetDefaultCompressedFontDataTTF(&ttf_compressed, &ttf_compressed_size);
|
GetDefaultCompressedFontDataTTF(&ttf_compressed, &ttf_compressed_size);
|
||||||
ImFont* font = AddFontFromMemoryCompressedTTF(ttf_compressed, ttf_compressed_size, 13.0f, GetGlyphRangesDefault(), 0);
|
return AddFontFromMemoryCompressedTTF(ttf_compressed, ttf_compressed_size, 13.0f, GetGlyphRangesDefault(), 0);
|
||||||
return font;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ImFont* ImFontAtlas::AddFontFromFileTTF(const char* filename, float size_pixels, const ImWchar* glyph_ranges, int font_no)
|
ImFont* ImFontAtlas::AddFontFromFileTTF(const char* filename, float size_pixels, const ImWchar* glyph_ranges, int font_no)
|
||||||
@ -9775,9 +9774,7 @@ ImFont* ImFontAtlas::AddFontFromFileTTF(const char* filename, float size_pixels,
|
|||||||
IM_ASSERT(0); // Could not load file.
|
IM_ASSERT(0); // Could not load file.
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
return AddFontFromMemoryTTF(data, data_size, size_pixels, glyph_ranges, font_no);
|
||||||
ImFont* font = AddFontFromMemoryTTF(data, data_size, size_pixels, glyph_ranges, font_no);
|
|
||||||
return font;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Transfer ownership of 'ttf_data' to ImFontAtlas, will be deleted after Build()
|
// Transfer ownership of 'ttf_data' to ImFontAtlas, will be deleted after Build()
|
||||||
@ -9808,14 +9805,10 @@ ImFont* ImFontAtlas::AddFontFromMemoryTTF(void* ttf_data, int ttf_size, float si
|
|||||||
|
|
||||||
ImFont* ImFontAtlas::AddFontFromMemoryCompressedTTF(const void* compressed_ttf_data, int compressed_ttf_size, float size_pixels, const ImWchar* glyph_ranges, int font_no)
|
ImFont* ImFontAtlas::AddFontFromMemoryCompressedTTF(const void* compressed_ttf_data, int compressed_ttf_size, float size_pixels, const ImWchar* glyph_ranges, int font_no)
|
||||||
{
|
{
|
||||||
// Decompress
|
|
||||||
const unsigned int buf_decompressed_size = stb_decompress_length((unsigned char*)compressed_ttf_data);
|
const unsigned int buf_decompressed_size = stb_decompress_length((unsigned char*)compressed_ttf_data);
|
||||||
unsigned char* buf_decompressed_data = (unsigned char *)ImGui::MemAlloc(buf_decompressed_size);
|
unsigned char* buf_decompressed_data = (unsigned char *)ImGui::MemAlloc(buf_decompressed_size);
|
||||||
stb_decompress(buf_decompressed_data, (unsigned char*)compressed_ttf_data, (unsigned int)compressed_ttf_size);
|
stb_decompress(buf_decompressed_data, (unsigned char*)compressed_ttf_data, (unsigned int)compressed_ttf_size);
|
||||||
|
return AddFontFromMemoryTTF(buf_decompressed_data, (int)buf_decompressed_size, size_pixels, glyph_ranges, font_no);
|
||||||
// Add
|
|
||||||
ImFont* font = AddFontFromMemoryTTF(buf_decompressed_data, (int)buf_decompressed_size, size_pixels, glyph_ranges, font_no);
|
|
||||||
return font;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ImFontAtlas::Build()
|
bool ImFontAtlas::Build()
|
||||||
@ -9983,8 +9976,6 @@ bool ImFontAtlas::Build()
|
|||||||
// Cleanup temporaries
|
// Cleanup temporaries
|
||||||
ImGui::MemFree(buf_packedchars);
|
ImGui::MemFree(buf_packedchars);
|
||||||
ImGui::MemFree(buf_ranges);
|
ImGui::MemFree(buf_ranges);
|
||||||
buf_packedchars = NULL;
|
|
||||||
buf_ranges = NULL;
|
|
||||||
|
|
||||||
// Render into our custom data block
|
// Render into our custom data block
|
||||||
RenderCustomTexData(1, &extra_rects);
|
RenderCustomTexData(1, &extra_rects);
|
||||||
@ -11185,7 +11176,7 @@ void ImGui::ShowTestWindow(bool* opened)
|
|||||||
if (ImGui::TreeNode("Details"))
|
if (ImGui::TreeNode("Details"))
|
||||||
{
|
{
|
||||||
ImGui::DragFloat("font scale", &font->Scale, 0.005f, 0.3f, 2.0f, "%.1f"); // scale only this font
|
ImGui::DragFloat("font scale", &font->Scale, 0.005f, 0.3f, 2.0f, "%.1f"); // scale only this font
|
||||||
ImGui::Text("Ascent: %f, Descent: %f", font->Ascent, font->Descent);
|
ImGui::Text("Ascent: %f, Descent: %f, Height: %f", font->Ascent, font->Descent, font->Ascent - font->Descent);
|
||||||
ImGui::Text("Fallback character: '%c' (%d)", font->FallbackChar, font->FallbackChar);
|
ImGui::Text("Fallback character: '%c' (%d)", font->FallbackChar, font->FallbackChar);
|
||||||
ImGui::TreePop();
|
ImGui::TreePop();
|
||||||
}
|
}
|
||||||
|
32
imgui.h
32
imgui.h
@ -1175,27 +1175,27 @@ struct ImFontAtlas
|
|||||||
struct ImFont
|
struct ImFont
|
||||||
{
|
{
|
||||||
// Members: Settings
|
// Members: Settings
|
||||||
float FontSize; // <user set> // Height of characters, set during loading (don't change after loading)
|
float FontSize; // <user set> // Height of characters, set during loading (don't change after loading)
|
||||||
float Scale; // = 1.0f // Base font scale, multiplied by the per-window font scale which you can adjust with SetFontScale()
|
float Scale; // = 1.0f // Base font scale, multiplied by the per-window font scale which you can adjust with SetFontScale()
|
||||||
ImVec2 DisplayOffset; // = (0.0f,0.0f) // Offset font rendering by xx pixels
|
ImVec2 DisplayOffset; // = (0.0f,0.0f) // Offset font rendering by xx pixels
|
||||||
ImWchar FallbackChar; // = '?' // Replacement glyph if one isn't found. Only set via SetFallbackChar()
|
ImWchar FallbackChar; // = '?' // Replacement glyph if one isn't found. Only set via SetFallbackChar()
|
||||||
|
|
||||||
// Members: Runtime data
|
// Members: Runtime data
|
||||||
struct Glyph
|
struct Glyph
|
||||||
{
|
{
|
||||||
ImWchar Codepoint;
|
ImWchar Codepoint;
|
||||||
float XAdvance;
|
float XAdvance;
|
||||||
float X0, Y0, X1, Y1;
|
float X0, Y0, X1, Y1;
|
||||||
float U0, V0, U1, V1; // Texture coordinates
|
float U0, V0, U1, V1; // Texture coordinates
|
||||||
};
|
};
|
||||||
float Ascent; // Distance from top to bottom of e.g. 'A' [0..FontSize]
|
float Ascent; // Distance from top to bottom of e.g. 'A' [0..FontSize]
|
||||||
float Descent; //
|
float Descent; //
|
||||||
ImFontAtlas* ContainerAtlas; // What we has been loaded into
|
ImFontAtlas* ContainerAtlas; // What we has been loaded into
|
||||||
ImVector<Glyph> Glyphs;
|
ImVector<Glyph> Glyphs;
|
||||||
const Glyph* FallbackGlyph; // == FindGlyph(FontFallbackChar)
|
const Glyph* FallbackGlyph; // == FindGlyph(FontFallbackChar)
|
||||||
float FallbackXAdvance; //
|
float FallbackXAdvance; //
|
||||||
ImVector<float> IndexXAdvance; // Glyphs->XAdvance directly indexable (for CalcTextSize functions which are often bottleneck in large UI)
|
ImVector<float> IndexXAdvance; // Sparse. Glyphs->XAdvance directly indexable (for CalcTextSize functions which are often bottleneck in large UI)
|
||||||
ImVector<int> IndexLookup; // Index glyphs by Unicode code-point
|
ImVector<int> IndexLookup; // Sparse. Index glyphs by Unicode code-point
|
||||||
|
|
||||||
// Methods
|
// Methods
|
||||||
IMGUI_API ImFont();
|
IMGUI_API ImFont();
|
||||||
|
Loading…
Reference in New Issue
Block a user