Up to date

This page is up to date for Godot 4.0. If you still find outdated information, please open an issue.

MenuBar

Inherits: Control < CanvasItem < Node < Object

A horizontal menu bar that creates a MenuButton for each PopupMenu child.

Description

A horizontal menu bar that creates a MenuButton for each PopupMenu child. New items are created by adding PopupMenus to this node.

Properties

bool

flat

false

String

language

“”

bool

prefer_global_menu

true

int

start_index

-1

bool

switch_on_hover

true

TextDirection

text_direction

0

Methods

int

get_menu_count ( ) const

PopupMenu

get_menu_popup ( int menu ) const

String

get_menu_title ( int menu ) const

String

get_menu_tooltip ( int menu ) const

bool

is_menu_disabled ( int menu ) const

bool

is_menu_hidden ( int menu ) const

bool

is_native_menu ( ) const

void

set_disable_shortcuts ( bool disabled )

void

set_menu_disabled ( int menu, bool disabled )

void

set_menu_hidden ( int menu, bool hidden )

void

set_menu_title ( int menu, String title )

void

set_menu_tooltip ( int menu, String tooltip )

Theme Properties

Color

font_color

Color(0.875, 0.875, 0.875, 1)

Color

font_disabled_color

Color(0.875, 0.875, 0.875, 0.5)

Color

font_focus_color

Color(0.95, 0.95, 0.95, 1)

Color

font_hover_color

Color(0.95, 0.95, 0.95, 1)

Color

font_hover_pressed_color

Color(1, 1, 1, 1)

Color

font_outline_color

Color(1, 1, 1, 1)

Color

font_pressed_color

Color(1, 1, 1, 1)

int

h_separation

4

int

outline_size

0

Font

font

int

font_size

StyleBox

disabled

StyleBox

focus

StyleBox

hover

StyleBox

normal

StyleBox

pressed


Property Descriptions

bool flat = false

  • void set_flat ( bool value )

  • bool is_flat ( )

Flat MenuBar don’t display item decoration.


String language = ""

  • void set_language ( String value )

  • String get_language ( )

Language code used for line-breaking and text shaping algorithms, if left empty current locale is used instead.


bool prefer_global_menu = true

  • void set_prefer_global_menu ( bool value )

  • bool is_prefer_global_menu ( )

If true, MenuBar will use system global menu when supported.


int start_index = -1

  • void set_start_index ( int value )

  • int get_start_index ( )

Position in the global menu to insert first MenuBar item at.


bool switch_on_hover = true

  • void set_switch_on_hover ( bool value )

  • bool is_switch_on_hover ( )

If true, when the cursor hovers above menu item, it will close the current PopupMenu and open the other one.


TextDirection text_direction = 0

Base text writing direction.


Method Descriptions

int get_menu_count ( ) const

Returns number of menu items.


PopupMenu get_menu_popup ( int menu ) const

Returns PopupMenu associated with menu item.


String get_menu_title ( int menu ) const

Returns menu item title.


String get_menu_tooltip ( int menu ) const

Returns menu item tooltip.


bool is_menu_disabled ( int menu ) const

Returns true, if menu item is disabled.


bool is_menu_hidden ( int menu ) const

Returns true, if menu item is hidden.


bool is_native_menu ( ) const

Returns true, if system global menu is supported and used by this MenuBar.


void set_disable_shortcuts ( bool disabled )

If true, shortcuts are disabled and cannot be used to trigger the button.


void set_menu_disabled ( int menu, bool disabled )

If true, menu item is disabled.


void set_menu_hidden ( int menu, bool hidden )

If true, menu item is hidden.


void set_menu_title ( int menu, String title )

Sets menu item title.


void set_menu_tooltip ( int menu, String tooltip )

Sets menu item tooltip.


Theme Property Descriptions

Color font_color = Color(0.875, 0.875, 0.875, 1)

Default text Color of the menu item.


Color font_disabled_color = Color(0.875, 0.875, 0.875, 0.5)

Text Color used when the menu item is disabled.


Color font_focus_color = Color(0.95, 0.95, 0.95, 1)

Text Color used when the menu item is focused. Only replaces the normal text color of the menu item. Disabled, hovered, and pressed states take precedence over this color.


Color font_hover_color = Color(0.95, 0.95, 0.95, 1)

Text Color used when the menu item is being hovered.


Color font_hover_pressed_color = Color(1, 1, 1, 1)

Text Color used when the menu item is being hovered and pressed.


Color font_outline_color = Color(1, 1, 1, 1)

The tint of text outline of the menu item.


Color font_pressed_color = Color(1, 1, 1, 1)

Text Color used when the menu item is being pressed.


int h_separation = 4

The horizontal space between menu items.


int outline_size = 0

The size of the text outline.

Note: If using a font with FontFile.multichannel_signed_distance_field enabled, its FontFile.msdf_pixel_range must be set to at least twice the value of outline_size for outline rendering to look correct. Otherwise, the outline may appear to be cut off earlier than intended.


Font font

Font of the menu item’s text.


int font_size

Font size of the menu item’s text.


StyleBox disabled

StyleBox used when the menu item is disabled.


StyleBox focus

StyleBox used when the menu item is focused. The focus StyleBox is displayed over the base StyleBox, so a partially transparent StyleBox should be used to ensure the base StyleBox remains visible. A StyleBox that represents an outline or an underline works well for this purpose. To disable the focus visual effect, assign a StyleBoxEmpty resource. Note that disabling the focus visual effect will harm keyboard/controller navigation usability, so this is not recommended for accessibility reasons.


StyleBox hover

StyleBox used when the menu item is being hovered.


StyleBox normal

Default StyleBox for the menu item.


StyleBox pressed

StyleBox used when the menu item is being pressed.