pthom / hello_imgui

Hello, Dear ImGui: unleash your creativity in app development and prototyping
https://pthom.github.io/hello_imgui
MIT License
680 stars 101 forks source link

Added config parameters to font loading functions #13

Closed codecat closed 3 years ago

codecat commented 3 years ago

This is in response to #12.

There is now an added ImFontConfig config parameters to all font loading functions, which serves as a "template" for the actual config (much like how imgui does it internally too). I've also exposed MergeFontAwesomeToLastFont so that it's easier to use a different configuration (and size) for both icon font & regular font.

Example usage:

auto& io = ImGui::GetIO();

ImFontConfig configIcons;
configIcons.GlyphMinAdvanceX = 18;
configIcons.GlyphMaxAdvanceX = 18;

io.FontDefault = HelloImGui::LoadFontTTF("fonts/DroidSans.ttf", 16);
HelloImGui::MergeFontAwesomeToLastFont(15, configIcons);

I have also removed the lambda's creating the config structures as well as the static variables intended to keep the config structures in memory as it doesn't appear to be necessary.

pthom commented 3 years ago

I have also removed the lambda's creating the config structures as well as the static variables intended to keep the config structures in memory as it doesn't appear to be necessary.

You are right, thanks for pointing this out! I now remember I had an issue with the glyph_range param of AddFontFromMemoryTTF, not with the config in itself.

Your PR looks good to me, and brings value!

Are you OK to merge?

codecat commented 3 years ago

Ah good point, I didn't see that one! I kept those arrays static however, so the PR should still be correct. If all looks okay to you, I'm ok to merge!