Skip to content

Commit fe598f7

Browse files
committed
WIP - (Breaking) remove ImFontAtlasCustomRect which is now the same as ImTextureRect
1 parent 1a20e47 commit fe598f7

File tree

2 files changed

+43
-40
lines changed

2 files changed

+43
-40
lines changed

imgui.h

+32-30
Original file line numberDiff line numberDiff line change
@@ -3559,22 +3559,6 @@ struct ImFontGlyphRangesBuilder
35593559
IMGUI_API void BuildRanges(ImVector<ImWchar>* out_ranges); // Output new ranges
35603560
};
35613561

3562-
// See ImFontAtlas::AddCustomRectXXX functions.
3563-
struct ImFontAtlasCustomRect
3564-
{
3565-
unsigned short X, Y; // Output // Packed position in Atlas
3566-
3567-
// [Internal]
3568-
unsigned short Width, Height; // Input // Desired rectangle dimension
3569-
unsigned int GlyphID : 31; // Input // For custom font glyphs only (ID < 0x110000)
3570-
unsigned int GlyphColored : 1; // Input // For custom font glyphs only: glyph is colored, removed tinting.
3571-
float GlyphAdvanceX; // Input // For custom font glyphs only: glyph xadvance
3572-
ImVec2 GlyphOffset; // Input // For custom font glyphs only: glyph display offset
3573-
ImFont* Font; // Input // For custom font glyphs only: target font
3574-
ImFontAtlasCustomRect() { X = Y = 0xFFFF; Width = Height = 0; GlyphID = 0; GlyphColored = 0; GlyphAdvanceX = 0.0f; GlyphOffset = ImVec2(0, 0); Font = NULL; }
3575-
bool IsPacked() const { return X != 0xFFFF; }
3576-
};
3577-
35783562
// Flags for ImFontAtlas build
35793563
enum ImFontAtlasFlags_
35803564
{
@@ -3659,24 +3643,21 @@ struct ImFontAtlas
36593643
// [ALPHA] Custom Rectangles/Glyphs API
36603644
//-------------------------------------------
36613645

3662-
// You can request arbitrary rectangles to be packed into the atlas, for your own purposes.
3646+
// You can request arbitrary rectangles to be packed into the atlas, for your own purpose.
36633647
// You can request your rectangles to be mapped as font glyph (given a font + Unicode point),
36643648
// so you can render e.g. custom colorful icons and use them as regular glyphs.
3665-
// - If your backend supports ImGuiBackendFlags_RendererHasTextures (since 1.92.X):
3666-
// - Packing is done immediately. Returns >= on success. Return <0 on error.
3667-
// - You can render your pixels into the texture right after calling the AddCustomRectXXX functions.
3668-
// - Texture may be resized, so you cannot cache UV coordinates. // FIXME-NEWATLAS-V1: How to handle that smoothly?
3669-
// - If your backend does NOT supports ImGuiBackendFlags_RendererHasTextures (older than 1.92.X):
3670-
// - After calling Build(), you can query the rectangle position and render your pixels.
3671-
// - If you render colored output, set 'atlas->TexPixelsUseColors = true' as this may help some backends decide of preferred texture format.
3649+
// - Since 1.92.X, packing is done immediately in the function call. Returns >= on success, <0 on error.
3650+
// - You can render your pixels into the texture right after calling the AddCustomRectXXX functions, without waiting for the Build() call.
3651+
// - If your backend supports ImGuiBackendFlags_RendererHasTextures:
3652+
// Texture may be resized, so you cannot cache UV coordinates: always use CalcCustomRectUV().
3653+
// - If you render colored output into your AddCustomRectRegular() rectangle: set 'atlas->TexPixelsUseColors = true'
3654+
// as this may help some backends decide of preferred texture format.
36723655
// - Read docs/FONTS.md for more details about using colorful icons.
36733656
// - Note: this API may be redesigned later in order to support multi-monitor varying DPI settings.
36743657
IMGUI_API int AddCustomRectRegular(int width, int height);
36753658
IMGUI_API int AddCustomRectFontGlyph(ImFont* font, ImWchar codepoint, int width, int height, float advance_x, const ImVec2& offset = ImVec2(0, 0));
3676-
IMGUI_API ImFontAtlasCustomRect* GetCustomRectByIndex(int index);
3677-
3678-
// [Internal]
3679-
IMGUI_API void CalcCustomRectUV(const ImFontAtlasCustomRect* rect, ImVec2* out_uv_min, ImVec2* out_uv_max) const;
3659+
IMGUI_API ImTextureRect* GetCustomRectByIndex(int index);
3660+
IMGUI_API void CalcCustomRectUV(const ImTextureRect* rect, ImVec2* out_uv_min, ImVec2* out_uv_max) const;
36803661

36813662
//-------------------------------------------
36823663
// Members
@@ -3704,7 +3685,6 @@ struct ImFontAtlas
37043685
ImVec2 TexUvWhitePixel; // Texture coordinates to a white pixel
37053686
ImVector<ImFont*> Fonts; // Hold all the fonts returned by AddFont*. Fonts[0] is the default font upon calling ImGui::NewFrame(), use ImGui::PushFont()/PopFont() to change the current font.
37063687
ImVector<ImFontConfig> Sources; // Source/configuration data
3707-
//ImVector<ImFontAtlasCustomRect> CustomRects; // Rectangles for packing custom texture data into the atlas.
37083688
ImVec4 TexUvLines[IM_DRAWLIST_TEX_LINES_WIDTH_MAX + 1]; // UVs for baked anti-aliased lines
37093689
int TexNextUniqueID; // Next value to be stored in TexData->UniqueID
37103690
ImVector<ImDrawListSharedData*> DrawListSharedDatas;
@@ -3718,7 +3698,8 @@ struct ImFontAtlas
37183698
int RefCount; // Number of contexts using this atlas
37193699

37203700
// [Obsolete]
3721-
//int TexDesiredWidth; // OBSOLETED in 1.91.5 (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)
3701+
//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)
3702+
//typedef ImTextureRect ImFontAtlasCustomRect; // OBSOLETED in 1.92.X
37223703
//typedef ImFontAtlasCustomRect CustomRect; // OBSOLETED in 1.72+
37233704
//typedef ImFontGlyphRangesBuilder GlyphRangesBuilder; // OBSOLETED in 1.67+
37243705
};
@@ -4124,6 +4105,27 @@ namespace ImGui
41244105
//static inline void SetScrollPosHere() { SetScrollHere(); } // OBSOLETED in 1.42
41254106
}
41264107

4108+
//-- OBSOLETED in 1.91.7 (from January 2025): ImFontAtlasCustomRect becomes ImTextureRect
4109+
// - ImFontAtlasCustomRect::X --> ImTextureRect::x
4110+
// - ImFontAtlasCustomRect::Y --> ImTextureRect::y
4111+
// - ImFontAtlasCustomRect::Width --> ImTextureRect::w
4112+
// - ImFontAtlasCustomRect::Height --> ImTextureRect::h
4113+
// - ImFontAtlasCustomRect::GlyphColored --> if you need to write to this, instead you can write to 'font->Glyphs.back()->Colored' after calling AddCustomRectFontGlyph()
4114+
// We could make ImTextureRect an union to use old names, such 1) this would be confusing 2) the fix is easy 3) ImFontAtlasCustomRect was always a rather esoteric api.
4115+
typedef ImTextureRect ImFontAtlasCustomRect;
4116+
/*struct ImFontAtlasCustomRect
4117+
{
4118+
unsigned short X, Y; // Output // Packed position in Atlas
4119+
unsigned short Width, Height; // Input // [Internal] Desired rectangle dimension
4120+
unsigned int GlyphID:31; // Input // [Internal] For custom font glyphs only (ID < 0x110000)
4121+
unsigned int GlyphColored:1; // Input // [Internal] For custom font glyphs only: glyph is colored, removed tinting.
4122+
float GlyphAdvanceX; // Input // [Internal] For custom font glyphs only: glyph xadvance
4123+
ImVec2 GlyphOffset; // Input // [Internal] For custom font glyphs only: glyph display offset
4124+
ImFont* Font; // Input // [Internal] For custom font glyphs only: target font
4125+
ImFontAtlasCustomRect() { X = Y = 0xFFFF; Width = Height = 0; GlyphID = 0; GlyphColored = 0; GlyphAdvanceX = 0.0f; GlyphOffset = ImVec2(0, 0); Font = NULL; }
4126+
bool IsPacked() const { return X != 0xFFFF; }
4127+
};*/
4128+
41274129
//-- OBSOLETED in 1.82 (from Mars 2021): flags for AddRect(), AddRectFilled(), AddImageRounded(), PathRect()
41284130
//typedef ImDrawFlags ImDrawCornerFlags;
41294131
//enum ImDrawCornerFlags_

imgui_draw.cpp

+11-10
Original file line numberDiff line numberDiff line change
@@ -3138,6 +3138,8 @@ int ImFontAtlas::AddCustomRectRegular(int width, int height)
31383138
return r_id;
31393139
}
31403140

3141+
// FIXME: we automatically set glyph.Colored=true by default.
3142+
// If you need to alter this, you can write 'font->Glyphs.back()->Colored' after calling AddCustomRectFontGlyph().
31413143
int ImFontAtlas::AddCustomRectFontGlyph(ImFont* font, ImWchar codepoint, int width, int height, float advance_x, const ImVec2& offset)
31423144
{
31433145
#ifdef IMGUI_USE_WCHAR32
@@ -3171,21 +3173,20 @@ int ImFontAtlas::AddCustomRectFontGlyph(ImFont* font, ImWchar codepoint, int wid
31713173
return r_id;
31723174
}
31733175

3174-
ImFontAtlasCustomRect* ImFontAtlas::GetCustomRectByIndex(int idx)
3176+
ImTextureRect* ImFontAtlas::GetCustomRectByIndex(int idx)
31753177
{
3176-
IM_STATIC_ASSERT(offsetof(ImFontAtlasCustomRect, X) == offsetof(ImFontAtlasRect, x));
3177-
IM_STATIC_ASSERT(offsetof(ImFontAtlasCustomRect, Y) == offsetof(ImFontAtlasRect, y));
3178-
IM_STATIC_ASSERT(offsetof(ImFontAtlasCustomRect, Width) == offsetof(ImFontAtlasRect, w));
3179-
IM_STATIC_ASSERT(offsetof(ImFontAtlasCustomRect, Height) == offsetof(ImFontAtlasRect, h));
3180-
return (ImFontAtlasCustomRect*)(void*)ImFontAtlasPackGetRect(this, idx);
3178+
IM_STATIC_ASSERT(offsetof(ImTextureRect, x) == offsetof(ImFontAtlasRect, x));
3179+
IM_STATIC_ASSERT(offsetof(ImTextureRect, y) == offsetof(ImFontAtlasRect, y));
3180+
IM_STATIC_ASSERT(offsetof(ImTextureRect, w) == offsetof(ImFontAtlasRect, w));
3181+
IM_STATIC_ASSERT(offsetof(ImTextureRect, h) == offsetof(ImFontAtlasRect, h));
3182+
return (ImTextureRect*)(void*)ImFontAtlasPackGetRect(this, idx);
31813183
}
31823184

3183-
void ImFontAtlas::CalcCustomRectUV(const ImFontAtlasCustomRect* rect, ImVec2* out_uv_min, ImVec2* out_uv_max) const
3185+
void ImFontAtlas::CalcCustomRectUV(const ImTextureRect* rect, ImVec2* out_uv_min, ImVec2* out_uv_max) const
31843186
{
31853187
IM_ASSERT(TexData->Width > 0 && TexData->Height > 0); // Font atlas needs to be built before we can calculate UV coordinates
3186-
IM_ASSERT(rect->IsPacked()); // Make sure the rectangle has been packed
3187-
*out_uv_min = ImVec2((float)rect->X * TexUvScale.x, (float)rect->Y * TexUvScale.y);
3188-
*out_uv_max = ImVec2((float)(rect->X + rect->Width) * TexUvScale.x, (float)(rect->Y + rect->Height) * TexUvScale.y);
3188+
*out_uv_min = ImVec2((float)rect->x * TexUvScale.x, (float)rect->y * TexUvScale.y);
3189+
*out_uv_max = ImVec2((float)(rect->x + rect->w) * TexUvScale.x, (float)(rect->y + rect->w) * TexUvScale.y);
31893190
}
31903191

31913192
bool ImFontAtlasGetMouseCursorTexData(ImFontAtlas* atlas, ImGuiMouseCursor cursor_type, ImVec2* out_offset, ImVec2* out_size, ImVec2 out_uv_border[2], ImVec2 out_uv_fill[2])

0 commit comments

Comments
 (0)