Using the font picker

fontcolorpickers.C summarizes how to use a x::w::font_picker display element. This display element 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 initial list of most recently used fonts gets specified in the x::w::color_picker_config when creating the font picker. The font picker element's overloaded most_recently_used() method either returns the current list of most recently used fonts, or sets the new list, updating the font picker popup accordingly.

The font picker itself does not modify the vector of most recently used fonts. One of the parameters to the on_font_update() callback is 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 updates the most recently used vector, and uses font picker element's most_recently_used() method.