Skip to content

Commit 57a586b

Browse files
committed
Font: Moved functions to internal block (not enforced). Made ConfigData pointer const. Added link to stb's notes.
1 parent fcdf704 commit 57a586b

File tree

3 files changed

+13
-13
lines changed

3 files changed

+13
-13
lines changed

imgui.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -805,9 +805,9 @@ CODE
805805

806806
// Options
807807
ImFontConfig config;
808-
config.OversampleH = 3;
808+
config.OversampleH = 2;
809809
config.OversampleV = 1;
810-
config.GlyphOffset.y -= 2.0f; // Move everything by 2 pixels up
810+
config.GlyphOffset.y -= 1.0f; // Move everything by 1 pixels up
811811
config.GlyphExtraSpacing.x = 1.0f; // Increase spacing between characters
812812
io.Fonts->AddFontFromFileTTF("myfontfile.ttf", size_pixels, &config);
813813

imgui.h

+10-10
Original file line numberDiff line numberDiff line change
@@ -1914,8 +1914,8 @@ struct ImFontConfig
19141914
bool FontDataOwnedByAtlas; // true // TTF/OTF data ownership taken by the container ImFontAtlas (will delete memory itself).
19151915
int FontNo; // 0 // Index of font within TTF/OTF file
19161916
float SizePixels; // // Size in pixels for rasterizer (more or less maps to the resulting font height).
1917-
int OversampleH; // 3 // Rasterize at higher quality for sub-pixel positioning. We don't use sub-pixel positions on the Y axis.
1918-
int OversampleV; // 1 // Rasterize at higher quality for sub-pixel positioning. We don't use sub-pixel positions on the Y axis.
1917+
int OversampleH; // 3 // Rasterize at higher quality for sub-pixel positioning. Read https://github.com/nothings/stb/blob/master/tests/oversample/README.md for details.
1918+
int OversampleV; // 1 // Rasterize at higher quality for sub-pixel positioning. We don't use sub-pixel positions on the Y axis.
19191919
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.
19201920
ImVec2 GlyphExtraSpacing; // 0, 0 // Extra spacing (in pixels) between glyphs. Only X axis is supported for now.
19211921
ImVec2 GlyphOffset; // 0, 0 // Offset all glyphs from this font input.
@@ -2080,7 +2080,7 @@ struct ImFontAtlas
20802080
struct ImFont
20812081
{
20822082
// Members: Hot ~24/32 bytes (for CalcTextSize)
2083-
ImVector<float> IndexAdvanceX; // 12/16 // out // // Sparse. Glyphs->AdvanceX in a directly indexable way (more cache-friendly, for CalcTextSize functions which are often bottleneck in large UI).
2083+
ImVector<float> IndexAdvanceX; // 12/16 // out // // Sparse. Glyphs->AdvanceX in a directly indexable way (cache-friendly for CalcTextSize functions which only this this info, and are often bottleneck in large UI).
20842084
float FontSize; // 4 // in // <user set> // Height of characters, set during loading (don't change after loading)
20852085
float FallbackAdvanceX; // 4 // out // = FallbackGlyph->AdvanceX
20862086
ImWchar FallbackChar; // 2 // in // = '?' // Replacement glyph if one isn't found. Only set via SetFallbackChar()
@@ -2093,21 +2093,18 @@ struct ImFont
20932093

20942094
// Members: Cold ~28/40 bytes
20952095
ImFontAtlas* ContainerAtlas; // 4-8 // out // // What we has been loaded into
2096-
ImFontConfig* ConfigData; // 4-8 // in // // Pointer within ContainerAtlas->ConfigData
2096+
const ImFontConfig* ConfigData; // 4-8 // in // // Pointer within ContainerAtlas->ConfigData
20972097
short ConfigDataCount; // 2 // in // ~ 1 // Number of ImFontConfig involved in creating this font. Bigger than 1 when merging multiple font sources into one ImFont.
20982098
bool DirtyLookupTables; // 1 // out //
20992099
float Scale; // 4 // in // = 1.f // Base font scale, multiplied by the per-window font scale which you can adjust with SetWindowFontScale()
2100-
float Ascent, Descent; // 8 // out // Ascent: distance from top to bottom of e.g. 'A' [0..FontSize]
2101-
int MetricsTotalSurface;// 4 // out // Total surface in pixels to get an idea of the font rasterization/texture cost (not exact, we approximate the cost of padding between glyphs)
2100+
float Ascent, Descent; // 8 // out // // Ascent: distance from top to bottom of e.g. 'A' [0..FontSize]
2101+
int MetricsTotalSurface;// 4 // out // // Total surface in pixels to get an idea of the font rasterization/texture cost (not exact, we approximate the cost of padding between glyphs)
21022102

21032103
// Methods
21042104
IMGUI_API ImFont();
21052105
IMGUI_API ~ImFont();
2106-
IMGUI_API void ClearOutputData();
2107-
IMGUI_API void BuildLookupTable();
21082106
IMGUI_API const ImFontGlyph*FindGlyph(ImWchar c) const;
21092107
IMGUI_API const ImFontGlyph*FindGlyphNoFallback(ImWchar c) const;
2110-
IMGUI_API void SetFallbackChar(ImWchar c);
21112108
float GetCharAdvance(ImWchar c) const { return ((int)c < IndexAdvanceX.Size) ? IndexAdvanceX[(int)c] : FallbackAdvanceX; }
21122109
bool IsLoaded() const { return ContainerAtlas != NULL; }
21132110
const char* GetDebugName() const { return ConfigData ? ConfigData->Name : "<unknown>"; }
@@ -2119,10 +2116,13 @@ struct ImFont
21192116
IMGUI_API void RenderChar(ImDrawList* draw_list, float size, ImVec2 pos, ImU32 col, ImWchar c) const;
21202117
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;
21212118

2122-
// [Internal]
2119+
// [Internal] Don't use!
2120+
IMGUI_API void BuildLookupTable();
2121+
IMGUI_API void ClearOutputData();
21232122
IMGUI_API void GrowIndex(int new_size);
21242123
IMGUI_API void AddGlyph(ImWchar c, float x0, float y0, float x1, float y1, float u0, float v0, float u1, float v1, float advance_x);
21252124
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.
2125+
IMGUI_API void SetFallbackChar(ImWchar c);
21262126

21272127
#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS
21282128
typedef ImFontGlyph Glyph; // OBSOLETE 1.52+

imgui_demo.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -2913,7 +2913,7 @@ void ImGui::ShowStyleEditor(ImGuiStyle* ref)
29132913
const float surface_sqrt = sqrtf((float)font->MetricsTotalSurface);
29142914
ImGui::Text("Texture surface: %d pixels (approx) ~ %dx%d", font->MetricsTotalSurface, (int)surface_sqrt, (int)surface_sqrt);
29152915
for (int config_i = 0; config_i < font->ConfigDataCount; config_i++)
2916-
if (ImFontConfig* cfg = &font->ConfigData[config_i])
2916+
if (const ImFontConfig* cfg = &font->ConfigData[config_i])
29172917
ImGui::BulletText("Input %d: \'%s\', Oversample: (%d,%d), PixelSnapH: %d", config_i, cfg->Name, cfg->OversampleH, cfg->OversampleV, cfg->PixelSnapH);
29182918
if (ImGui::TreeNode("Glyphs", "Glyphs (%d)", font->Glyphs.Size))
29192919
{

0 commit comments

Comments
 (0)