Doc: Tweak and extra mention of AddCustomRectFontGlyph + made the example register two rectangles.
This commit is contained in:
parent
eb3e271c24
commit
4b95e7c2f3
@ -844,6 +844,8 @@ CODE
|
|||||||
main font. Then you can refer to icons within your strings.
|
main font. Then you can refer to icons within your strings.
|
||||||
You may want to see ImFontConfig::GlyphMinAdvanceX to make your icon look monospace to facilitate alignment.
|
You may want to see ImFontConfig::GlyphMinAdvanceX to make your icon look monospace to facilitate alignment.
|
||||||
(Read the 'misc/fonts/README.txt' file for more details about icons font loading.)
|
(Read the 'misc/fonts/README.txt' file for more details about icons font loading.)
|
||||||
|
With some extra effort, you may use colorful icon by registering custom rectangle space inside the font atlas,
|
||||||
|
and copying your own graphics data into it. See misc/fonts/README.txt about using the AddCustomRectFontGlyph API.
|
||||||
|
|
||||||
Q: How can I load multiple fonts?
|
Q: How can I load multiple fonts?
|
||||||
A: Use the font atlas to pack them into a single texture:
|
A: Use the font atlas to pack them into a single texture:
|
||||||
|
@ -212,9 +212,11 @@ texture, and blit/copy any graphics data of your choice into those rectangles.
|
|||||||
|
|
||||||
Pseudo-code:
|
Pseudo-code:
|
||||||
|
|
||||||
// Add font, then register one custom 13x13 rectangle mapped to glyph 'a' of this font
|
// Add font, then register two custom 13x13 rectangles mapped to glyph 'a' and 'b' of this font
|
||||||
ImFont* font = io.Fonts->AddFontDefault();
|
ImFont* font = io.Fonts->AddFontDefault();
|
||||||
int rect_id = io.Fonts->AddCustomRectFontGlyph(font, 'a', 13, 13, 13+1);
|
int rect_ids[2];
|
||||||
|
rect_ids[0] = io.Fonts->AddCustomRectFontGlyph(font, 'a', 13, 13, 13+1);
|
||||||
|
rect_ids[1] = io.Fonts->AddCustomRectFontGlyph(font, 'b', 13, 13, 13+1);
|
||||||
|
|
||||||
// Build atlas
|
// Build atlas
|
||||||
io.Fonts->Build();
|
io.Fonts->Build();
|
||||||
@ -224,14 +226,18 @@ Pseudo-code:
|
|||||||
int tex_width, tex_height;
|
int tex_width, tex_height;
|
||||||
io.Fonts->GetTexDataAsRGBA32(&tex_pixels, &tex_width, &tex_height);
|
io.Fonts->GetTexDataAsRGBA32(&tex_pixels, &tex_width, &tex_height);
|
||||||
|
|
||||||
// Fill the custom rectangle with red pixels (in reality you would draw/copy your bitmap data here)
|
for (int rect_n = 0; rect_n < IM_ARRAYSIZE(rect_ids); rect_n++)
|
||||||
if (const ImFontAtlas::CustomRect* rect = io.Fonts->GetCustomRectByIndex(rect_id))
|
|
||||||
{
|
{
|
||||||
for (int y = 0; y < rect->Height; y++)
|
int rect_id = rects_ids[rect_n];
|
||||||
|
if (const ImFontAtlas::CustomRect* rect = io.Fonts->GetCustomRectByIndex(rect_id))
|
||||||
{
|
{
|
||||||
ImU32* p = (ImU32*)tex_pixels + (rect->Y + y) * tex_width + (rect->X);
|
// Fill the custom rectangle with red pixels (in reality you would draw/copy your bitmap data here!)
|
||||||
for (int x = rect->Width; x > 0; x--)
|
for (int y = 0; y < rect->Height; y++)
|
||||||
*p++ = IM_COL32(255, 0, 0, 255);
|
{
|
||||||
|
ImU32* p = (ImU32*)tex_pixels + (rect->Y + y) * tex_width + (rect->X);
|
||||||
|
for (int x = rect->Width; x > 0; x--)
|
||||||
|
*p++ = IM_COL32(255, 0, 0, 255);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user