FLTK provides several layout widgets (containers) for organizing child widgets without manual coordinate calculations. Each layout widget serves different use cases and has unique resize behaviors.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/fltk/fltk/llms.txt
Use this file to discover all available pages before exploring further.
Layout Widget Types
Fl_Group - Base Container
The foundation for all layout widgets. Maintains an ordered list of child widgets with customizable resize behavior through the resizable widget. When to use:- Need precise control over widget positions
- Building custom resize behavior
- Creating simple fixed layouts
Fl_Flex - Flexible Box Layout
Modern flexible layout system for single rows or columns. Provides automatic positioning with configurable margins, gaps, and fixed/flexible sizing. When to use:- Toolbars and button rows
- Form layouts with consistent spacing
- Responsive single-direction layouts
- As a drop-in replacement for Fl_Pack (recommended since FLTK 1.4.0)
Fl_Grid - Grid Layout
CSS-like grid system with rows and columns. Widgets can span multiple cells and be aligned within their assigned grid positions. When to use:- Complex multi-row, multi-column layouts
- Dialog boxes and forms
- Dashboard-style interfaces
- Calculator or calendar layouts
Fl_Pack - Automatic Packing
Legacy packing widget that automatically arranges children horizontally or vertically and resizes itself to fit. When to use:- Simple widget lists
- Legacy code compatibility
- Self-sizing containers
Fl_Scroll - Scrollable Areas
Container that adds scrollbars when content exceeds visible area. Can contain any widget arrangement. When to use:- Large content areas
- Image viewers
- Long forms or lists
- Canvas widgets for panning
Fl_Tabs - Tabbed Interface
Tabbed container where each child group becomes a selectable tab. Only one tab’s content is visible at a time. When to use:- Multi-page dialogs
- Settings panels
- Organizing related controls
- Space-constrained interfaces
Choosing the Right Layout
Single row/column of widgets
Single row/column of widgets
Use Fl_Flex for predictable resize behavior with margins and gaps, or Fl_Pack for legacy compatibility.
Grid-based layout
Grid-based layout
Use Fl_Grid for structured multi-row/column arrangements with cell spanning.
Content larger than viewport
Content larger than viewport
Use Fl_Scroll to add scrollbars to any layout widget.
Multiple pages in same space
Multiple pages in same space
Use Fl_Tabs to organize content into selectable tabs.
Custom positioning
Custom positioning
Use Fl_Group with manual widget coordinates and custom resizable behavior.
Nesting Layouts
Layout widgets can be nested to create complex interfaces:Resize Behavior
Each layout widget handles resizing differently:- Fl_Group: Uses resizable widget to control which children expand/move
- Fl_Flex: Distributes extra space among non-fixed children
- Fl_Grid: Uses row/column weights to distribute space
- Fl_Pack: Resizes itself to wrap children (not recommended for resizable layouts)
- Fl_Scroll: Shows/hides scrollbars based on content size
- Fl_Tabs: Tabs stay constant height (if resizable set correctly)
Best Practices
Set Size Ranges
Always set
window->size_range() to prevent layouts from becoming too small:End Groups
Always call
end() after adding all children:Set Resizable
Make the main layout resizable:
Use Margins
Add visual breathing room:
Common Patterns
Toolbar with Spacer
Form Layout
Scrollable List
See Also
- Resize Behavior - Understanding FLTK’s resize system
- Widget Hierarchy - Parent-child relationships
- Drawing - How layout affects rendering