mirror of
https://github.com/ocornut/imgui.git
synced 2025-12-23 22:59:10 +00:00
Fonts: add optional out parameter to AddCustomRect()
This commit is contained in:
2
imgui.h
2
imgui.h
@@ -3633,7 +3633,7 @@ struct ImFontAtlas
|
||||
// - AddCustomRectRegular() --> Renamed to AddCustomRect()
|
||||
// - AddCustomRectFontGlyph() --> Prefer using custom ImFontLoader inside ImFontConfig
|
||||
// - ImFontAtlasCustomRect --> Renamed to ImFontAtlasRect
|
||||
IMGUI_API ImFontAtlasRectId AddCustomRect(int width, int height); // Register a rectangle. Return -1 (ImFontAtlasRectId_Invalid) on error.
|
||||
IMGUI_API ImFontAtlasRectId AddCustomRect(int width, int height, ImFontAtlasRect* out_r = NULL);// Register a rectangle. Return -1 (ImFontAtlasRectId_Invalid) on error.
|
||||
IMGUI_API void RemoveCustomRect(ImFontAtlasRectId id); // Unregister a rectangle. Existing pixels will stay in texture until resized / garbage collected.
|
||||
IMGUI_API bool GetCustomRect(ImFontAtlasRectId id, ImFontAtlasRect* out_r) const; // Get rectangle coordinates for current texture. Valid immediately, never store this (read above)!
|
||||
|
||||
|
||||
@@ -3225,7 +3225,8 @@ void ImFontAtlas::RemoveFont(ImFont* font)
|
||||
ImFontAtlasBuildNotifySetFont(this, font, new_current_font);
|
||||
}
|
||||
|
||||
ImFontAtlasRectId ImFontAtlas::AddCustomRect(int width, int height)
|
||||
// At it is common to do an AddCustomRect() followed by a GetCustomRect(), we provide an optional 'ImFontAtlasRect* out_r = NULL' argument to retrieve the info straight away.
|
||||
ImFontAtlasRectId ImFontAtlas::AddCustomRect(int width, int height, ImFontAtlasRect* out_r)
|
||||
{
|
||||
IM_ASSERT(width > 0 && width <= 0xFFFF);
|
||||
IM_ASSERT(height > 0 && height <= 0xFFFF);
|
||||
@@ -3236,9 +3237,14 @@ ImFontAtlasRectId ImFontAtlas::AddCustomRect(int width, int height)
|
||||
ImFontAtlasRectId r_id = ImFontAtlasPackAddRect(this, width, height);
|
||||
if (r_id == ImFontAtlasRectId_Invalid)
|
||||
return ImFontAtlasRectId_Invalid;
|
||||
ImTextureRect* r = ImFontAtlasPackGetRect(this, r_id);
|
||||
if (out_r != NULL)
|
||||
GetCustomRect(r_id, out_r);
|
||||
|
||||
if (RendererHasTextures)
|
||||
{
|
||||
ImTextureRect* r = ImFontAtlasPackGetRect(this, r_id);
|
||||
ImFontAtlasTextureBlockQueueUpload(this, TexData, r->x, r->y, r->w, r->h);
|
||||
}
|
||||
return r_id;
|
||||
}
|
||||
|
||||
@@ -4321,7 +4327,7 @@ ImFontAtlasRectId ImFontAtlasPackAddRect(ImFontAtlas* atlas, int w, int h, ImFon
|
||||
return ImFontAtlasPackAllocRectEntry(atlas, builder->Rects.Size - 1);
|
||||
}
|
||||
|
||||
// Important: don'return pointer valid until next call to AddRect(), e.g. FindGlyph(), CalcTextSize() can all potentially invalidate previous pointers.
|
||||
// Important: return pointer is valid until next call to AddRect(), e.g. FindGlyph(), CalcTextSize() can all potentially invalidate previous pointers.
|
||||
ImTextureRect* ImFontAtlasPackGetRect(ImFontAtlas* atlas, ImFontAtlasRectId id)
|
||||
{
|
||||
IM_ASSERT(id != ImFontAtlasRectId_Invalid);
|
||||
|
||||
Reference in New Issue
Block a user