struct fltk::Style


Each widget has a pointer to an instance of fltk::Style. Usually many widgets share pointers to the same fltk::Style. All the fltk::Styles are linked into a hierarchy of parents & child styles, so that it is possible to change an item in a parent style and propagate all the changes to the children.

When a widget looks up a value from a style, it looks at that style and each parent up until it finds a non-zero value to return, or until there are no more parents, in which case zero is used. Thus changing a parent style can make global changes as long as widgets do not have local values set.

In normal usage "set" methods like fltk::Widget::box(n) will create a "unique" style for that widget, which is a child of the original style, and set the box in that style. This "unique" style is reused for any other changes to that widget and it is deleted when the widget is deleted.

Member variables

fltk::Box box;

The type of box to draw around the outer edge of the widget (for the majority of widgets, some classes ignore this or use it to draw only text fields inside the widget). The default is fltk::DOWN_BOX.

fltk::Box button_box;

The type of box to draw buttons internal the widget (notice that fltk::Button uses box, however). The default is fltk::UP_BOX.

fltk::Box focus_box;

Type of box to draw to indicate focus. This is always called with the fltk::INVISIBLE flag as only the border should be drawn. The default is fltk::DOTTED_FRAME.

void (*glyph)(const fltk::Widget*, int glyph, int x, int y, int w, int h, fltk::Flags);

Draw part of a widget, called a "glyph". Examples are the up and down arrows on sliders, the slider itself, and check boxes. The base class draws arrow buttons (because they are so commonly used), but most widgets that use this define their own function to call. A theme can make these functions point at it's own code and thus customize the appearance of widgets quite a bit.

The default glyph function can draw these values for glyph:

If you wish to write your own glyph function you should examine the ones in the fltk source code and in the sample theme plugins to see how the arguments are interpreted.

fltk::Font label_font;

The font used to draw the label. Default is fltk::HELVETICA.

unsigned int label_size;

Size of label_font. Default is 12.

fltk::Font text_font;

Provides a font for text displays. Default is fltk::HELVETICA.

unsigned int text_size;

Size of text_font. Checkboxes and some other widgets use this to control the size of the glyph. Default is 12.

unsigned int leading;

Extra spacing added between text lines or other things that are stacked vertically. The default is 0 (menus have a default of 4).

fltk::Labeltype label_type;

How to draw the label. This provides things like inset, shadow, and the symbols. fltk::NORMAL_LABEL.

fltk::Color color;

Color of the widgets. The default is fltk::WHITE. This color is inherited by text displays and browsers, most of the "gray" you see is due to widgets like fltk::Group that default the color to gray, and the fact that many parts of the interface are drawn with the button_color described below.

If you want to change the overall color of all the gray parts of the interface you want to call fltk::background(color) instead, as this will set the entry for fltk::GRAY and also set the "gray ramp" so that the edges of buttons are the same color.

fltk::Color label_color;

Color used to draw labels and glyphs. Default is fltk::BLACK.

fltk::Color highlight_color;

The color to draw the widget when the mouse is over it (for scrollbars and sliders this is used to color the buttons). The default of zero disables highlighting.

fltk::Color highlight_label_color;

Color to draw labels atop the highlight_color. The default of zero leaves the label_color unchanged.

fltk::Color button_color;

Color used when drawing internal buttons. Default is fltk::GRAY. Check and radio buttons use this to color in the glyph.

fltk::Color text_color;

Color to draw text inside the widget. Default is black. Check and radio buttons use this to control the color of the checkmark.

fltk::Color selection_color;

Color drawn behind selected text in inputs, or selected browser or menu items, or lit light buttons. The default is Windows 95 blue.

fltk::Color selection_text_color;

The color to draw text atop the selection_color. The default is fltk::WHITE.

fltk::NamedStyle* fltk::Style::find(const char* name);

This is a static method on fltk::Style. It returns the first style found that matches the name. Case is ignored and spaces and underscores are considered equivalent. If nothing matches NULL is returned.

Theme-setting code uses this to locate the styles it has to modify. Using a string to locate the styles serves several purposes: