Skip to content
This repository has been archived by the owner on Dec 31, 2022. It is now read-only.

Commit

Permalink
Add support for setting a FontConfig name
Browse files Browse the repository at this point in the history
IMGUI will synthesize a diagnostic name for fonts added from files
(eg "foo.ttf, 16px") if there isn't a name provided in the FontConfig.

There isn't an equivalent synthetic name for fonts added from memory,
so enable the name to be set on the FontConfig.

The names are visible in the Dear Imgui Demo window
under Configuration / Style, in the Fonts drop-list.
  • Loading branch information
somersf committed Aug 30, 2020
1 parent 1f38586 commit 5f1384d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
13 changes: 13 additions & 0 deletions FontConfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,19 @@ func (config FontConfig) SetMergeMode(value bool) {
}
}

// SetName sets a short display name for a font, for diagnostic purposes.
// If the FontConfig does not provide a name, one will be synthesized for
// fonts which are added from files. When adding fonts from memory, this
// method can be used to provide a name.
// The name will be truncated if it is longer than the limit supported by imgui.
func (config FontConfig) SetName(name string) {
if config != DefaultFontConfig {
nameArg, nameFin := wrapString(name)
defer nameFin()
C.iggFontConfigSetName(config.handle(), nameArg)
}
}

// getFontDataOwnedByAtlas gets the current ownership status of the font data.
func (config FontConfig) getFontDataOwnedByAtlas() bool {
if config != DefaultFontConfig {
Expand Down
8 changes: 8 additions & 0 deletions wrapper/FontConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ void iggFontConfigSetMergeMode(IggFontConfig handle, IggBool value)
fontConfig->MergeMode = value;
}

void iggFontConfigSetName(IggFontConfig handle, char const *value)
{
ImFontConfig *fontConfig = reinterpret_cast<ImFontConfig *>(handle);
const size_t bufSize = sizeof(fontConfig->Name);
strncpy(fontConfig->Name, value, bufSize - 1);
fontConfig->Name[bufSize - 1] = '\0';
}

int iggFontConfigGetFontDataOwnedByAtlas(IggFontConfig handle)
{
ImFontConfig *fontConfig = reinterpret_cast<ImFontConfig *>(handle);
Expand Down
1 change: 1 addition & 0 deletions wrapper/FontConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ extern void iggFontConfigSetPixelSnapH(IggFontConfig handle, IggBool value);
extern void iggFontConfigSetGlyphMinAdvanceX(IggFontConfig handle, float value);
extern void iggFontConfigSetGlyphMaxAdvanceX(IggFontConfig handle, float value);
extern void iggFontConfigSetMergeMode(IggFontConfig handle, IggBool value);
extern void iggFontConfigSetName(IggFontConfig handle, char const *value);
extern int iggFontConfigGetFontDataOwnedByAtlas(IggFontConfig handle);

#ifdef __cplusplus
Expand Down

0 comments on commit 5f1384d

Please sign in to comment.