Fl_Grid is experimental in FLTK 1.4.x. The API is stable but may have minor changes in future releases.
Key Features
- Multi-row, multi-column layouts
- Widgets can span multiple cells
- Per-cell alignment (top, bottom, left, right, center, fill)
- Individual row heights and column widths
- Row/column weights for resize behavior
- Configurable margins and gaps
- Grid helper lines for debugging
Creating Fl_Grid
Defining Grid Layout
rows- Number of rowscols- Number of columnsmargin- Margin around all cells (default: 0)gap- Gap between cells (default: 0)
Adding Widgets to Grid
Basic Widget Assignment
w- Widget to add (x, y, w, h are ignored)row- Row index (0-based)col- Column index (0-based)align- Alignment within cell
Cell Spanning
Cell Alignment
Control how widgets are positioned and sized within their cells:Margins and Gaps
Margins (Space Around Grid)
Gaps (Space Between Cells)
Row and Column Configuration
Column Width
Row Height
Column/Row Weights
Control how extra space is distributed when resizing:Higher weight: Gets more space when resizing
Per-Row/Column Gaps
Working with Cells
Finding Cells
Cell Properties
Grid Helper Lines
Show grid lines during development:Complete Example
Fromexamples/grid-simple.cxx:
Common Patterns
Form Layout
Calculator Layout
Dashboard Layout
Resizing Behavior
Fl_Grid ignores the normal Fl_Group::resizable() widget. Instead, use row/column weights:Best Practices
Set Minimum Sizes
Prevent grid from becoming too small:
Use show_grid()
Debug layout during development:
Set Weights
Define which rows/columns resize:
Ignore Widget Sizes
x, y, w, h are ignored:
Reference
Header File
Key Methods
| Method | Description |
|---|---|
layout(rows, cols, margin, gap) | Define grid structure |
widget(w, row, col, align) | Add widget to cell |
widget(w, row, col, rowspan, colspan, align) | Add with spanning |
margin(...) | Set margins |
gap(row_gap, col_gap) | Set gaps |
col_width(col, width) | Set column width |
row_height(row, height) | Set row height |
col_weight(col, weight) | Set column resize weight |
row_weight(row, weight) | Set row resize weight |
show_grid(enable) | Show grid helper lines |
cell(row, col) | Get cell object |
See Also
- Fl_Flex - Single row/column layout
- Fl_Group - Base container widget
- Layout Overview - Choosing the right layout