Closed IniKiwi closed 2 weeks ago
The glyph needs to be marked as Colored to undo the vertex coloring applied by text color. It should happens to work because in the darker style the text color is white (1,1,1,1) and in the other it is black (0,0,0,1) which multiplies down the color.
There is 1 bit in ImFontGlyph for that:
unsigned int Colored : 1; // Flag to indicate glyph is colored and should generally ignore tinting
Unfortunately this wasn't planned ahead in the AddCustomRectFontGlyph()
function, there is no way to pass that parameter.
You would currently need to use this workaround:
int rect_ids[10];
rect_ids[0] = io.Fonts->AddCustomRectFontGlyph(font, *(const ImWchar*)ICON_WORLD, 16, 16, 16+1);
rect_ids[1] = io.Fonts->AddCustomRectFontGlyph(font, *(const ImWchar*)ICON_BRICK, 16, 16, 16+1);
// Build atlas
io.Fonts->Build();
for (int n = 0; n < 2; n++)
{
ImFontGlyph* glyph = (ImFontGlyph*)font->FindGlyph(rect_ids[n].GlyphID);
glyph->Colored = 1;
}
Normally I would fix it by expanding the AddCustomRectFontGlyph()
API but as with #8107 I am currently working on a large refactor of the font system.
Thanks you very much! Do you have any idea how fit this icon in the treenode by changing the vertical alignment of the glyph and the size of the tree nodes?
If you manually add glyphs to a font it should be added with same vertical size. Horizontal size you specify.
Consider using emoji svg fonts using freetype as an alternative.
I'm using same icons as gmod and old roblox, these icons are just 16x16 bitmaps. I will leave it like this. Thanks you very much!
These icons are so cute!
As an undocumented small change I have pushed 17bd417
You can now do this:
rect_ids[0] = io.Fonts->AddCustomRectFontGlyph(font, *(const ImWchar*)ICON_WORLD, 16, 16, 16+1);
rect_ids[1] = io.Fonts->AddCustomRectFontGlyph(font, *(const ImWchar*)ICON_BRICK, 16, 16, 16+1);
for (int n = 0; n < 2; n++)
io.Fonts->GetCustomRectByIndex(rects_id[n])->GlyphColored = 1;
It's not great and doesn't constitute a neat public API, but you can do this in the same call size without waiting for Build() to occur.
I'll keep this in mind when we introduce a new API.
Version/Branch of Dear ImGui:
Version latest, Branch: docking
Back-ends:
imgui_impl_glfw.cpp + imgui_impl_opengl3.cpp
Compiler, OS:
Linux Debian 12
Full config/build information:
Details:
I'm trying to add icons to a treenode. But the icons are made black.
Screenshots/Video:
https://github.com/user-attachments/assets/64840460-4a67-4bec-98f8-160c497e6bb8
Minimal, Complete and Verifiable Example code: