TraitsUI

Manages internal element sizes for a BaseUI-derived object.  TraitsUI provides a foundation for any BaseUI class to have a set of parameters that define a default size for the UI element as well as every single internal element within the overall element.  The TraitsUI class provides a set of hash maps that let any size value needed to draw the window be accessed via a text string, allowing great flexibility and extensibility.

TraitsUI handles user-initiated resizes of every UI element by resetting itself back to its default state and then applying the resize percentage to every element in its size hash map, thus ensuring a linear size change for every element when the UI element is drawn.  By applying the same change percentage to every element, it allows the relative sizes of the UI element to preserved, the goal being that the UI element looks good at any size.

Project

UICore

Include

TraitsUI.h

Summary
Manages internal element sizes for a BaseUI-derived object.
Returns the size value for the given key.
Returns the color value for the given key.
Returns the font value for the given key.
Determines the best sized font for a given height.
Resizes all values in the size hash.
The TraitsUI constructor.
The size hash.
Unchangeable integer data hash.
The color hash.
The font hash.
Resets the TraitsUI size hash back to default values.

Public

Summary
Returns the size value for the given key.
Returns the color value for the given key.
Returns the font value for the given key.
Determines the best sized font for a given height.
Resizes all values in the size hash.

Functions

size

wxInt32 size(const wxString &key)

Returns the size value for the given key.  First checks for the key in the constant hash.  Then checks in the size hash, and finally throws an error message to the screen if the key does not exist.

Paramaters

keyThe key for the size hash map.

Returns

The size value associated with the key.

color

wxColour color(const wxString &key)

Returns the color value for the given key.  Throws an error message to the screen if the key does not exist.

Paramaters

keyThe key for the color hash map.

Returns

The color value associated with the key.

font

const wxFont &font(const wxString &key)

Returns the font value for the given key.  Throws an error message to the screen if the key does not exist.

Paramaters

keyThe key for the color hash map.

Returns

The font value associated with the key.

calculateFontSize

void calculateFontSize(wxDC &dc, 
const wxString &font, 
const wxString &height, 
const wxInt32 num = 1)

Determines the best sized font for a given height.  Given a font value, a height, and the number of lines of text, determines the size of the font that will fit that number of lines of text into the given height, and then sets the font point size to it.

Parameters

dcThe device context the text is being drawn in.
fontThe key of the font in the font hash.
heightThe total height the font has to fit in.
numThe number of lines within the total height.

Virtual Functions

Resize

virtual void Resize(const float percent)

Resizes all values in the size hash.  Resets the TraitsUI object to its default values and then multiplies all values in the size hash by the given percentage.

Parameters

perecentThe percent to multiple the size hash values by.

Protected

Summary
The TraitsUI constructor.
The size hash.
Unchangeable integer data hash.
The color hash.
The font hash.

Constructors

TraitsUI

TraitsUI()

The TraitsUI constructor.  Sets default size fields of Width and Height, since all UI elements have at least a width and a height.  Sets default constants for wxCurve and winCurve, for elements to know how much “roundness” to have on their edges.  Sets default colors for background, outline, and font color, so that all UI elements have a common look and feel.  Sets the default font for all UI elements, for the same reason.

Variables

mSizes

IntHash mSizes

The size hash.  Contains UI element sizes that will be resized if the user initiates a total UI resize event.

mConstants

IntHash mConstants

Unchangeable integer data hash.  Any constants that need to be saved through UI resizes are stored here.

mColours

ColourHash mColours

The color hash.  Any colors needed for the UI element are stored here.

mFonts

FontHash mFonts

The font hash.  Any fonts needed for the UI element are stored here.

Private

Summary
Resets the TraitsUI size hash back to default values.

Pure Virtual Functions

Reset

virtual void Reset()=0

Resets the TraitsUI size hash back to default values.

A base class for all main screen UI.
wxInt32 size(const wxString &key)
Returns the size value for the given key.
wxColour color(const wxString &key)
Returns the color value for the given key.
const wxFont &font(const wxString &key)
Returns the font value for the given key.
void calculateFontSize(wxDC &dc, 
const wxString &font, 
const wxString &height, 
const wxInt32 num = 1)
Determines the best sized font for a given height.
virtual void Resize(const float percent)
Resizes all values in the size hash.
TraitsUI()
The TraitsUI constructor.
IntHash mSizes
The size hash.
IntHash mConstants
Unchangeable integer data hash.
ColourHash mColours
The color hash.
FontHash mFonts
The font hash.
virtual void Reset()=0
Resets the TraitsUI size hash back to default values.
UICore provides a set of common UI controls that promote a constant look and feel across all aspects of the UI.