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.
Fl_Button
TheFl_Button widget generates callbacks when clicked by the user. It supports various button types including normal, toggle, and radio buttons, and can respond to keyboard shortcuts.
Header File
Class Overview
Fl_Button is a clickable widget that triggers callbacks in response to user interaction. Buttons can:
- Generate callbacks on mouse clicks
- Respond to keyboard shortcuts (explicit or from label)
- Toggle between states (normal, toggle, radio button modes)
- Display custom down states with different box types and colors
Inheritance
Fl_Widget
Button Types
Thetype() method controls button behavior:
FL_NORMAL_BUTTON(0) - Standard push button,value()is 1 during press, 0 when releasedFL_TOGGLE_BUTTON(1) - Toggle button,value()toggles between 0 and 1 on each clickFL_RADIO_BUTTON- Radio button, sets this button to 1 and others in the group to 0FL_HIDDEN_BUTTON(3) - For Forms compatibility
Constructor
The X coordinate of the button relative to the enclosing window
The Y coordinate of the button relative to the enclosing window
Width of the button in pixels
Height of the button in pixels
Label text for the button. Use ’&’ before a character to create a keyboard shortcut
Public Methods
value()
New value to set (0 or 1)
set()
value(1). Sets the button to the “on” state.
Returns: int - Always returns 1
clear()
value(0). Sets the button to the “off” state.
Returns: int - Always returns 0
setonly()
FL_RADIO_BUTTON types.
shortcut()
Bitwise OR of a key and shift flags (e.g.,
FL_ALT | 'a', FL_CTRL | 'x', or just 'a')Setting a shortcut overrides the use of ’&’ in the label. Use lowercase letters unless you require the shift key to be held down.
down_box()
value() is non-zero.
The box type to use for the “down” state. A value of 0 (default) causes FLTK to figure out the correct matching down version of
box()down_color()
selection_color() (provided for backwards compatibility).
Color value for the down state
compact()
0 to disable compact mode, 1 to enable it
handle()
The FLTK event type
int - 1 if handled, 0 otherwise
Protected Methods
draw()
Callback Behavior
Thewhen() method controls when callbacks are triggered:
0- Callback not done, onlychanged()flag is setFL_WHEN_RELEASE(default) - Callback when button is released or shortcut typedFL_WHEN_CHANGED- Callback each timevalue()changesFL_WHEN_NOT_CHANGED- Callback when released but value didn’t change
Usage Example
Fromtest/button.cxx:
Toggle Button Example
See Also
- Fl_Widget - Base widget class
- Fl_Return_Button - Button with default return key binding
- Fl_Light_Button - Button with indicator light
- Fl_Check_Button - Checkbox button
- Fl_Radio_Button - Radio button with circle indicator