juliettef / IconFontCppHeaders

C and C++ headers, C# and Python classes, Rust files and Go package for icon fonts Font Awesome, Fork Awesome, Google Material Design, Pictogrammers Material Design icons, Kenney game icons, Fontaudio, Codicons and Lucide.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Material Design Icons & ImGui

BluTree opened this issue · comments

Hello,
I tried to load the MDI font with ImGui, using the code passed in the Readme to load it :

        io.Fonts->AddFontDefault();

        ImFontConfig config;
        config.MergeMode = true;
        config.GlyphMinAdvanceX = 13.0f; // Use if you want to make the icon monospaced
        static const ImWchar icon_ranges[] = { ICON_MIN_MDI, ICON_MAX_MDI, 0 };
        _icon = io.Fonts->AddFontFromFileTTF("./resources/Editor/materialdesignicons-webfont.ttf", 13.0f, &config, icon_ranges);

but the text using the icons keeps showing me no icons and incorrect characters.
Using this code ImGui::Button(ICON_MDI_PLAY); show me this : image
I also looked in the Styles editor of imgui, but the font doesn't appear in the default font.
I tried with Font Awesome 5, and everything worked fine.

It looks like you can't use MDI with Dear ImGui. The MDI fonts moved to using 32 bit codepoints and Dear ImGui only supports 16 bit.
Additionally my code only supports 16 bits so it's broken. I'll remove Material Design Icons from this repository.

Is this issues fixed by
ocornut/imgui@c8ea0a0
?

It might do but you'd have to use the IconsMaterialDesignIcons_c.h file as IconsMaterialDesignIcons.h only supports 16 bits.

I might take a look at this in future. Right now I don't have the time.

Thanks

Adding some notes for anyone who finds this issue:

IconFontCppHeaders now support both 16bit and 32bit maximum fonts.

For 16bit font ranges use the example code with:

static const ImWchar icons_ranges[] = { ICON_MIN_MDI, ICON_MAX_MDI_FA, 0 };

and for 32bit font ranges use the example code with:

static const ImWchar icons_ranges[] = { ICON_MIN_MDI, ICON_MAX_MDI, 0 };

Since the commit mentioned above Dear ImGui now supports 32bit font codepoints internally, which requires setting the IMGUI_USE_WCHAR32 define in your imconfig.h or compile definitions:

//---- Use 32-bit for ImWchar (default is 16-bit) to support unicode planes 1-16. (e.g. point beyond 0xFFFF like emoticons, dingbats, symbols, shapes, ancient languages, etc...)
#define IMGUI_USE_WCHAR32