mirror of
https://github.com/ocornut/imgui.git
synced 2026-01-11 00:04:24 +00:00
Fonts: added RemoveCustomRect().
+ internally add ImFontAtlasPackReuseRectEntry()
This commit is contained in:
parent
e9cf3de58f
commit
23dc46c4f8
3 changed files with 22 additions and 12 deletions
|
|
@ -2499,8 +2499,10 @@ void ImTextureData::DestroyPixels()
|
|||
// - ImFontAtlasBuildNotifySetFont()
|
||||
//-----------------------------------------------------------------------------
|
||||
// - ImFontAtlas::AddCustomRect()
|
||||
// - ImFontAtlas::AddCustomRectFontGlyph()
|
||||
// - ImFontAtlas::RemoveCustomRect()
|
||||
// - ImFontAtlas::GetCustomRect()
|
||||
// - ImFontAtlas::AddCustomRectFontGlyph() [legacy]
|
||||
// - ImFontAtlas::AddCustomRectFontGlyphForSize() [legacy]
|
||||
// - ImFontAtlasGetMouseCursorTexData()
|
||||
//-----------------------------------------------------------------------------
|
||||
// - ImFontAtlasBuildMain()
|
||||
|
|
@ -2538,6 +2540,7 @@ void ImTextureData::DestroyPixels()
|
|||
//-----------------------------------------------------------------------------
|
||||
// - ImFontAtlasPackInit()
|
||||
// - ImFontAtlasPackAllocRectEntry()
|
||||
// - ImFontAtlasPackReuseRectEntry()
|
||||
// - ImFontAtlasPackDiscardRect()
|
||||
// - ImFontAtlasPackAddRect()
|
||||
// - ImFontAtlasPackGetRect()
|
||||
|
|
@ -3239,6 +3242,12 @@ ImFontAtlasRectId ImFontAtlas::AddCustomRect(int width, int height)
|
|||
return r_id;
|
||||
}
|
||||
|
||||
void ImFontAtlas::RemoveCustomRect(ImFontAtlasRectId id)
|
||||
{
|
||||
IM_ASSERT(id != ImFontAtlasRectId_Invalid);
|
||||
ImFontAtlasPackDiscardRect(this, id);
|
||||
}
|
||||
|
||||
#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS
|
||||
// This API does not make sense anymore with scalable fonts.
|
||||
// - Prefer adding a font source (ImFontConfig) using a custom/procedural loader.
|
||||
|
|
@ -4095,7 +4104,7 @@ ImVec2i ImFontAtlasBuildGetTextureSizeEstimate(ImFontAtlas* atlas)
|
|||
return ImVec2i(new_tex_w, new_tex_h);
|
||||
}
|
||||
|
||||
// Clear all output. Invalidates all AddCustomRectXXX return values.
|
||||
// Clear all output. Invalidates all AddCustomRect() return values!
|
||||
void ImFontAtlasBuildClear(ImFontAtlas* atlas)
|
||||
{
|
||||
ImVec2i new_tex_size = ImFontAtlasBuildGetTextureSizeEstimate(atlas);
|
||||
|
|
@ -4237,6 +4246,13 @@ static ImFontAtlasRectId ImFontAtlasPackAllocRectEntry(ImFontAtlas* atlas, int r
|
|||
return (ImFontAtlasRectId)index_idx;
|
||||
}
|
||||
|
||||
static ImFontAtlasRectId ImFontAtlasPackReuseRectEntry(ImFontAtlas* atlas, ImFontAtlasRectEntry* overwrite_entry)
|
||||
{
|
||||
IM_ASSERT(overwrite_entry->Used);
|
||||
overwrite_entry->TargetIndex = atlas->Builder->Rects.Size - 1;
|
||||
return atlas->Builder->RectsIndex.index_from_ptr(overwrite_entry);
|
||||
}
|
||||
|
||||
// This is expected to be called in batches and followed by a repack
|
||||
void ImFontAtlasPackDiscardRect(ImFontAtlas* atlas, ImFontAtlasRectId id)
|
||||
{
|
||||
|
|
@ -4300,16 +4316,9 @@ ImFontAtlasRectId ImFontAtlasPackAddRect(ImFontAtlas* atlas, int w, int h, ImFon
|
|||
|
||||
builder->Rects.push_back(r);
|
||||
if (overwrite_entry != NULL)
|
||||
{
|
||||
// Write into an existing entry instead of adding one (used during repack)
|
||||
IM_ASSERT(overwrite_entry->Used);
|
||||
overwrite_entry->TargetIndex = builder->Rects.Size - 1;
|
||||
return builder->RectsIndex.index_from_ptr(overwrite_entry);
|
||||
}
|
||||
return ImFontAtlasPackReuseRectEntry(atlas, overwrite_entry); // Write into an existing entry instead of adding one (used during repack)
|
||||
else
|
||||
{
|
||||
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.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue