Files
Basalt2/docs/references/elements/Menu.md
2025-11-05 15:20:58 +00:00

2.2 KiB

Menu

This is the menu class. It provides a horizontal menu bar with selectable items. Menu items are displayed in a single row and can have custom colors and callbacks.

Extends: List

Properties

Property Type Default Description
separatorColor color gray The color used for separator items in the menu
spacing number 0 The number of spaces between menu items
openDropdown table nil Currently open dropdown data {index, items, x, y, width, height}
dropdownBackground color black Background color for dropdown menus
dropdownForeground color white Foreground color for dropdown menus
horizontalOffset number 0 Current horizontal scroll offset
maxWidth number nil Maximum width before scrolling is enabled (nil = auto-size to items)

Functions

Method Returns Description
Menu:getTotalWidth number Calculates total width of menu items
Menu:showDropdown - Shows dropdown menu
Menu:hideDropdown - Closes dropdown menu
Menu:isInsideDropdown boolean Checks if position is in dropdown
Menu:handleDropdownClick boolean Handles dropdown click

Menu:getTotalWidth()

Calculates the total width of all menu items with spacing

Returns

  • number totalWidth The total width of all items

Menu:showDropdown(index, item, itemX)

Shows a dropdown menu for a specific item

Parameters

  • index number The item index
  • item table The menu item
  • itemX number The X position of the item

Menu:hideDropdown()

Closes the currently open dropdown

Menu:isInsideDropdown(relX, relY, dropdown)

Checks if a position is inside the dropdown

Parameters

  • relX number Relative X position
  • relY number Relative Y position
  • dropdown table Dropdown data

Returns

  • boolean inside Whether position is inside dropdown

Menu:handleDropdownClick(relX, relY, dropdown)

Handles click inside dropdown

Parameters

  • relX number Relative X position
  • relY number Relative Y position
  • dropdown table Dropdown data

Returns

  • boolean handled Whether click was handled