StyleOptions Class Reference

#include <Pt/Forms/StyleOptions.h>

Stores named appearance options. More...

Public Member Functions

 StyleOptions ()
 Constructs an empty options object.
 StyleOptions (const StyleOptions &o)
 Copies o.
 ~StyleOptions ()
 Destructor.
StyleOptionsoperator= (const StyleOptions &o)
 Assigns o.
std::size_t generation () const
 Returns the current change generation.
bool hasOptions () const
 Returns true if this object contains any local option.
bool isDefault (const StyleOptions &base) const
 Returns true if this object does not override base.
void bind (const StyleOptions *inherited)
 Binds this overlay to the parent options inherited.
const StyleOptionsparent () const
 Returns the bound parent options, or 0.
template<typename T>
const T * findLocal () const
 Returns the local option of type T, or 0.
template<typename T>
const T * find () const
 Returns the local or inherited option of type T, or 0.
template<typename T>
const T & get () const
 Returns the local or inherited option of type T.
template<typename T>
void set (const T &option)
 Adds or replaces the local option of type T.
template<typename T>
void reset ()
 Removes the local option of type T if present.

Static Public Member Functions

static StyleOptions defaults ()
 Returns options filled with the built-in default values.

Static Public Attributes

static const std::size_t InvalidGeneration = 0
 Invalid generation value.

Detailed Description

A StyleOptions object contains named appearance options, such as the application background, text colors, accent color, contour pen, and default font. A Style uses these values when it prepares the renderers that paint controls.

Application owns the global style options. It creates them from defaults() and uses them with the default PlatinumStyle. To change the application theme, create an options object, change the values that the application requires, and pass it to Application::setStyleOptions(). The application resets its renderers and invalidates its widgets so that the new appearance is applied.

options.set(
);
options.set(
);
app.setStyleOptions(options);
Accent color option.
Definition StyleOptions.h:188
Provides the runtime root of a Forms user interface.
Definition Application.h:88
void setStyleOptions(const StyleOptions &options)
Replaces the style options for all widgets.
static Application & instance()
Returns the Forms application instance.
Stores named appearance options.
Definition StyleOptions.h:646
static StyleOptions defaults()
Returns options filled with the built-in default values.
void set(const T &option)
Adds or replaces the local option of type T.
Definition StyleOptions.h:778
Text color option.
Definition StyleOptions.h:335
8-bit ARGB color.
Definition Color.h:65

The default constructor creates an empty options object. An empty object is useful as a local overlay for a control. A styler binds this overlay to the application options. A local option overrides the option of the same type in the application options, while an option that is not present locally continues to use the application value. Application owns the live global instance, constructed from defaults(). Application::styleOptions() returns that object as const.

findLocal() searches only this object and returns 0 when the option is not stored locally. find() searches this object and then its bound parent. After bind(), get() returns a local or inherited token and throws std::logic_error when the requested option is not available. set() adds or replaces a local option, and reset() removes a local option.

StyleOptions stores tokens that every style can honor. Look-specific metrics stay in the derived style or renderer.

FontOption supports complete and partial font overrides. A local option can change only the font size, weight, or slant while inheriting the font family and all remaining attributes from the application font.

generation() changes when local options or their binding change. Stylers use the generation to detect that a renderer must prepare its drawing state again.

Member Function Documentation

◆ generation()

std::size_t generation ( ) const

The generation changes when local options or their binding change.

◆ bind()

void bind ( const StyleOptions * inherited)

Rebinding with the same parent and parent generation does no work. Passing 0 removes the parent.

◆ get()

template<typename T>
const T & get ( ) const
Exceptions
%std::logic_errorif the requested option is not available.