Chapter 13. Extending and Adding Widgets

Table of Contents
Subclassing
Making a Subclass of Fl_Widget
The Constructor
Protected Methods of Fl_Widget
Handling Events
Drawing the Widget
Resizing the Widget
Making a Composite Widget
Cut and Paste Support
Making a subclass of Fl_Window

This chapter describes how to add your own widgets or extend existing widgets in FLTK.

Subclassing

New widgets are created by subclassing an existing FLTK widget, typically Fl_Widget for controls and Fl_Group for composite widgets.

A control widget typically interacts with the user to receive and/or display a value of some sort.

A composite widget widget holds a list of child widgets and handles moving, sizing, showing, or hiding them as needed. Fl_Group is the main composite widget widget class in FLTK, and all of the other composite widgets (Fl_Pack, Fl_Scroll, Fl_Tabs, Fl_Tile, and Fl_Window) are subclasses of it.

You can also subclass other existing widgets to provide a different look or user-interface. For example, the button widgets are all subclasses of Fl_Button since they all interact with the user via a mouse button click. The only difference is the code that draws the face of the button.