Skip to content

Commit 62e1d6a

Browse files
committed
WIP - Fonts: moved ImFontAtlasRectId back to public API.
1 parent 7a09d85 commit 62e1d6a

File tree

3 files changed

+15
-14
lines changed

3 files changed

+15
-14
lines changed

imgui.h

+12-6
Original file line numberDiff line numberDiff line change
@@ -3606,8 +3606,14 @@ struct ImFontGlyphRangesBuilder
36063606
IMGUI_API void BuildRanges(ImVector<ImWchar>* out_ranges); // Output new ranges
36073607
};
36083608

3609+
// An identifier to a rectangle in the atlas. -1 when invalid.
3610+
// The rectangle may move and UV may be invalidated, use GetCustomRect() to retrieve it.
3611+
typedef int ImFontAtlasRectId;
3612+
#define ImFontAtlasRectId_Invalid -1
3613+
36093614
// Output of ImFontAtlas::GetCustomRect() when using custom rectangles.
36103615
// Those values may not be cached/stored as they are only valid for the current value of atlas->TexRef
3616+
// (this is in theory derived from ImTextureRect but we use separate structures for reasons)
36113617
struct ImFontAtlasRect
36123618
{
36133619
unsigned short x, y; // Position (in current texture)
@@ -3724,8 +3730,8 @@ struct ImFontAtlas
37243730
// - AddCustomRectRegular() --> Renamed to AddCustomRect()
37253731
// - AddCustomRectFontGlyph() --> Prefer using custom ImFontLoader inside ImFontConfig
37263732
// - ImFontAtlasCustomRect --> Renamed to ImFontAtlasRect
3727-
IMGUI_API int AddCustomRect(int width, int height); // Register a rectangle. Return -1 on error.
3728-
IMGUI_API bool GetCustomRect(int id, ImFontAtlasRect* out_r) const; // Get rectangle coordinates for current texture. Valid immediately, never store this (read above)!
3733+
IMGUI_API ImFontAtlasRectId AddCustomRect(int width, int height); // Register a rectangle. Return -1 (ImFontAtlasRectId_Invalid) on error.
3734+
IMGUI_API bool GetCustomRect(ImFontAtlasRectId id, ImFontAtlasRect* out_r) const; // Get rectangle coordinates for current texture. Valid immediately, never store this (read above)!
37293735

37303736
//-------------------------------------------
37313737
// Members
@@ -3776,11 +3782,11 @@ struct ImFontAtlas
37763782
#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS
37773783
// Legacy: You can request your rectangles to be mapped as font glyph (given a font + Unicode point), so you can render e.g. custom colorful icons and use them as regular glyphs. --> Prefer using a custom ImFontLoader.
37783784
ImFontAtlasRect TempRect; // For old GetCustomRectByIndex() API
3779-
inline int AddCustomRectRegular(int w, int h) { return AddCustomRect(w, h); } // RENAMED in 1.92.X
3780-
inline const ImFontAtlasRect* GetCustomRectByIndex(int id) { return GetCustomRect(id, &TempRect) ? &TempRect : NULL; } // OBSOLETED in 1.92.X
3785+
inline ImFontAtlasRectId AddCustomRectRegular(int w, int h) { return AddCustomRect(w, h); } // RENAMED in 1.92.X
3786+
inline const ImFontAtlasRect* GetCustomRectByIndex(ImFontAtlasRectId id) { return GetCustomRect(id, &TempRect) ? &TempRect : NULL; } // OBSOLETED in 1.92.X
37813787
inline void CalcCustomRectUV(const ImFontAtlasRect* r, ImVec2* out_uv_min, ImVec2* out_uv_max) const { *out_uv_min = r->uv0; *out_uv_max = r->uv1; } // OBSOLETED in 1.92.X
3782-
IMGUI_API int AddCustomRectFontGlyph(ImFont* font, ImWchar codepoint, int w, int h, float advance_x, const ImVec2& offset = ImVec2(0, 0)); // OBSOLETED in 1.92.X: Use custom ImFontLoader in ImFontConfig
3783-
IMGUI_API int AddCustomRectFontGlyphForSize(ImFont* font, float font_size, ImWchar codepoint, int w, int h, float advance_x, const ImVec2& offset = ImVec2(0, 0)); // ADDED AND OBSOLETED in 1.92.X
3788+
IMGUI_API ImFontAtlasRectId AddCustomRectFontGlyph(ImFont* font, ImWchar codepoint, int w, int h, float advance_x, const ImVec2& offset = ImVec2(0, 0)); // OBSOLETED in 1.92.X: Use custom ImFontLoader in ImFontConfig
3789+
IMGUI_API ImFontAtlasRectId AddCustomRectFontGlyphForSize(ImFont* font, float font_size, ImWchar codepoint, int w, int h, float advance_x, const ImVec2& offset = ImVec2(0, 0)); // ADDED AND OBSOLETED in 1.92.X
37843790
#endif
37853791
//int TexDesiredWidth; // OBSOLETED in 1.92.X (force texture width before calling Build(). Must be a power-of-two. If have many glyphs your graphics API have texture size restrictions you may want to increase texture width to decrease height)
37863792
//typedef ImFontAtlasRect ImFontAtlasCustomRect; // OBSOLETED in 1.92.X

imgui_draw.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -3225,7 +3225,7 @@ void ImFontAtlas::RemoveFont(ImFont* font)
32253225
ImFontAtlasBuildNotifySetFont(this, font, new_current_font);
32263226
}
32273227

3228-
int ImFontAtlas::AddCustomRect(int width, int height)
3228+
ImFontAtlasRectId ImFontAtlas::AddCustomRect(int width, int height)
32293229
{
32303230
IM_ASSERT(width > 0 && width <= 0xFFFF);
32313231
IM_ASSERT(height > 0 && height <= 0xFFFF);
@@ -3292,9 +3292,9 @@ int ImFontAtlas::AddCustomRectFontGlyphForSize(ImFont* font, float font_size, Im
32923292
}
32933293
#endif // #ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS
32943294

3295-
bool ImFontAtlas::GetCustomRect(int id, ImFontAtlasRect* out_r) const
3295+
bool ImFontAtlas::GetCustomRect(ImFontAtlasRectId id, ImFontAtlasRect* out_r) const
32963296
{
3297-
ImTextureRect* r = ImFontAtlasPackGetRect((ImFontAtlas*)this, (ImFontAtlasRectId)id);
3297+
ImTextureRect* r = ImFontAtlasPackGetRect((ImFontAtlas*)this, id);
32983298
if (r == NULL)
32993299
return false;
33003300
IM_ASSERT(TexData->Width > 0 && TexData->Height > 0); // Font atlas needs to be built before we can calculate UV coordinates

imgui_internal.h

-5
Original file line numberDiff line numberDiff line change
@@ -3981,11 +3981,6 @@ IMGUI_API const ImFontLoader* ImFontAtlasGetFontLoaderForStbTruetype();
39813981
// [SECTION] ImFontAtlas internal API
39823982
//-----------------------------------------------------------------------------
39833983

3984-
// An identifier to a rectangle in the atlas. -1 when invalid.
3985-
// The rectangle may move and UV may be invalidated, use GetCustomRect() to retrieve it.
3986-
typedef int ImFontAtlasRectId;
3987-
#define ImFontAtlasRectId_Invalid -1
3988-
39893984
// Packed rectangle lookup entry (we need an indirection to allow removing/reordering rectangles)
39903985
// User are returned ImFontAtlasRectId values which are meant to be persistent.
39913986
// We handle this with an indirection. While Rects[] may be in theory shuffled, compacted etc., RectsIndex[] cannot it is keyed by ImFontAtlasRectId.

0 commit comments

Comments
 (0)