Use this file to discover all available pages before exploring further.
Widgets are the fundamental building blocks of FLTK applications. Every visible element in your interface—buttons, text fields, windows, and more—is a widget derived from the Fl_Widget base class.
All widgets in FLTK inherit from Fl_Widget, which provides the core functionality for:
Position and size management
Visual appearance (colors, box types, labels)
Event handling
Parent-child relationships
Callback mechanisms
You cannot create an Fl_Widget directly because its constructor is protected. Instead, use one of FLTK’s many derived widget classes or create your own subclass.
Widgets have two primary colors defined in FL/Fl_Widget.H:121-122:
// Background colorwidget->color(FL_WHITE);widget->color(FL_RED);widget->color(fl_rgb_color(200, 220, 240)); // Custom RGB// Selection/highlight colorwidget->selection_color(FL_BLUE);// Set both at oncewidget->color(FL_WHITE, FL_BLUE);
The Fl_Label struct (FL/Fl_Widget.H:49-76) stores all label information:
// Set label textwidget->label("Hello World");// Make a copy (widget manages memory)widget->copy_label("Temporary String");// Label with imageFl_PNG_Image *icon = new Fl_PNG_Image("icon.png");widget->image(icon);
widget->show(); // Make visiblewidget->hide(); // Make invisibleif (widget->visible()) { // Widget is set to visible}if (widget->visible_r()) { // Widget AND all parents are visible}
class My_Widget : public Fl_Widget {public: My_Widget(int X, int Y, int W, int H, const char *L = 0) : Fl_Widget(X, Y, W, H, L) { box(FL_UP_BOX); color(FL_WHITE); } void draw() override; int handle(int event) override;};
Widgets are typically allocated with new and automatically deleted when their parent is deleted. The parent window deletes all children when it’s destroyed.
Fl_Window *win = new Fl_Window(400, 300);Fl_Button *btn = new Fl_Button(10, 10, 100, 30);// btn will be automatically deleted when win is deleted
Call redraw() After Property Changes
FLTK doesn’t automatically redraw when you change widget properties: