Skip to main content

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.

Overview

The Fl_Browser widget displays a scrolling list of text lines and manages all the storage for the text. It’s useful for showing a vertical list of named objects to the user.
Line numbers start from 1 (zero is reserved for “no line”). Methods do not check if passed line numbers are in range - they must always be greater than zero and ≤ size().

Constructor

Fl_Browser
constructor
Creates a new browser widget.
X
int
required
X position of the widget
Y
int
required
Y position of the widget
W
int
required
Width of the widget
H
int
required
Height of the widget
L
const char*
default:"0"
Optional label for the widget

Item Management

add
void
Adds a new line to the end of the browser.
newtext
const char*
required
The text string to add
d
void*
default:"0"
Optional data pointer associated with this line
insert
void
Inserts a new line at the specified position.
line
int
required
Line number where to insert (1-based)
newtext
const char*
required
The text string to insert
d
void*
default:"0"
Optional data pointer associated with this line
remove
void
Removes the specified line from the browser.
line
int
required
Line number to remove (1-based)
clear
void
Removes all lines from the browser.
load
int
Loads the browser with the lines from a file.
filename
const char*
required
Path to the file to load
Returns non-zero on error.
swap
void
Swaps two lines in the browser.
a
int
required
First line number (1-based)
b
int
required
Second line number (1-based)

Selection

select
int
Selects or deselects a line.
line
int
required
Line number to select (1-based)
val
int
default:"1"
1 to select, 0 to deselect
Returns 1 if state changed, 0 otherwise.
selected
int
Returns whether a line is selected.
line
int
required
Line number to check (1-based)
Returns 1 if selected, 0 otherwise.
value
int
Returns the line number of the currently selected line, or 0 if none selected.

Display Control

topline
void
Scrolls the browser so the specified line is at the top.
line
int
required
Line number to display at top (1-based)
middleline
void
Scrolls the browser so the specified line is in the middle.
line
int
required
Line number to display in middle (1-based)
bottomline
void
Scrolls the browser so the specified line is at the bottom.
line
int
required
Line number to display at bottom (1-based)
displayed
int
Checks if a line is currently visible in the display window.
line
int
required
Line number to check (1-based)
Returns 1 if visible, 0 otherwise.
make_visible
void
Scrolls the browser to make the specified line visible.
line
int
required
Line number to make visible (1-based)

Text Access

text
const char*
Gets or sets the text for a line.
line
int
required
Line number (1-based)
Returns pointer to the line’s text.
data
void*
Gets or sets the user data pointer for a line.
line
int
required
Line number (1-based)
Returns the data pointer associated with the line.

Formatting

format_char
char
Gets or sets the format code prefix character (default ’@’).
column_char
char
Gets or sets the column separator character (default ‘\t’).
column_widths
const int*
Gets or sets the array of column widths in pixels. The array must be zero-terminated.

Format Codes

When format_char() is ’@’, you can use these codes at the start of each line:
  • @. - Print rest of line, don’t look for more ’@’ signs
  • @@ - Print ’@’ character
  • @l - Use large (24 point) font
  • @m - Use medium large (18 point) font
  • @s - Use small (11 point) font
  • @b - Use bold font
  • @i - Use italic font
  • @f or @t - Use fixed-pitch font
  • @c - Center the line
  • @r - Right-justify the text
  • @B### - Fill background with color ###
  • @C### - Use color ### for text
  • @u or @_ - Underline the text

Example

#include <FL/Fl_Select_Browser.H>
#include <FL/Fl_Double_Window.H>

Fl_Select_Browser *browser;

void browser_callback(Fl_Widget *w, void *) {
  Fl_Browser *b = (Fl_Browser*)w;
  printf("Selected line: %d\n", b->value());
}

int main() {
  Fl_Double_Window *win = new Fl_Double_Window(400, 300);
  browser = new Fl_Select_Browser(10, 10, 380, 280);
  browser->type(FL_MULTI_BROWSER);
  browser->callback(browser_callback);
  
  // Add some items
  browser->add("@bBold text");
  browser->add("@iItalic text");
  browser->add("Normal text");
  browser->add("@C1Red text");
  
  // Or load from file
  browser->load("/path/to/file.txt");
  
  win->end();
  win->show();
  return Fl::run();
}

Common Patterns

Iterating Through All Items

for (int i = 1; i <= browser->size(); i++) {
  printf("Line %d: %s\n", i, browser->text(i));
}

Using Columns

static int widths[] = { 50, 50, 70, 0 };  // Zero-terminated
browser->column_widths(widths);
browser->column_char('\t');
browser->add("Name\tAge\tCity");
browser->add("John\t25\tNew York");

See Also