fltk.menu

FLTK Menu Widgets

This module provides menu-related widgets:

  • Choice: Dropdown menu for selecting from options
  • MenuBar: Horizontal menu bar with dropdown menus
  • MenuButton: Button that shows popup menu when clicked
  • InputChoice: Combo box (input field + dropdown menu)

    Authors

    Dejan Lekić

    License

    BSD-3-Clause

Types 5

classChoice : Widget

Dropdown menu widget for selecting from options.

Choice displays a dropdown menu with selectable items. Only one item can be selected at a time.

Example:

auto choice = new Choice(10, 10, 150, 25, "Color:");
choice.add("Red");
choice.add("Green");
choice.add("Blue");
choice.selectedIndex = 0;
auto selected = choice.selectedText;

Fields
ChoicePtr _choiceHandle
Methods
ChoicePtr choiceHandle() @safe nothrow @nogc
int add(string text)Adds an item to the dropdown menu.
void clear()Clears all items from the menu.
int selectedIndex() constGets the currently selected item index.
void selectedIndex(int index)Sets the currently selected item by index.
string selectedText() constGets the text of the currently selected item.
int value() constAlias for selectedIndex
void value(int index)
Constructors
this(int x, int y, int width, int height, string label = null)Creates a new choice widget.
Destructors

Menu bar widget.

MenuBar provides a horizontal menu bar typically placed at the top of a window, with dropdown menus.

Example:

auto menubar = new MenuBar(0, 0, 400, 25);
menubar.add("File/New");
menubar.add("File/Open");
menubar.add("File/Quit");
menubar.add("Edit/Copy");
menubar.add("Edit/Paste");

Fields
MenuBarPtr _menuBarHandle
Methods
MenuBarPtr menuBarHandle() @safe nothrow @nogc
int add(string path, int shortcut = 0, int flags = 0)Adds a menu item.
void clear()Clears all menu items.
Constructors
this(int x, int y, int width, int height, string label = null)
Destructors

System menu bar widget.

SysMenuBar is a menu bar that integrates with the operating system's native menu system. On macOS, menus appear in the system menu bar at the top of the screen. On other platforms (Linux, Windows), it behaves like a regular MenuBar widget.

This class is useful for creating cross-platform applications that should use the native menu bar on macOS while still working on other platforms.

Example:

auto menubar = new SysMenuBar(0, 0, 400, 25);
menubar.add("File/New");
menubar.add("File/Open");
menubar.add("File/Quit");
menubar.add("Edit/Copy");
menubar.add("Edit/Paste");

Fields
SysMenuBarPtr _sysMenuBarHandle
Methods
SysMenuBarPtr sysMenuBarHandle() @safe nothrow @nogcReturns the underlying system menu bar handle.
int add(string path, int shortcut = 0, int flags = 0)Adds a menu item.
int insert(int index, string label, int shortcut = 0, int flags = 0)Inserts a menu item at a specific index.
void remove(int index)Removes a menu item.
void replace(int index, string name)Replaces the label of a menu item.
void clear()Clears all menu items.
int clearSubmenu(int index)Clears a submenu.
void update()Updates the system menu bar to reflect any changes. On macOS, this syncs changes to the system menu. On other platforms, this is typically a no-op.
int mode(int index)Gets the flags of a menu item.
void setMode(int index, int flags)Sets the flags of a menu item.
void shortcut(int index, int shortcut)Sets the shortcut of a menu item.
Constructors
this(int x, int y, int width, int height, string label = null)Creates a new system menu bar widget.
Destructors
~thisDestroys the system menu bar and releases resources.

Menu button widget.

MenuButton shows a popup menu when clicked.

Example:

auto menu = new MenuButton(10, 10, 100, 25, "Options");
menu.add("Option 1");
menu.add("Option 2");
menu.add("Option 3");

Fields
MenuButtonPtr _menuButtonHandle
Methods
MenuButtonPtr menuButtonHandle() @safe nothrow @nogc
int add(string path, int shortcut = 0, int flags = 0)Adds a menu item.
void clear()Clears all menu items.
Constructors
this(int x, int y, int width, int height, string label = null)
Destructors

Input choice widget (combo box).

InputChoice combines a text input field with a dropdown menu, allowing users to either type a value or select from predefined options.

Example:

auto combo = new InputChoice(10, 10, 150, 25, "Color:");
combo.add("Red");
combo.add("Green");
combo.add("Blue");
combo.value = "Custom";

Fields
InputChoicePtr _inputChoiceHandle
Methods
InputChoicePtr inputChoiceHandle() @safe nothrow @nogc
string value() constGets the current text value.
void value(string text)Sets the current text value.
void add(string text)Adds an item to the dropdown menu.
void clear()Clears all menu items.
Constructors
this(int x, int y, int width, int height, string label = null)
Destructors