Doc: Tweak and extra mention of AddCustomRectFontGlyph + made the example register two rectangles.
diff --git a/imgui.cpp b/imgui.cpp
index 0df747f..79c2de9 100644
--- a/imgui.cpp
+++ b/imgui.cpp
@@ -844,6 +844,8 @@
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.
(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?
A: Use the font atlas to pack them into a single texture:
diff --git a/misc/fonts/README.txt b/misc/fonts/README.txt
index 010a720..cf953cf 100644
--- a/misc/fonts/README.txt
+++ b/misc/fonts/README.txt
@@ -212,9 +212,11 @@
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();
- 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
io.Fonts->Build();
@@ -224,14 +226,18 @@
int 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)
- if (const ImFontAtlas::CustomRect* rect = io.Fonts->GetCustomRectByIndex(rect_id))
+ for (int rect_n = 0; rect_n < IM_ARRAYSIZE(rect_ids); rect_n++)
{
- 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);
- for (int x = rect->Width; x > 0; x--)
- *p++ = IM_COL32(255, 0, 0, 255);
+ // Fill the custom rectangle with red pixels (in reality you would draw/copy your bitmap data here!)
+ for (int y = 0; y < rect->Height; y++)
+ {
+ 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);
+ }
}
}