Code for changing fonts and fontsizes for FLTK 1.1 and 1.3

Often the user wants to set up windows for his own style, older ones need larger texts, the younger stylish fonts. Also it should be possible, that text follows size of window, when resizing.

Download Code


All FLTK widgets and windows are based on class Fl_Widget. So it is easy to change labelfont and labelsize, because every widget provides the methods labelfont(Fl_Font) and labelsize(Fl_Fontsize). When there is a window it is just necessary to go through all widgets and tell them new labelfont and labelsize.

Because not every widget provides text, the methods textfont() and textsize() are not methods of basic Fl_Widget. That's a pity, but not a real problem. When there is a Fl_Widget* the function tries to cast it to a class, that provides textfont() and textsize() and then uses this class. Because most of FLTK widgets derive from a few basic classe this is not a serious amount of casting. When there is a window, it is only necessary to go through all widgets and tell them textfont and textsize, when they use text.

All functionality regarding to font and fontsize is inside of files "f_font_size.h" and "f_font_size.cpp". The following functions and interfaces are defined in these files. To use them, you must

#include "f_font_size.h"


There are four functions inside of namespace f_font_size:

void Resize_Fonts(Fl_Widget* pWdg, int Labelsize, int Textsize);

    Resizes labelsize and textsize for pWdg and all widgets inside of pWdg, in case pWdg is derived from Fl_Group.

void Set_Fonts(Fl_Widget* pWdg, Fl_Font Lbl_Font, Fl_Font Txt_Font);

    Sets labelfont and textfont for pWdg and all widgets inside of pWdg, in case pWdg is derived from Fl_Group.

void Resize_Fonts(int Labelsize, int Textsize);

    Sets Labelsize and Textsize to all visible windows

void Set_Fonts(Fl_Font Lbl_Font, Fl_Font Txt_Font);

    Sets Labelfont and Textfont to all visible windows

Be aware, there is no check for valid parameters. Invalid fonts and sizes can vanish all texts of the applications.

Special Demands

It's a good start to be able to set all fonts and sizes of an application, but there are some demands missing, so there are some special classes:


i_basic_font_size adds font control to any widget or group, but normally it will be assigned to the Fl_Window to control all widgets inside of it.


assigns current settings to a group or window.  This is ment for intitialising not resizable windows. It not only assigns the fonts, it also adjusts the size of the window, to meet general settings.
When there is a main window resized to double size and also using larger fonts and a subwindow is going to be opened, it also will be set to double size. Now the subwindow matches to larger fonts of main window and all windows are consistent


must be used to make user defined widgets accessable by font_size classes and functions.


The example demonstrates how to use the font_size classes.

f_font_size.h, f_font_size.cpp
classes for managing fonts and textsizes

fld_fonts.fld, fld_fonts.h, fld_fonts.cpp
definition of font dialog mask

Fl_Fonts_Dialog.h, Fl_Fonts_Dialog.cpp
these files provide the methods to choose fonts and to change size of labels and texts. fld_fonts is used by this dialog. The code comes from the FLTK fonts example.

this is an inheritance from Fl_Double_Window and connects font_size methods to resizing of a window. It can be used to add the functionality to existing applications by replacing e.g. FL_Double_Window by Fl_Font_Window.

Fl_Example.fld, Fl_Example.h, Fl_Example.cpp
definition of example dialog mask

Fl_Sub_Dlg.fld, Fl_Sub_Dlg.h, Fl_Sub_Dlg.cpp
definition of sub dialog

contains dlg_example which provides the methods for Fl_Example
contains main loop

[ i_basic_font_size ] [ i_local_font_size ] [ i_font_size ]