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.

FLTK provides comprehensive text input widgets for capturing user text input, with built-in support for editing, selection, undo/redo, and clipboard operations.

Fl_Input

Header: FL/Fl_Input.H The standard single-line text input widget. Displays and edits a single line of text with full UTF-8 support.

Constructor

Fl_Input(int x, int y, int w, int h, const char *label = 0);

Key Methods

Access the text content of the input field.
const char* value() const;     // Get current text
int value(const char *text);   // Set text
int value(const char *text, int len);  // Set with length

Fl_Input *input = new Fl_Input(50, 50, 200, 30, "Name:");
input->value("John Doe");
printf("Entered: %s\n", input->value());
Programmatically modify text content.
input->insert("text");          // Insert at cursor
input->replace(0, 5, "new");    // Replace range
input->cut();                   // Cut selection
input->copy();                  // Copy to clipboard
input->paste();                 // Paste from clipboard
Get or set the text cursor position.
int position() const;           // Get cursor position
int position(int p);            // Set cursor position
int position(int p, int m);     // Set position and mark

input->position(0);             // Move to start
input->position(input->size()); // Move to end
Get the length of the text.
int size() const;  // Returns number of bytes (not characters for UTF-8)

if (input->size() > 0) {
  printf("Has text\n");
}
Set maximum number of characters allowed.
void maximum_size(int m);
int maximum_size() const;

input->maximum_size(50);  // Limit to 50 characters
Make the input field read-only.
void readonly(int b);
int readonly() const;

input->readonly(1);  // User cannot edit
input->color(FL_BACKGROUND2_COLOR);  // Visual feedback

Keyboard Bindings

Fl_Input supports standard text editing keys:
ActionWindows/LinuxmacOS
Select AllCtrl+ACmd+A
CopyCtrl+CCmd+C
PasteCtrl+VCmd+V
CutCtrl+XCmd+X
UndoCtrl+ZCmd+Z
Move to startHomeCmd+Left
Move to endEndCmd+Right
Word leftCtrl+LeftAlt+Left
Word rightCtrl+RightAlt+Right

Example

#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Input.H>
#include <FL/Fl_Button.H>
#include <stdio.h>

void submit_cb(Fl_Widget *, void *v) {
  Fl_Input *input = (Fl_Input*)v;
  printf("Submitted: %s\n", input->value());
}

int main() {
  Fl_Window *win = new Fl_Window(400, 150);
  
  Fl_Input *name = new Fl_Input(100, 30, 250, 30, "Name:");
  name->value("Enter your name");
  
  Fl_Button *btn = new Fl_Button(150, 80, 100, 30, "Submit");
  btn->callback(submit_cb, name);
  
  win->end();
  win->show();
  return Fl::run();
}

Specialized Input Types

FLTK provides specialized input widgets for specific data types:

Fl_Int_Input

Header: FL/Fl_Int_Input.H Accepts only integer input (digits and minus sign).
Fl_Int_Input *qty = new Fl_Int_Input(100, 50, 100, 30, "Quantity:");
qty->value("42");

int quantity = atoi(qty->value());

Fl_Float_Input

Header: FL/Fl_Float_Input.H Accepts floating-point numbers (digits, decimal point, minus, and ‘e’ for scientific notation).
Fl_Float_Input *price = new Fl_Float_Input(100, 50, 100, 30, "Price:");
price->value("19.99");

double amount = atof(price->value());

Fl_Secret_Input

Header: FL/Fl_Secret_Input.H Displays asterisks (****) instead of actual characters. Perfect for password fields.
Fl_Secret_Input *pwd = new Fl_Secret_Input(100, 50, 200, 30, "Password:");
pwd->maximum_size(32);

Fl_Multiline_Input

Header: FL/Fl_Multiline_Input.H Multi-line text input with scrolling.
Fl_Multiline_Input *notes = new Fl_Multiline_Input(50, 50, 300, 150, "Notes:");
notes->align(FL_ALIGN_TOP_LEFT);

Standard Input

Fl_Input - Single-line textWhite rectangular field with thin border. Displays text cursor when focused.Use for: Names, titles, search boxes, single-line data

Integer Input

Fl_Int_Input - Numbers onlyIdentical appearance to Fl_Input but rejects non-digit input.Use for: Quantities, ages, counts, IDs

Float Input

Fl_Float_Input - Decimal numbersAccepts numbers with decimal points and scientific notation.Use for: Prices, measurements, percentages

Secret Input

Fl_Secret_Input - Hidden charactersDisplays asterisks or dots instead of typed characters.Use for: Passwords, PINs, sensitive data

Common Patterns

Login Form

Fl_Window *login = new Fl_Window(300, 180, "Login");

Fl_Input *username = new Fl_Input(120, 30, 150, 30, "Username:");
username->maximum_size(50);

Fl_Secret_Input *password = new Fl_Secret_Input(120, 70, 150, 30, "Password:");
password->maximum_size(32);

Fl_Return_Button *login_btn = new Fl_Return_Button(100, 120, 100, 30, "Login");
login_btn->callback([](Fl_Widget *, void *v) {
  auto *data = (std::pair<Fl_Input*, Fl_Secret_Input*>*)v;
  printf("Login: %s / %s\n", data->first->value(), data->second->value());
}, new std::pair(username, password));

login->end();

Numeric Input with Validation

void validate_number(Fl_Widget *w, void *) {
  Fl_Input *input = (Fl_Input*)w;
  const char *text = input->value();
  
  // Simple validation
  for (int i = 0; text[i]; i++) {
    if (!isdigit(text[i]) && text[i] != '.') {
      fl_beep();
      input->value("");  // Clear invalid input
      return;
    }
  }
}

Fl_Input *amount = new Fl_Input(100, 50, 150, 30, "Amount:");
amount->when(FL_WHEN_CHANGED);
amount->callback(validate_number);

Input with Default Text

Fl_Input *search = new Fl_Input(50, 20, 300, 30);
search->value("Search...");
search->color(FL_BACKGROUND2_COLOR);

// Clear default text on first focus
void focus_cb(Fl_Widget *w, void *) {
  Fl_Input *inp = (Fl_Input*)w;
  static bool first = true;
  if (first && strcmp(inp->value(), "Search...") == 0) {
    inp->value("");
    inp->color(FL_WHITE);
    first = false;
  }
}

search->callback(focus_cb);
search->when(FL_WHEN_CHANGED);

Multi-line Text Area

Fl_Window *win = new Fl_Window(400, 300);

Fl_Multiline_Input *editor = new Fl_Multiline_Input(10, 40, 380, 200, "Comments:");
editor->align(FL_ALIGN_TOP_LEFT);
editor->textfont(FL_COURIER);
editor->textsize(14);
editor->wrap(1);  // Word wrap

Fl_Button *save = new Fl_Button(150, 250, 100, 30, "Save");
save->callback([](Fl_Widget *, void *v) {
  Fl_Multiline_Input *text = (Fl_Multiline_Input*)v;
  save_to_file(text->value());
}, editor);

win->end();

Input Styling

Fl_Input *input = new Fl_Input(50, 50, 250, 35);

// Colors
input->color(FL_WHITE);           // Background
input->textcolor(FL_BLACK);       // Text color
input->selection_color(FL_BLUE);  // Selection highlight
input->cursor_color(FL_RED);      // Cursor color

// Typography
input->textfont(FL_COURIER);
input->textsize(16);

// Border
input->box(FL_DOWN_BOX);

Callbacks and Events

Fl_Input *input = new Fl_Input(50, 50, 200, 30);

// Callback on Enter key
input->when(FL_WHEN_ENTER_KEY);
input->callback([](Fl_Widget *w, void *) {
  Fl_Input *inp = (Fl_Input*)w;
  printf("Enter pressed: %s\n", inp->value());
});

// Callback on every change
input->when(FL_WHEN_CHANGED);
input->callback([](Fl_Widget *w, void *) {
  Fl_Input *inp = (Fl_Input*)w;
  printf("Changed to: %s\n", inp->value());
});

// Callback when focus is lost
input->when(FL_WHEN_RELEASE);

Important Notes

The value() method returns a pointer to internal buffer that may become invalid after widget modification. Copy the string if you need to keep it.
Fl_Input fully supports UTF-8 text encoding. Use size() to get byte count, not character count.
Use readonly(1) instead of deactivate() if you want text to be copyable but not editable. Deactivated widgets appear grayed out.

Reference

  • Source: FL/Fl_Input.H (lines 220-271)
  • Source: FL/Fl_Int_Input.H
  • Source: FL/Fl_Float_Input.H
  • Source: FL/Fl_Secret_Input.H
  • Source: FL/Fl_Multiline_Input.H