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)
License
BSD-3-ClauseCopyright
Copyright © 2025 DDN (D Developer Network) Members
Types 5
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;ChoicePtr _choiceHandleint add(string text)Adds an item to the dropdown menu.void clear()Clears all items from the menu.void selectedIndex(int index)Sets the currently selected item by index.void value(int index)this(int x, int y, int width, int height, string label = null)Creates a new choice widget.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");MenuBarPtr _menuBarHandleint add(string path, int shortcut = 0, int flags = 0)Adds a menu item.void clear()Clears all menu items.this(int x, int y, int width, int height, string label = null)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");SysMenuBarPtr _sysMenuBarHandleint 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.this(int x, int y, int width, int height, string label = null)Creates a new system menu bar widget.~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");MenuButtonPtr _menuButtonHandleint add(string path, int shortcut = 0, int flags = 0)Adds a menu item.void clear()Clears all menu items.this(int x, int y, int width, int height, string label = null)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";InputChoicePtr _inputChoiceHandlevoid 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.this(int x, int y, int width, int height, string label = null)