Using fonts

Columns UI features centralised configuration of fonts on its Font preferences page. This allows fonts for different parts of the UI to be configured in one place.

Third-party panel components can add their own entries to the Font preferences page, and query fonts that have configured.

Adding a new entry

To add a new element to the Columns UI Fonts preferences page, you need to implement a cui::fonts::client service and register it using the cui::fonts::client::factory factory.

For an example of this, see the Console panel source.

A single component can add multiple entries by implementing cui::fonts::client multiple times, each with a different client GUID.

Querying fonts

cui::fonts::create_hfont_with_fallback() can be used to create to an HFONT for a particular font client, while cui::fonts::get_log_font_with_fallback() and can be used to get the LOGFONT structure for a particular font client. There are also various other utility functions for other scenarios in the cui::fonts namespace.

It’s also possible to pass the ID of a common font rather than a font client to these functions. However, given the ease of implementing a font client to add a custom entry, it’s not generally recommended to use the common fonts directly.

Panels using DirectWrite can use the experimental cui::fonts::get_font() function to retrieve a cui::fonts::font instance and create an IDWriteTextFormat object. Note that cui::fonts::get_font() requires Columns UI 3.0.0 alpha 1 or later, and compatibility may be broken before the final Columns UI 3.0.0 release. If a compatible version of Columns UI isn’t installed, the function will return an empty std::optional. Fallback logic should be implemented for this scenario.