struct Fl_Style

Each widget has a pointer to an instance of Fl_Style. Usually many widgets share pointers to the same Fl_Style. All the Fl_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 Fl_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

Fl_Boxtype box;

The type of box to draw around the outer edge of the widget, or around raised button-like things in a complex widget such as a scrollbar. The default is FL_UP_BOX.

Fl_Boxtype text_box;

The type of box to draw around text fields and other sunken parts of a widget, such as the checkmark in a check button or the background of a slider. The default is FL_DOWN_BOX.

void (*glyph)(int type, int x,int y,int w,int h, Fl_Color bg, Fl_Color fg, Fl_Flags, Fl_Boxtype);

Draw a widget part, called a "glyph", such as a checkbox or arrow button. You should use the FL_VALUE of the flags to determine if the glyph is pushed in or turned on. If you write your own function call the default of fl_glyph() for any symbols you don't recognize. Currently defined glyphs:

These glyphs all have values starting at 100 or more. Many widget subclasses define a private glyph function to draw parts of themselves, using local glyphs whose values start at 1. A "theme" may want to replace these functions, you should examine the fltk source code to find out what the codes for the glyphs are.

Fl_Font label_font;

The font used to draw the label. Default is FL_HELVETICA.

unsigned int label_size;

Size of label_font. Default is 12.

Fl_Font text_font;

Provides a font for text displays. Default is FL_HELVETICA.

unsigned int text_size;

Size of text_font. Default is 12.

unsigned int leading;

Extra spacing added between text lines or other things that are stacked vertically. The default is 2.

Fl_Labeltype label_type;

How to draw the label. This provides things like inset, shadow, and the symbols. FL_NORMAL_LABEL.

Fl_Color color;

Color passed to box. Default is FL_GRAY. If you wish to change the general color of fltk you probably want to call fl_background(color) instead, as this will set the entry for FL_GRAY and also set the "gray ramp" so that the edges of buttons are the same color.

Fl_Color label_color;

Color used to draw labels and glyphs. Default FL_NO_COLOR.

Fl_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 moving parts). The default of zero disables highlighting.

Fl_Color highlight_label_color;

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

Fl_Color text_background;

Color passed to text_box. Default is FL_LIGHT2.

Fl_Color text_color;

Color to draw text inside the widget. Default is black.

Fl_Color selection_color;

Color drawn behind selected text or browser or menu items. The default is Windows 95 blue.

Check buttons, radio buttons, menu items, and light buttons use this to color in the glyph that indicates check/radio state when the button is turned on (text_background is used for the check marks when they are off).

Fl_Color selection_text_color;

The color to draw text atop the selection_color. The default is FL_WHITE.

Fl_Named_Style

Fl_Named_Style(const char* name, void (*revertfunc)(Fl_Style*)=0, Fl_Style** pdefault_style = 0);

If you define your own widget class you may want it to have a default style that is different than the parent class. To do this you should declare a static style structure with a string name so that the theme code can locate (and possibly modify) it. You must also provide a "revert" function which is used to initialize the style and to reset it if the user changes the theme (it is cleared to zero before revert is called).

Here is an example of a class that wants the box to default to FL_ROUND_BOX:

static void revert(Fl_Style* s) {
  s->box = FL_ROUND_BOX;
}
static Fl_Named_Style* style = new Fl_Named_Style("MyWidget", revert, &style);

MyWidget::MyWidget(int x, int y, int w, int h, const char *l)
  : Fl_Widget(x,y,w,h,l)
{
  style(::style);
}

If you don't care if the themes can see you widget, you can pass a null pointer as the style name. You can pass null as the revert function if the revert function does not change anything from the default.

Setting a Theme

To implement "themes" the theme code needs to write a number of static locations, primarily the default style of several classes. If you change the theme after windows are displayed, use Fl::redraw() to cause everything to redraw.

You ususally only need to change a few styles to implement a theme. All widgets inherit from the default style anything that they don't set themselves.

Fl_Named_Style* Fl_Style::find(const char* name);

To locate a style to modify by name, use this static Fl_Style method. By using this function for anything other than default_style it allows you to test if a style is actually linked into the program, so that you can make a theme plugin that changes any style.

Case is ignored and spaces and underscores are considered equivalent.

Fl_Widget::default_style

Provides all the defaults described above. This is the only style that does not have a parent. Highlighting is disabled by default, to turn it on you should set highlight color.

Fl_Style::find("input")

This style is used by Fl_Input, but a few other widgets directly refer to it to draw imbedded text editing fields.

Fl_Style::find("output")

This style is used by Fl_Output, but a few other widgets directly refer to it to draw imbedded display fields. Setting the color to gray will simulate NeXTStep or other user interfaces where interactivity is indicated by color.

Fl_Style::find("Check_Button")

Styles usually need to mess with the window color and glyph function here to get check marks correct.

Fl_Style::find("menu")

This style is used for the pop-up menu windows. text_box is drawn around each item, and selection_color is used to color the current one.

Fl_Style::find("item")

Menu items. If you use checkmarks in menus you will have to make similar fixes to this as to check_button. Notice that the box drawn around each item is chosen by "menu", not by this.

Fl_Style::find("menu_title")

How to draw the titles in menu bars. The box is drawn around each of them.

Fl_Style::find("Scrollbar")

Styles usually need to mess with the window color and glyph function to get these to appear correctly.

Fl_Tooltip::default_style

The box and color of this controls the appearance of the tooltips. This is always linked in, so you don't need find(). Tooltips also have some other static fields to set the timeout and position, see the Fl_Tooltip documentation.

void fl_background(Fl_Color)

This global function changes the "gray ramp" in the fltk color map so that the color FL_GRAY is set the the rgb values of the passed color. This is the best way to change the overall color of your application, because it sets all the shaded borders.

fl_normal_box.data
fl_down_box.data

These are pointers to string constants. Changing these pointers can globally modify how the edges of all the thick boxes are drawn. They are used not only for the normal box, but also by the FL_DIAMOND_BOX and FL_ROUND_BOX, and also by the glyphs.

The string contains one letter for each edge of the box, drawn counter-clockwise from the outside in in a spiral. The letter 'A' is black, the letter 'X' is white, and the letter 'R' is FL_GRAY. It starts in the lower-left corner, or if you put a leading '2' it starts in the upper-right corner.