Skip to content

Commit 20360e0

Browse files
committed
Merge miscellaneous small changes to reduce drift with texture update branch.
- ImGuiDebugLogFlags_EventFont is yet unused.
1 parent 551b6c4 commit 20360e0

File tree

6 files changed

+95
-71
lines changed

6 files changed

+95
-71
lines changed

Diff for: backends/imgui_impl_opengl3.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@
164164
// In the rest of your app/engine, you can use another loader of your choice (gl3w, glew, glad, glbinding, glext, glLoadGen, etc.).
165165
// If you happen to be developing a new feature for this backend (imgui_impl_opengl3.cpp):
166166
// - You may need to regenerate imgui_impl_opengl3_loader.h to add new symbols. See https://github.com/dearimgui/gl3w_stripped
167+
// Typically you would run: python3 ./gl3w_gen.py --output ../imgui/backends/imgui_impl_opengl3_loader.h --ref ../imgui/backends/imgui_impl_opengl3.cpp ./extra_symbols.txt
167168
// - You can temporarily use an unstripped version. See https://github.com/dearimgui/gl3w_stripped/releases
168169
// Changes to this backend using new APIs should be accompanied by a regenerated stripped loader version.
169170
#define IMGL3W_IMPL
@@ -689,7 +690,7 @@ bool ImGui_ImplOpenGL3_CreateFontsTexture()
689690
#endif
690691
GL_CALL(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels));
691692

692-
// Store our identifier
693+
// Store identifier
693694
io.Fonts->SetTexID((ImTextureID)(intptr_t)bd->FontTexture);
694695

695696
// Restore state

Diff for: imgui.cpp

+15-13
Original file line numberDiff line numberDiff line change
@@ -4010,7 +4010,7 @@ ImGuiContext::ImGuiContext(ImFontAtlas* shared_font_atlas)
40104010
StackSizesInBeginForCurrentWindow = NULL;
40114011

40124012
DebugDrawIdConflictsCount = 0;
4013-
DebugLogFlags = ImGuiDebugLogFlags_EventError | ImGuiDebugLogFlags_OutputToTTY;
4013+
DebugLogFlags = ImGuiDebugLogFlags_EventError | ImGuiDebugLogFlags_OutputToTTY | ImGuiDebugLogFlags_EventFont;
40144014
DebugLocateId = 0;
40154015
DebugLogSkippedErrors = 0;
40164016
DebugLogAutoDisableFlags = ImGuiDebugLogFlags_None;
@@ -4226,8 +4226,8 @@ ImGuiWindow::ImGuiWindow(ImGuiContext* ctx, const char* name) : DrawListInst(NUL
42264226
FontWindowScale = 1.0f;
42274227
SettingsOffset = -1;
42284228
DrawList = &DrawListInst;
4229-
DrawList->_Data = &Ctx->DrawListSharedData;
42304229
DrawList->_OwnerName = Name;
4230+
DrawList->_Data = &Ctx->DrawListSharedData;
42314231
NavPreferredScoringPosRel[0] = NavPreferredScoringPosRel[1] = ImVec2(FLT_MAX, FLT_MAX);
42324232
}
42334233

@@ -5025,7 +5025,7 @@ void ImGui::UpdateHoveredWindowAndCaptureFlags()
50255025
io.WantTextInput = (g.WantTextInputNextFrame != -1) ? (g.WantTextInputNextFrame != 0) : false;
50265026
}
50275027

5028-
// Calling SetupDrawListSharedData() is followed by SetCurrentFont() which sets up the remaining data.
5028+
// Called once a frame. Followed by SetCurrentFont() which sets up the remaining data.
50295029
static void SetupDrawListSharedData()
50305030
{
50315031
ImGuiContext& g = *GImGui;
@@ -15180,6 +15180,17 @@ void ImGui::UpdateDebugToolFlashStyleColor()
1518015180
DebugFlashStyleColorStop();
1518115181
}
1518215182

15183+
static const char* FormatTextureIDForDebugDisplay(char* buf, int buf_size, ImTextureID tex_id)
15184+
{
15185+
union { void* ptr; int integer; } tex_id_opaque;
15186+
memcpy(&tex_id_opaque, &tex_id, ImMin(sizeof(void*), sizeof(tex_id)));
15187+
if (sizeof(tex_id) >= sizeof(void*))
15188+
ImFormatString(buf, buf_size, "0x%p", tex_id_opaque.ptr);
15189+
else
15190+
ImFormatString(buf, buf_size, "0x%04X", tex_id_opaque.integer);
15191+
return buf;
15192+
}
15193+
1518315194
// Avoid naming collision with imgui_demo.cpp's HelpMarker() for unity builds.
1518415195
static void MetricsHelpMarker(const char* desc)
1518515196
{
@@ -15868,16 +15879,6 @@ void ImGui::DebugNodeColumns(ImGuiOldColumns* columns)
1586815879
TreePop();
1586915880
}
1587015881

15871-
static void FormatTextureIDForDebugDisplay(char* buf, int buf_size, ImTextureID tex_id)
15872-
{
15873-
union { void* ptr; int integer; } tex_id_opaque;
15874-
memcpy(&tex_id_opaque, &tex_id, ImMin(sizeof(void*), sizeof(tex_id)));
15875-
if (sizeof(tex_id) >= sizeof(void*))
15876-
ImFormatString(buf, buf_size, "0x%p", tex_id_opaque.ptr);
15877-
else
15878-
ImFormatString(buf, buf_size, "0x%04X", tex_id_opaque.integer);
15879-
}
15880-
1588115882
// [DEBUG] Display contents of ImDrawList
1588215883
void ImGui::DebugNodeDrawList(ImGuiWindow* window, ImGuiViewportP* viewport, const ImDrawList* draw_list, const char* label)
1588315884
{
@@ -16379,6 +16380,7 @@ void ImGui::ShowDebugLogWindow(bool* p_open)
1637916380
ShowDebugLogFlag("Clipper", ImGuiDebugLogFlags_EventClipper);
1638016381
ShowDebugLogFlag("Focus", ImGuiDebugLogFlags_EventFocus);
1638116382
ShowDebugLogFlag("IO", ImGuiDebugLogFlags_EventIO);
16383+
//ShowDebugLogFlag("Font", ImGuiDebugLogFlags_EventFont);
1638216384
ShowDebugLogFlag("Nav", ImGuiDebugLogFlags_EventNav);
1638316385
ShowDebugLogFlag("Popup", ImGuiDebugLogFlags_EventPopup);
1638416386
ShowDebugLogFlag("Selection", ImGuiDebugLogFlags_EventSelection);

Diff for: imgui.h

+12-7
Original file line numberDiff line numberDiff line change
@@ -2309,6 +2309,7 @@ struct ImGuiIO
23092309
// (the imgui_impl_xxxx backend files are setting those up for you)
23102310
//------------------------------------------------------------------
23112311

2312+
// Nowadays those would be stored in ImGuiPlatformIO but we are leaving them here for legacy reasons.
23122313
// Optional: Platform/Renderer backend name (informational only! will be displayed in About Window) + User data for backend/wrappers to store their own stuff.
23132314
const char* BackendPlatformName; // = NULL
23142315
const char* BackendRendererName; // = NULL
@@ -3064,10 +3065,11 @@ struct ImDrawList
30643065
float _FringeScale; // [Internal] anti-alias fringe is scaled by this value, this helps to keep things sharp while zooming at vertex buffer content
30653066
const char* _OwnerName; // Pointer to owner window's name for debugging
30663067

3067-
// If you want to create ImDrawList instances, pass them ImGui::GetDrawListSharedData() or create and use your own ImDrawListSharedData (so you can use ImDrawList without ImGui)
3068-
ImDrawList(ImDrawListSharedData* shared_data) { memset(this, 0, sizeof(*this)); _Data = shared_data; }
3069-
3070-
~ImDrawList() { _ClearFreeMemory(); }
3068+
// If you want to create ImDrawList instances, pass them ImGui::GetDrawListSharedData().
3069+
// (advanced: you may create and use your own ImDrawListSharedData so you can use ImDrawList without ImGui, but that's more involved)
3070+
IMGUI_API ImDrawList(ImDrawListSharedData* shared_data);
3071+
IMGUI_API ~ImDrawList();
3072+
30713073
IMGUI_API void PushClipRect(const ImVec2& clip_rect_min, const ImVec2& clip_rect_max, bool intersect_with_current_clip_rect = false); // Render-level scissoring. This is passed down to your render function but not used for CPU-side coarse clipping. Prefer using higher-level ImGui::PushClipRect() to affect logic (hit-testing and widget culling)
30723074
IMGUI_API void PushClipRectFullScreen();
30733075
IMGUI_API void PopClipRect();
@@ -3277,14 +3279,16 @@ struct ImFontGlyphRangesBuilder
32773279
// See ImFontAtlas::AddCustomRectXXX functions.
32783280
struct ImFontAtlasCustomRect
32793281
{
3280-
unsigned short Width, Height; // Input // Desired rectangle dimension
32813282
unsigned short X, Y; // Output // Packed position in Atlas
3283+
3284+
// [Internal]
3285+
unsigned short Width, Height; // Input // Desired rectangle dimension
32823286
unsigned int GlyphID : 31; // Input // For custom font glyphs only (ID < 0x110000)
32833287
unsigned int GlyphColored : 1; // Input // For custom font glyphs only: glyph is colored, removed tinting.
32843288
float GlyphAdvanceX; // Input // For custom font glyphs only: glyph xadvance
32853289
ImVec2 GlyphOffset; // Input // For custom font glyphs only: glyph display offset
32863290
ImFont* Font; // Input // For custom font glyphs only: target font
3287-
ImFontAtlasCustomRect() { Width = Height = 0; X = Y = 0xFFFF; GlyphID = 0; GlyphColored = 0; GlyphAdvanceX = 0.0f; GlyphOffset = ImVec2(0, 0); Font = NULL; }
3291+
ImFontAtlasCustomRect() { X = Y = 0xFFFF; Width = Height = 0; GlyphID = 0; GlyphColored = 0; GlyphAdvanceX = 0.0f; GlyphOffset = ImVec2(0, 0); Font = NULL; }
32883292
bool IsPacked() const { return X != 0xFFFF; }
32893293
};
32903294

@@ -3431,8 +3435,9 @@ struct ImFont
34313435
const ImFontGlyph* FallbackGlyph; // 4-8 // out // = FindGlyph(FontFallbackChar)
34323436

34333437
// Members: Cold ~32/40 bytes
3438+
// Conceptually ConfigData[] is the list of font sources merged to create this font.
34343439
ImFontAtlas* ContainerAtlas; // 4-8 // out // // What we has been loaded into
3435-
const ImFontConfig* ConfigData; // 4-8 // in // // Pointer within ContainerAtlas->ConfigData
3440+
const ImFontConfig* ConfigData; // 4-8 // in // // Pointer within ContainerAtlas->ConfigData to ConfigDataCount instances
34363441
short ConfigDataCount; // 2 // in // ~ 1 // Number of ImFontConfig involved in creating this font. Bigger than 1 when merging multiple font sources into one ImFont.
34373442
ImWchar FallbackChar; // 2 // out // = FFFD/'?' // Character used if a glyph isn't found.
34383443
ImWchar EllipsisChar; // 2 // out // = '...'/'.'// Character used for ellipsis rendering.

Diff for: imgui_draw.cpp

+52-38
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Index of this file:
1414
// [SECTION] Helpers ShadeVertsXXX functions
1515
// [SECTION] ImFontConfig
1616
// [SECTION] ImFontAtlas
17-
// [SECTION] ImFontAtlas glyph ranges helpers
17+
// [SECTION] ImFontAtlas: glyph ranges helpers
1818
// [SECTION] ImFontGlyphRangesBuilder
1919
// [SECTION] ImFont
2020
// [SECTION] ImGui Internal Render Helpers
@@ -394,6 +394,17 @@ void ImDrawListSharedData::SetCircleTessellationMaxError(float max_error)
394394
ArcFastRadiusCutoff = IM_DRAWLIST_CIRCLE_AUTO_SEGMENT_CALC_R(IM_DRAWLIST_ARCFAST_SAMPLE_MAX, CircleSegmentMaxError);
395395
}
396396

397+
ImDrawList::ImDrawList(ImDrawListSharedData* shared_data)
398+
{
399+
memset(this, 0, sizeof(*this));
400+
_Data = shared_data;
401+
}
402+
403+
ImDrawList::~ImDrawList()
404+
{
405+
_ClearFreeMemory();
406+
}
407+
397408
// Initialize before use in a new frame. We always have a command ready in the buffer.
398409
// In the majority of cases, you would want to call PushClipRect() and PushTextureID() after this.
399410
void ImDrawList::_ResetForNewFrame()
@@ -2528,6 +2539,7 @@ ImFont* ImFontAtlas::AddFont(const ImFontConfig* font_cfg)
25282539
IM_ASSERT(font_cfg->FontData != NULL && font_cfg->FontDataSize > 0);
25292540
IM_ASSERT(font_cfg->SizePixels > 0.0f && "Is ImFontConfig struct correctly initialized?");
25302541
IM_ASSERT(font_cfg->OversampleH > 0 && font_cfg->OversampleV > 0 && "Is ImFontConfig struct correctly initialized?");
2542+
IM_ASSERT(font_cfg->RasterizerDensity > 0.0f);
25312543

25322544
// Create new font
25332545
if (!font_cfg->MergeMode)
@@ -2546,9 +2558,16 @@ ImFont* ImFontAtlas::AddFont(const ImFontConfig* font_cfg)
25462558
memcpy(new_font_cfg.FontData, font_cfg->FontData, (size_t)new_font_cfg.FontDataSize);
25472559
}
25482560

2561+
// Round font size
2562+
// - We started rounding in 1.90 WIP (18991) as our layout system currently doesn't support non-rounded font size well yet.
2563+
// - Note that using io.FontGlobalScale or SetWindowFontScale(), with are legacy-ish, partially supported features, can still lead to unrounded sizes.
2564+
// - We may support it better later and remove this rounding.
2565+
new_font_cfg.SizePixels = ImTrunc(new_font_cfg.SizePixels);
2566+
25492567
if (new_font_cfg.DstFont->EllipsisChar == (ImWchar)-1)
25502568
new_font_cfg.DstFont->EllipsisChar = font_cfg->EllipsisChar;
25512569

2570+
// Pointers to ConfigData and BuilderData are otherwise dangling
25522571
ImFontAtlasUpdateConfigDataPointers(this);
25532572

25542573
// Invalidate texture
@@ -3163,35 +3182,35 @@ static void ImFontAtlasBuildRenderDefaultTexData(ImFontAtlas* atlas)
31633182
IM_ASSERT(r->IsPacked());
31643183

31653184
const int w = atlas->TexWidth;
3166-
if (!(atlas->Flags & ImFontAtlasFlags_NoMouseCursors))
3185+
if (atlas->Flags & ImFontAtlasFlags_NoMouseCursors)
31673186
{
3168-
// Render/copy pixels
3169-
IM_ASSERT(r->Width == FONT_ATLAS_DEFAULT_TEX_DATA_W * 2 + 1 && r->Height == FONT_ATLAS_DEFAULT_TEX_DATA_H);
3170-
const int x_for_white = r->X;
3171-
const int x_for_black = r->X + FONT_ATLAS_DEFAULT_TEX_DATA_W + 1;
3187+
// White pixels only
3188+
IM_ASSERT(r->Width == 2 && r->Height == 2);
3189+
const int offset = (int)r->X + (int)r->Y * w;
31723190
if (atlas->TexPixelsAlpha8 != NULL)
31733191
{
3174-
ImFontAtlasBuildRender8bppRectFromString(atlas, x_for_white, r->Y, FONT_ATLAS_DEFAULT_TEX_DATA_W, FONT_ATLAS_DEFAULT_TEX_DATA_H, FONT_ATLAS_DEFAULT_TEX_DATA_PIXELS, '.', 0xFF);
3175-
ImFontAtlasBuildRender8bppRectFromString(atlas, x_for_black, r->Y, FONT_ATLAS_DEFAULT_TEX_DATA_W, FONT_ATLAS_DEFAULT_TEX_DATA_H, FONT_ATLAS_DEFAULT_TEX_DATA_PIXELS, 'X', 0xFF);
3192+
atlas->TexPixelsAlpha8[offset] = atlas->TexPixelsAlpha8[offset + 1] = atlas->TexPixelsAlpha8[offset + w] = atlas->TexPixelsAlpha8[offset + w + 1] = 0xFF;
31763193
}
31773194
else
31783195
{
3179-
ImFontAtlasBuildRender32bppRectFromString(atlas, x_for_white, r->Y, FONT_ATLAS_DEFAULT_TEX_DATA_W, FONT_ATLAS_DEFAULT_TEX_DATA_H, FONT_ATLAS_DEFAULT_TEX_DATA_PIXELS, '.', IM_COL32_WHITE);
3180-
ImFontAtlasBuildRender32bppRectFromString(atlas, x_for_black, r->Y, FONT_ATLAS_DEFAULT_TEX_DATA_W, FONT_ATLAS_DEFAULT_TEX_DATA_H, FONT_ATLAS_DEFAULT_TEX_DATA_PIXELS, 'X', IM_COL32_WHITE);
3196+
atlas->TexPixelsRGBA32[offset] = atlas->TexPixelsRGBA32[offset + 1] = atlas->TexPixelsRGBA32[offset + w] = atlas->TexPixelsRGBA32[offset + w + 1] = IM_COL32_WHITE;
31813197
}
31823198
}
31833199
else
31843200
{
3185-
// Render 4 white pixels
3186-
IM_ASSERT(r->Width == 2 && r->Height == 2);
3187-
const int offset = (int)r->X + (int)r->Y * w;
3201+
// White pixels and mouse cursor
3202+
IM_ASSERT(r->Width == FONT_ATLAS_DEFAULT_TEX_DATA_W * 2 + 1 && r->Height == FONT_ATLAS_DEFAULT_TEX_DATA_H);
3203+
const int x_for_white = r->X;
3204+
const int x_for_black = r->X + FONT_ATLAS_DEFAULT_TEX_DATA_W + 1;
31883205
if (atlas->TexPixelsAlpha8 != NULL)
31893206
{
3190-
atlas->TexPixelsAlpha8[offset] = atlas->TexPixelsAlpha8[offset + 1] = atlas->TexPixelsAlpha8[offset + w] = atlas->TexPixelsAlpha8[offset + w + 1] = 0xFF;
3207+
ImFontAtlasBuildRender8bppRectFromString(atlas, x_for_white, r->Y, FONT_ATLAS_DEFAULT_TEX_DATA_W, FONT_ATLAS_DEFAULT_TEX_DATA_H, FONT_ATLAS_DEFAULT_TEX_DATA_PIXELS, '.', 0xFF);
3208+
ImFontAtlasBuildRender8bppRectFromString(atlas, x_for_black, r->Y, FONT_ATLAS_DEFAULT_TEX_DATA_W, FONT_ATLAS_DEFAULT_TEX_DATA_H, FONT_ATLAS_DEFAULT_TEX_DATA_PIXELS, 'X', 0xFF);
31913209
}
31923210
else
31933211
{
3194-
atlas->TexPixelsRGBA32[offset] = atlas->TexPixelsRGBA32[offset + 1] = atlas->TexPixelsRGBA32[offset + w] = atlas->TexPixelsRGBA32[offset + w + 1] = IM_COL32_WHITE;
3212+
ImFontAtlasBuildRender32bppRectFromString(atlas, x_for_white, r->Y, FONT_ATLAS_DEFAULT_TEX_DATA_W, FONT_ATLAS_DEFAULT_TEX_DATA_H, FONT_ATLAS_DEFAULT_TEX_DATA_PIXELS, '.', IM_COL32_WHITE);
3213+
ImFontAtlasBuildRender32bppRectFromString(atlas, x_for_black, r->Y, FONT_ATLAS_DEFAULT_TEX_DATA_W, FONT_ATLAS_DEFAULT_TEX_DATA_H, FONT_ATLAS_DEFAULT_TEX_DATA_PIXELS, 'X', IM_COL32_WHITE);
31953214
}
31963215
}
31973216
atlas->TexUvWhitePixel = ImVec2((r->X + 0.5f) * atlas->TexUvScale.x, (r->Y + 0.5f) * atlas->TexUvScale.y);
@@ -3205,38 +3224,38 @@ static void ImFontAtlasBuildRenderLinesTexData(ImFontAtlas* atlas)
32053224
// This generates a triangular shape in the texture, with the various line widths stacked on top of each other to allow interpolation between them
32063225
ImFontAtlasCustomRect* r = atlas->GetCustomRectByIndex(atlas->PackIdLines);
32073226
IM_ASSERT(r->IsPacked());
3208-
for (unsigned int n = 0; n < IM_DRAWLIST_TEX_LINES_WIDTH_MAX + 1; n++) // +1 because of the zero-width row
3227+
for (int n = 0; n < IM_DRAWLIST_TEX_LINES_WIDTH_MAX + 1; n++) // +1 because of the zero-width row
32093228
{
32103229
// Each line consists of at least two empty pixels at the ends, with a line of solid pixels in the middle
3211-
unsigned int y = n;
3212-
unsigned int line_width = n;
3213-
unsigned int pad_left = (r->Width - line_width) / 2;
3214-
unsigned int pad_right = r->Width - (pad_left + line_width);
3230+
int y = n;
3231+
int line_width = n;
3232+
int pad_left = (r->Width - line_width) / 2;
3233+
int pad_right = r->Width - (pad_left + line_width);
32153234

32163235
// Write each slice
32173236
IM_ASSERT(pad_left + line_width + pad_right == r->Width && y < r->Height); // Make sure we're inside the texture bounds before we start writing pixels
32183237
if (atlas->TexPixelsAlpha8 != NULL)
32193238
{
32203239
unsigned char* write_ptr = &atlas->TexPixelsAlpha8[r->X + ((r->Y + y) * atlas->TexWidth)];
3221-
for (unsigned int i = 0; i < pad_left; i++)
3240+
for (int i = 0; i < pad_left; i++)
32223241
*(write_ptr + i) = 0x00;
32233242

3224-
for (unsigned int i = 0; i < line_width; i++)
3243+
for (int i = 0; i < line_width; i++)
32253244
*(write_ptr + pad_left + i) = 0xFF;
32263245

3227-
for (unsigned int i = 0; i < pad_right; i++)
3246+
for (int i = 0; i < pad_right; i++)
32283247
*(write_ptr + pad_left + line_width + i) = 0x00;
32293248
}
32303249
else
32313250
{
32323251
unsigned int* write_ptr = &atlas->TexPixelsRGBA32[r->X + ((r->Y + y) * atlas->TexWidth)];
3233-
for (unsigned int i = 0; i < pad_left; i++)
3252+
for (int i = 0; i < pad_left; i++)
32343253
*(write_ptr + i) = IM_COL32(255, 255, 255, 0);
32353254

3236-
for (unsigned int i = 0; i < line_width; i++)
3255+
for (int i = 0; i < line_width; i++)
32373256
*(write_ptr + pad_left + i) = IM_COL32_WHITE;
32383257

3239-
for (unsigned int i = 0; i < pad_right; i++)
3258+
for (int i = 0; i < pad_right; i++)
32403259
*(write_ptr + pad_left + line_width + i) = IM_COL32(255, 255, 255, 0);
32413260
}
32423261

@@ -3251,13 +3270,6 @@ static void ImFontAtlasBuildRenderLinesTexData(ImFontAtlas* atlas)
32513270
// Note: this is called / shared by both the stb_truetype and the FreeType builder
32523271
void ImFontAtlasBuildInit(ImFontAtlas* atlas)
32533272
{
3254-
// Round font size
3255-
// - We started rounding in 1.90 WIP (18991) as our layout system currently doesn't support non-rounded font size well yet.
3256-
// - Note that using io.FontGlobalScale or SetWindowFontScale(), with are legacy-ish, partially supported features, can still lead to unrounded sizes.
3257-
// - We may support it better later and remove this rounding.
3258-
for (ImFontConfig& cfg : atlas->ConfigData)
3259-
cfg.SizePixels = ImTrunc(cfg.SizePixels);
3260-
32613273
// Register texture region for mouse cursors or standard white pixels
32623274
if (atlas->PackIdMouseCursors < 0)
32633275
{
@@ -3308,6 +3320,10 @@ void ImFontAtlasBuildFinish(ImFontAtlas* atlas)
33083320
atlas->TexReady = true;
33093321
}
33103322

3323+
//-------------------------------------------------------------------------
3324+
// [SECTION] ImFontAtlas: glyph ranges helpers
3325+
//-------------------------------------------------------------------------
3326+
33113327
// Retrieve list of range (2 int per range, values are inclusive)
33123328
const ImWchar* ImFontAtlas::GetGlyphRangesDefault()
33133329
{
@@ -3369,10 +3385,6 @@ static void UnpackAccumulativeOffsetsIntoRanges(int base_codepoint, const short*
33693385
out_ranges[0] = 0;
33703386
}
33713387

3372-
//-------------------------------------------------------------------------
3373-
// [SECTION] ImFontAtlas glyph ranges helpers
3374-
//-------------------------------------------------------------------------
3375-
33763388
const ImWchar* ImFontAtlas::GetGlyphRangesChineseSimplifiedCommon()
33773389
{
33783390
// Store 2500 regularly used characters for Simplified Chinese.
@@ -3799,8 +3811,9 @@ void ImFont::AddGlyph(const ImFontConfig* cfg, ImWchar codepoint, float x0, floa
37993811
advance_x += cfg->GlyphExtraSpacing.x;
38003812
}
38013813

3814+
int glyph_idx = Glyphs.Size;
38023815
Glyphs.resize(Glyphs.Size + 1);
3803-
ImFontGlyph& glyph = Glyphs.back();
3816+
ImFontGlyph& glyph = Glyphs[glyph_idx];
38043817
glyph.Codepoint = (unsigned int)codepoint;
38053818
glyph.Visible = (x0 != x1) && (y0 != y1);
38063819
glyph.Colored = false;
@@ -3836,6 +3849,7 @@ void ImFont::AddRemapChar(ImWchar dst, ImWchar src, bool overwrite_dst)
38363849
IndexAdvanceX[dst] = (src < index_size) ? IndexAdvanceX.Data[src] : 1.0f;
38373850
}
38383851

3852+
// Find glyph, return fallback if missing
38393853
const ImFontGlyph* ImFont::FindGlyph(ImWchar c)
38403854
{
38413855
if (c >= (size_t)IndexLookup.Size)

0 commit comments

Comments
 (0)