gboisse / gfx

A minimalist and easy to use graphics API.
MIT License
498 stars 35 forks source link

ImGui: Support specifying multiple fonts with attached font configs #71

Closed maoliver-amd closed 1 year ago

maoliver-amd commented 1 year ago

ImGui by default only loads glyphs for standard Latin characters (i.e. first 255). In order to load glyphs outside this range you need to pass in the requested range using a font config struct. The font config struct also allows setting other values such as font size, offset etc. This PR allows specifying a font config struct with each font (now also supports passing multiple fonts)

example usage:

char const  *fonts[] = {"C:\\Windows\\Fonts\\seguisym.ttf"};
ImFontConfig fontConfigs[1];
fontConfigs[0].MergeMode           = true;
static const ImWchar glyphRanges[] = {
    0x23E0,
    0x23FF, // Media player icons
    0x1F500,
    0x1F505, // Restart icon
    0,
};
fontConfigs[0].GlyphRanges = &glyphRanges[0];
fontConfigs[0].SizePixels  = 30.0f;
fontConfigs[0].GlyphOffset.y += 5.0f; // Need to offset glyphs downward to properly center them
auto err = gfxImGuiInitialize(contextGFX, fonts, 1, fontConfigs);