-
-
Notifications
You must be signed in to change notification settings - Fork 10.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
A colored icon glyph loses its color in light mode but keeps intact in dark/classic mode. #8133
Comments
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 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 |
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. |
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:
Capture.video.du.2024-11-06.13-01-54.mp4
Minimal, Complete and Verifiable Example code:
The text was updated successfully, but these errors were encountered: