Using the font picker

fontcolorpickers.C summarizes how to use a x::w::font_picker widget. This widget provides a popup for selecting the most common font options of the x::w::font.

x::w::font_picker's overloaded current_font() method gives the most recently selected font and its options, or resets the font picker's options from the specified x::w::font's. on_font_update() installs a callback that gets invoked whenever a new font gets officially picked, by the popup's Ok button. Only one callback can be installed at one time, and the initial callback is one of the values that are specified in x::w::font_picker_config when creating the font picker.

The font picker lists all available font families in alphabetical order. An optional list of most recently used fonts appears first, and provides a convenient way to find often use fonts. x::w::font_picker_group_id represents a font family, and the list of most recently used fonts is just a std::vector of them.

The most recently used font list requires the application to install an on_font_update() callback. The callback controls how many most recently used fonts appear first. This callback can be installed after creating the font picker, or by setting it in the x::w::font_picker_config. The first two parameters to the callback are the picked x::w::font_picker_group_id, in addition to the picked x::w::font. The application has complete control over the most recently used vector, and how big it is. As fontcolorpickers.C demonstrates, the callback retrieves the vector of the most recently used fonts from the font picker, updates it, and installs the updated most_recently_used() vector.

The initial list of most recently used fonts gets tentatively specified in the x::w::font_picker_config when creating the font picker. The final list of most recently used fonts, in the new widget, may differ for the following reasons.

The final list of the font picker's most recently used fonts comes from the widget's overloaded most_recently_used() method. It either returns the current list of most recently used fonts, or sets the new list, updating the font picker popup accordingly.