Skip to content

Menu

A Menu is one self contained menu: a banner, a subtitle bar, a list of menu items, a description box and (optionally) instructional buttons.

Every menu has to be registered with the MenuController, which takes care of drawing it and of handling all controls for you. Menus can be nested: bind any menu to a MenuItem of another menu and that item becomes a submenu button.

All events (OnItemSelect, OnCheckboxChange, etc.) are members of this class. They are documented on their own page: Events.


using MenuAPI;
// Create a menu with a banner title and a subtitle.
Menu menu = new Menu("Main Menu", "Subtitle");
// Register the menu. The first menu you register automatically becomes
// MenuController.MainMenu, which is the menu that the toggle key opens.
MenuController.AddMenu(menu);
// Add some items to it.
menu.AddMenuItem(new MenuItem("Normal Button", "A simple button with a description."));
menu.AddMenuItem(new MenuCheckboxItem("Checkbox", "A checkbox.", true));
// Listen for button presses.
menu.OnItemSelect += (_menu, _item, _index) =>
{
Debug.WriteLine($"'{_item.Text}' was pressed (index {_index}).");
};
// Open the menu whenever you want.
menu.OpenMenu();
Menu menu = new Menu("Main Menu", "Subtitle");
MenuController.AddMenu(menu);
// A submenu is just another Menu. Use AddSubmenu instead of AddMenu so the
// parent/child relation is set up for you (this is what makes 'back' work).
Menu submenu = new Menu("Submenu", "Secondary Menu");
MenuController.AddSubmenu(menu, submenu);
// Create the item that opens the submenu, then bind the two together.
MenuItem submenuButton = new MenuItem("Open submenu", "This opens the submenu.")
{
RightIcon = MenuItem.Icon.ARROW_RIGHT
};
menu.AddMenuItem(submenuButton);
MenuController.BindMenuItem(menu, submenu, submenuButton);
// Pressing the back/cancel control in the submenu now returns to `menu`.
submenu.AddMenuItem(new MenuItem("I'm inside the submenu!"));


Creates a new menu with only a banner title.

Parameter Type Description
name string The text displayed on the menu banner. Pass null to create a menu without a banner.

Creates a new menu with a banner title and a subtitle.

Parameter Type Description
name string The text displayed on the menu banner. Pass null to create a menu without a banner.
subtitle string The text displayed in the subtitle bar, directly below the banner.
// With a banner and a subtitle.
Menu menu = new Menu("Main Menu", "Subtitle");
// With a banner only.
Menu menu2 = new Menu("Main Menu");
// Without a banner, only a subtitle.
Menu menu3 = new Menu(null, "Only a subtitle, no banner.");

Property Type Default value Description Optional
MenuTitle string - The text displayed on the menu banner. If this is null or empty, no banner is drawn. Yes
MenuSubtitle string Null The text displayed in the subtitle bar below the banner. Yes
HeaderTexture KeyValuePair<string, string> (empty) A custom banner image. The Key is the streamed texture dictionary, the Value is the texture name. The texture dictionary is requested for you. When this is not set, the default banner is used. Yes
CounterPreText string Null Text placed in front of the current / total counter in the top right of the subtitle bar. Setting this forces the counter to be shown, even when all items already fit on screen. Yes
Visible boolean false Whether this menu is currently being drawn. Prefer OpenMenu() and CloseMenu(), because those also trigger the open/close events (and enable/disable the UI prompts). Yes
EnableInstructionalButtons boolean true Whether the instructional buttons (UI prompts) for this menu are shown while the menu is open. Yes
IgnoreDontOpenMenus boolean false When true, this menu keeps being drawn even while MenuController.DontOpenAnyMenu is set to true. Yes
InstructionalButtons List<InstructionalButton> Select, Back, Up / Down The instructional buttons for this menu. See Instructional buttons. Yes
ButtonPressHandlers List<ButtonPressHandler> (empty) Custom control handlers that run while this menu is open. See Button press handlers. Yes
Size int 0 (Getter only) The number of items in this menu. When a filter is active, this is the number of items that passed the filter. Yes
CurrentIndex int 0 (Getter only) The index of the currently highlighted menu item. Use RefreshIndex() to change it. Yes
MaxItemsOnScreen int 10 (Getter only) How many items are visible on screen at a time. Use SetMaxItemsOnScreen() to change it. Yes
ViewIndexOffset int 0 (Getter only) The index of the first item that is currently visible on screen. Yes
ParentMenu Menu Null (Getter only) The parent of this menu, or null if it has none. Set by MenuController.AddSubmenu(). Yes
Position KeyValuePair<float, float> (0f, 20f) (Getter only) The current x/y position of the menu on screen. Yes
MenuItemsYOffset float 0f (Getter only) The y offset (in pixels) of the first menu item, relative to the top of the menu. Recalculated every frame. Yes

Constant Type Value Description
Width float 300f The width of a menu, in 1080p scaled pixels. (This is 500f in FiveM.)


Sets how many menu items are visible on screen at a time. The value is clamped between 3 and 10.

Parameter Type Description
max int A value between 3 and 10 (inclusive).

This function does not return anything.

// Only show 5 items at a time.
menu.SetMaxItemsOnScreen(5);

Resets the highlighted item back to the first item, and scrolls the menu back to the top.

This function does not have any parameters.

This function does not return anything.


Highlights the item at index and scrolls the menu so that item is visible.

Parameter Type Description
index int The index of the item to highlight.

This function does not return anything.


Highlights the item at index and scrolls the menu so that the item at viewOffset is the first item on screen. Use this when you want full control over the scroll position.

Parameter Type Description
index int The index of the item to highlight.
viewOffset int The index of the item that should be drawn at the top of the menu.

This function does not return anything.

// Rebuild the menu, but keep the user roughly where they were.
int index = menu.CurrentIndex;
int offset = menu.ViewIndexOffset;
menu.ClearMenuItems();
BuildItems(menu);
menu.RefreshIndex(index, offset);

Adds a menu item to the bottom of this menu, and sets that item’s ParentMenu to this menu.

Parameter Type Description
item MenuItem The item to add. Any item type can be used, since they all inherit MenuItem.

This function does not return anything.


Removes the item at the given index. The current index is corrected so the highlighted item does not jump around. Does nothing if the index is out of range.

Parameter Type Description
itemIndex int The index of the item to remove.

This function does not return anything.


Removes the given item from this menu. Does nothing if the item is not in this menu.

Parameter Type Description
item MenuItem The item to remove.

This function does not return anything.


Removes all menu items and resets the index and scroll position.

This function does not have any parameters.

This function does not return anything.


Removes all menu items, optionally keeping the current index and scroll position. Useful when you rebuild the contents of a menu while it is open.

Parameter Type Description
dontResetIndex boolean When true, the current index and scroll position are kept.

This function does not return anything.

// Rebuild the items without the menu jumping back to the top.
menu.ClearMenuItems(true);
BuildItems(menu);

Returns the items in this menu. When a filter is active, only the items that passed the filter are returned.

This function does not have any parameters.

Type Description
List<MenuItem> All (visible) menu items in this menu.
// Toggle the 'enabled' state of every item in the menu.
menu.GetMenuItems().ForEach(item => item.Enabled = !item.Enabled);

Returns the currently highlighted menu item.

This function does not have any parameters.

Type Description
MenuItem The currently highlighted item, or null if the menu is empty or the current index is out of range.

Selects the item at the given index, exactly as if the user had pressed the select control on it. Disabled items play the error sound instead, and submenu buttons open their submenu.

Parameter Type Description
index int The index of the item to select.

This function does not return anything.


Selects the given item, exactly as if the user had pressed the select control on it.

Parameter Type Description
item MenuItem The item to select.

This function does not return anything.


Makes this menu visible and triggers the OnMenuOpen event. This also prepares and enables the UI prompts for this menu’s instructional buttons.

This function does not have any parameters.

This function does not return anything.


Hides this menu, triggers the OnMenuClose event and disables this menu’s UI prompts.

This function does not have any parameters.

This function does not return anything.


Closes this menu and opens its parent menu. If there is no parent menu, the menu simply closes.

This function does not have any parameters.

This function does not return anything.


Moves the highlighted item up by one, wrapping around to the bottom of the list. Triggers the OnIndexChange event. Does nothing if the menu is not visible or has fewer than 2 items.

This function does not have any parameters.

This function does not return anything.


Moves the highlighted item down by one, wrapping around to the top of the list. Triggers the OnIndexChange event. Does nothing if the menu is not visible or has fewer than 2 items.

This function does not have any parameters.

This function does not return anything.


Moves the currently highlighted item to the left, if it supports that (list and dynamic list items). If the item does not support it and MenuController.NavigateMenuUsingArrows is enabled, this returns to the parent menu instead.

This function does not have any parameters.

This function does not return anything.


Moves the currently highlighted item to the right, if it supports that (list and dynamic list items).

This function does not have any parameters.

This function does not return anything.


SortMenuItems(Comparison<MenuItem> compare)

Section titled “SortMenuItems(Comparison<MenuItem> compare)”

Sorts the items in this menu using the provided compare function. Any active filter is cleared first.

Parameter Type Description
compare Comparison<MenuItem> The compare function used to sort the items.

This function does not return anything.

// Sort all items alphabetically by their text.
menu.SortMenuItems((a, b) => a.Text.ToLower().CompareTo(b.Text.ToLower()));

FilterMenuItems(Func<MenuItem, bool> predicate)

Section titled “FilterMenuItems(Func<MenuItem, bool> predicate)”

Hides every item for which the predicate returns false. The index and scroll position are reset. Only one filter can be active at a time; calling this again replaces the previous filter.

While a filter is active, Size and GetMenuItems() only report the items that passed the filter, but the hidden items are not removed from the menu.

Parameter Type Description
predicate Func<MenuItem, bool> Returns true for every item that should stay visible.

This function does not return anything.

// Only show items that are enabled.
menu.FilterMenuItems(item => item.Enabled);
// Or use ItemData to filter on your own data.
menu.FilterMenuItems(item => item.ItemData?.category == "horses");
// Show everything again.
menu.ResetFilter();

Clears the active filter, making all items visible again, and resets the index.

This function does not have any parameters.

This function does not return anything.


In RedM, instructional buttons are drawn as native UI prompts. Every menu has its own set, and by default that is select, back and up / down.

The prompts are registered and enabled when the menu is opened, and disabled again when it is closed. Set EnableInstructionalButtons to false before opening the menu if you want to handle prompts yourself.

// Add your own prompt.
menu.InstructionalButtons.Add(
new Menu.InstructionalButton(new Control[1] { Control.Reload }, "Reset")
);
// Add a prompt for a combination of controls.
menu.InstructionalButtons.Add(
new Menu.InstructionalButton(
new Control[2] { Control.FrontendLeft, Control.FrontendRight },
"Change value"
)
);
// Remove the default 'up / down' prompt.
Menu.InstructionalButton upDown = menu.InstructionalButtons
.Find(b => b.GetTextString() == "Up / Down");
upDown.Dispose();
menu.InstructionalButtons.Remove(upDown);
// Or turn them off entirely for this menu.
menu.EnableInstructionalButtons = false;
InstructionalButton(Control[] controls, string text)
Section titled “InstructionalButton(Control[] controls, string text)”

Creates a new prompt for one or more controls.

Parameter Type Description
controls Control[] The controls this prompt listens for. Pass more than one to show a combination.
text string The text displayed next to the prompt.
Property Type Description
IsPrepared boolean (Getter only) Whether the prompt has been registered with the game and is ready to be displayed.

Registers the prompt with the game. This is done for you when the menu is opened. Does nothing if the prompt is already prepared.

Shows/hides and enables/disables the prompt on screen. The prompt has to be prepared first.

Parameter Type Description
visible boolean Whether the prompt is visible.
enabled boolean Whether the prompt can be triggered.

Removes the prompt from the game. Prepare() has to be called again before the prompt can be used.

Returns the text of this prompt.

Type Description
string The prompt text.

Returns the controls of this prompt.

Type Description
Control[] The controls this prompt listens for.

Button press handlers let you run your own code when a control is pressed while this menu is open, without having to write your own tick function. They are only processed while the menu is open and while MenuController.DisableMenuButtons is false.

Parameter Type Description
control Control The control to listen for.
pressType ControlPressCheckType How the control should be checked.
function Action<Menu, Control> The function to run. It receives the menu and the control that triggered it.
disableControl boolean Whether the control should be disabled (blocking the game’s own action) while this menu is open.
Value Description
ControlPressCheckType.JUST_PRESSED Triggers once, on the frame the control is pressed down.
ControlPressCheckType.JUST_RELEASED Triggers once, on the frame the control is released.
ControlPressCheckType.PRESSED Triggers every frame while the control is held down.
ControlPressCheckType.RELEASED Triggers every frame while the control is not held down.
// Toggle the 'enabled' state of every item whenever this control is released.
menu.ButtonPressHandlers.Add(
new Menu.ButtonPressHandler(
Control.FrontendSocialClubSecondary,
Menu.ControlPressCheckType.JUST_RELEASED,
new Action<Menu, Control>((m, c) =>
{
m.GetMenuItems().ForEach(item => item.Enabled = !item.Enabled);
}),
true
)
);

These members are part of the FiveM build of MenuAPI and are not available (or have no effect) in RedM:

Member Notes
LeftAligned Right aligned menus are FiveM only, so this property does not exist in the RedM build.
CustomInstructionalButtons FiveM only. In RedM, add your own InstructionalButton to InstructionalButtons instead.
SetWeaponStats(), SetWeaponComponentStats() FiveM only. The weapon stats panel is not drawn in RedM.
SetVehicleStats(), SetVehicleUpgradeStats() FiveM only. The vehicle stats panel is not drawn in RedM.
ShowWeaponStatsPanel, ShowVehicleStatsPanel These properties exist in the RedM build, but setting them has no effect because the panels are never drawn.
WeaponStats, WeaponComponentStats, VehicleStats, VehicleUpgradeStats These properties exist in the RedM build, but always contain zeroes because there is no way to set them.

All menu events are documented on the Events page.