Attention: Here be dragons

This is thelatest (unstable) version of this documentation, which may document features not available in or compatible with released stable versions of Godot.

Checking the stable version of the documentation...

TabBar

Inherits:Control<CanvasItem<Node<Object

A control that provides a horizontal bar with tabs.

Description

A control that provides a horizontal bar with tabs. Similar toTabContainer but is only in charge of drawing tabs, not interacting with children.

Properties

bool

clip_tabs

true

bool

close_with_middle_mouse

true

int

current_tab

-1

bool

deselect_enabled

false

bool

drag_to_rearrange_enabled

false

FocusMode

focus_mode

2 (overridesControl)

int

max_tab_width

0

bool

scroll_to_selected

true

bool

scrolling_enabled

true

bool

select_with_rmb

false

AlignmentMode

tab_alignment

0

CloseButtonDisplayPolicy

tab_close_display_policy

0

int

tab_count

0

int

tabs_rearrange_group

-1

Methods

void

add_tab(title:String = "", icon:Texture2D = null)

void

clear_tabs()

void

ensure_tab_visible(idx:int)

bool

get_offset_buttons_visible()const

int

get_previous_tab()const

Texture2D

get_tab_button_icon(tab_idx:int)const

Texture2D

get_tab_icon(tab_idx:int)const

int

get_tab_icon_max_width(tab_idx:int)const

int

get_tab_idx_at_point(point:Vector2)const

String

get_tab_language(tab_idx:int)const

Variant

get_tab_metadata(tab_idx:int)const

int

get_tab_offset()const

Rect2

get_tab_rect(tab_idx:int)const

TextDirection

get_tab_text_direction(tab_idx:int)const

String

get_tab_title(tab_idx:int)const

String

get_tab_tooltip(tab_idx:int)const

bool

is_tab_disabled(tab_idx:int)const

bool

is_tab_hidden(tab_idx:int)const

void

move_tab(from:int, to:int)

void

remove_tab(tab_idx:int)

bool

select_next_available()

bool

select_previous_available()

void

set_tab_button_icon(tab_idx:int, icon:Texture2D)

void

set_tab_disabled(tab_idx:int, disabled:bool)

void

set_tab_hidden(tab_idx:int, hidden:bool)

void

set_tab_icon(tab_idx:int, icon:Texture2D)

void

set_tab_icon_max_width(tab_idx:int, width:int)

void

set_tab_language(tab_idx:int, language:String)

void

set_tab_metadata(tab_idx:int, metadata:Variant)

void

set_tab_text_direction(tab_idx:int, direction:TextDirection)

void

set_tab_title(tab_idx:int, title:String)

void

set_tab_tooltip(tab_idx:int, tooltip:String)

Theme Properties

Color

drop_mark_color

Color(1,1,1,1)

Color

font_disabled_color

Color(0.875,0.875,0.875,0.5)

Color

font_hovered_color

Color(0.95,0.95,0.95,1)

Color

font_outline_color

Color(0,0,0,1)

Color

font_selected_color

Color(0.95,0.95,0.95,1)

Color

font_unselected_color

Color(0.7,0.7,0.7,1)

int

h_separation

4

int

icon_max_width

0

int

outline_size

0

int

tab_separation

0

Font

font

int

font_size

Texture2D

close

Texture2D

decrement

Texture2D

decrement_highlight

Texture2D

drop_mark

Texture2D

increment

Texture2D

increment_highlight

StyleBox

button_highlight

StyleBox

button_pressed

StyleBox

tab_disabled

StyleBox

tab_focus

StyleBox

tab_hovered

StyleBox

tab_selected

StyleBox

tab_unselected


Signals

active_tab_rearranged(idx_to:int)🔗

Emitted when the active tab is rearranged via mouse drag. Seedrag_to_rearrange_enabled.


tab_button_pressed(tab:int)🔗

Emitted when a tab's right button is pressed. Seeset_tab_button_icon().


tab_changed(tab:int)🔗

Emitted when switching to another tab.


tab_clicked(tab:int)🔗

Emitted when a tab is clicked, even if it is the current tab.


tab_close_pressed(tab:int)🔗

Emitted when a tab's close button is pressed or when middle-clicking on a tab, ifclose_with_middle_mouse is enabled.

Note: Tabs are not removed automatically once the close button is pressed, this behavior needs to be programmed manually. For example:

$TabBar.tab_close_pressed.connect($TabBar.remove_tab)

tab_hovered(tab:int)🔗

Emitted when a tab is hovered by the mouse.


tab_rmb_clicked(tab:int)🔗

Emitted when a tab is right-clicked.select_with_rmb must be enabled.


tab_selected(tab:int)🔗

Emitted when a tab is selected via click, directional input, or script, even if it is the current tab.


Enumerations

enumAlignmentMode:🔗

AlignmentModeALIGNMENT_LEFT =0

Places tabs to the left.

AlignmentModeALIGNMENT_CENTER =1

Places tabs in the middle.

AlignmentModeALIGNMENT_RIGHT =2

Places tabs to the right.

AlignmentModeALIGNMENT_MAX =3

Represents the size of theAlignmentMode enum.


enumCloseButtonDisplayPolicy:🔗

CloseButtonDisplayPolicyCLOSE_BUTTON_SHOW_NEVER =0

Never show the close buttons.

CloseButtonDisplayPolicyCLOSE_BUTTON_SHOW_ACTIVE_ONLY =1

Only show the close button on the currently active tab.

CloseButtonDisplayPolicyCLOSE_BUTTON_SHOW_ALWAYS =2

Show the close button on all tabs.

CloseButtonDisplayPolicyCLOSE_BUTTON_MAX =3

Represents the size of theCloseButtonDisplayPolicy enum.


Property Descriptions

boolclip_tabs =true🔗

Iftrue, tabs overflowing this node's width will be hidden, displaying two navigation buttons instead. Otherwise, this node's minimum size is updated so that all tabs are visible.


boolclose_with_middle_mouse =true🔗

Iftrue, middle clicking on the mouse will fire thetab_close_pressed signal.


intcurrent_tab =-1🔗

The index of the current selected tab. A value of-1 means that no tab is selected and can only be set whendeselect_enabled istrue or if all tabs are hidden or disabled.


booldeselect_enabled =false🔗

Iftrue, all tabs can be deselected so that no tab is selected. Click on the current tab to deselect it.


booldrag_to_rearrange_enabled =false🔗

Iftrue, tabs can be rearranged with mouse drag.


intmax_tab_width =0🔗

Sets the maximum width which all tabs should be limited to. Unlimited if set to0.


boolscroll_to_selected =true🔗

Iftrue, the tab offset will be changed to keep the currently selected tab visible.


boolscrolling_enabled =true🔗

iftrue, the mouse's scroll wheel can be used to navigate the scroll view.


boolselect_with_rmb =false🔗

Iftrue, enables selecting a tab with the right mouse button.


AlignmentModetab_alignment =0🔗

The position at which tabs will be placed.


CloseButtonDisplayPolicytab_close_display_policy =0🔗

When the close button will appear on the tabs.


inttab_count =0🔗

The number of tabs currently in the bar.


inttabs_rearrange_group =-1🔗

TabBars with the same rearrange group ID will allow dragging the tabs between them. Enable drag withdrag_to_rearrange_enabled.

Setting this to-1 will disable rearranging betweenTabBars.


Method Descriptions

voidadd_tab(title:String = "", icon:Texture2D = null)🔗

Adds a new tab.


voidclear_tabs()🔗

Clears all tabs.


voidensure_tab_visible(idx:int)🔗

Moves the scroll view to make the tab visible.


boolget_offset_buttons_visible()const🔗

Returnstrue if the offset buttons (the ones that appear when there's not enough space for all tabs) are visible.


intget_previous_tab()const🔗

Returns the previously active tab index.


Texture2Dget_tab_button_icon(tab_idx:int)const🔗

Returns the icon for the right button of the tab at indextab_idx ornull if the right button has no icon.


Texture2Dget_tab_icon(tab_idx:int)const🔗

Returns the icon for the tab at indextab_idx ornull if the tab has no icon.


intget_tab_icon_max_width(tab_idx:int)const🔗

Returns the maximum allowed width of the icon for the tab at indextab_idx.


intget_tab_idx_at_point(point:Vector2)const🔗

Returns the index of the tab at local coordinatespoint. Returns-1 if the point is outside the control boundaries or if there's no tab at the queried position.


Stringget_tab_language(tab_idx:int)const🔗

Returns tab title language code.


Variantget_tab_metadata(tab_idx:int)const🔗

Returns the metadata value set to the tab at indextab_idx usingset_tab_metadata(). If no metadata was previously set, returnsnull by default.


intget_tab_offset()const🔗

Returns the number of hidden tabs offsetted to the left.


Rect2get_tab_rect(tab_idx:int)const🔗

Returns tabRect2 with local position and size.


TextDirectionget_tab_text_direction(tab_idx:int)const🔗

Returns tab title text base writing direction.


Stringget_tab_title(tab_idx:int)const🔗

Returns the title of the tab at indextab_idx.


Stringget_tab_tooltip(tab_idx:int)const🔗

Returns the tooltip text of the tab at indextab_idx.


boolis_tab_disabled(tab_idx:int)const🔗

Returnstrue if the tab at indextab_idx is disabled.


boolis_tab_hidden(tab_idx:int)const🔗

Returnstrue if the tab at indextab_idx is hidden.


voidmove_tab(from:int, to:int)🔗

Moves a tab fromfrom toto.


voidremove_tab(tab_idx:int)🔗

Removes the tab at indextab_idx.


boolselect_next_available()🔗

Selects the first available tab with greater index than the currently selected. Returnstrue if tab selection changed.


boolselect_previous_available()🔗

Selects the first available tab with lower index than the currently selected. Returnstrue if tab selection changed.


voidset_tab_button_icon(tab_idx:int, icon:Texture2D)🔗

Sets anicon for the button of the tab at indextab_idx (located to the right, before the close button), making it visible and clickable (Seetab_button_pressed). Giving it anull value will hide the button.


voidset_tab_disabled(tab_idx:int, disabled:bool)🔗

Ifdisabled istrue, disables the tab at indextab_idx, making it non-interactable.


voidset_tab_hidden(tab_idx:int, hidden:bool)🔗

Ifhidden istrue, hides the tab at indextab_idx, making it disappear from the tab area.


voidset_tab_icon(tab_idx:int, icon:Texture2D)🔗

Sets anicon for the tab at indextab_idx.


voidset_tab_icon_max_width(tab_idx:int, width:int)🔗

Sets the maximum allowed width of the icon for the tab at indextab_idx. This limit is applied on top of the default size of the icon and on top oficon_max_width. The height is adjusted according to the icon's ratio.


voidset_tab_language(tab_idx:int, language:String)🔗

Sets language code of tab title used for line-breaking and text shaping algorithms, if left empty current locale is used instead.


voidset_tab_metadata(tab_idx:int, metadata:Variant)🔗

Sets the metadata value for the tab at indextab_idx, which can be retrieved later usingget_tab_metadata().


voidset_tab_text_direction(tab_idx:int, direction:TextDirection)🔗

Sets tab title base writing direction.


voidset_tab_title(tab_idx:int, title:String)🔗

Sets atitle for the tab at indextab_idx.


voidset_tab_tooltip(tab_idx:int, tooltip:String)🔗

Sets atooltip for tab at indextab_idx.

Note: By default, if thetooltip is empty and the tab text is truncated (not all characters fit into the tab), the title will be displayed as a tooltip. To hide the tooltip, assign"" as thetooltip text.


Theme Property Descriptions

Colordrop_mark_color =Color(1,1,1,1)🔗

Modulation color for thedrop_mark icon.


Colorfont_disabled_color =Color(0.875,0.875,0.875,0.5)🔗

Font color of disabled tabs.


Colorfont_hovered_color =Color(0.95,0.95,0.95,1)🔗

Font color of the currently hovered tab. Does not apply to the selected tab.


Colorfont_outline_color =Color(0,0,0,1)🔗

The tint of text outline of the tab name.


Colorfont_selected_color =Color(0.95,0.95,0.95,1)🔗

Font color of the currently selected tab.


Colorfont_unselected_color =Color(0.7,0.7,0.7,1)🔗

Font color of the other, unselected tabs.


inth_separation =4🔗

The horizontal separation between the elements inside tabs.


inticon_max_width =0🔗

The maximum allowed width of the tab's icon. This limit is applied on top of the default size of the icon, but before the value set withset_tab_icon_max_width(). The height is adjusted according to the icon's ratio.


intoutline_size =0🔗

The size of the tab text outline.

Note: If using a font withFontFile.multichannel_signed_distance_field enabled, itsFontFile.msdf_pixel_range must be set to at leasttwice the value ofoutline_size for outline rendering to look correct. Otherwise, the outline may appear to be cut off earlier than intended.


inttab_separation =0🔗

The space between tabs in the tab bar.


Fontfont🔗

The font used to draw tab names.


intfont_size🔗

Font size of the tab names.


Texture2Dclose🔗

The icon for the close button (seetab_close_display_policy).


Texture2Ddecrement🔗

Icon for the left arrow button that appears when there are too many tabs to fit in the container width. When the button is disabled (i.e. the first tab is visible), it appears semi-transparent.


Texture2Ddecrement_highlight🔗

Icon for the left arrow button that appears when there are too many tabs to fit in the container width. Used when the button is being hovered with the cursor.


Texture2Ddrop_mark🔗

Icon shown to indicate where a dragged tab is gonna be dropped (seedrag_to_rearrange_enabled).


Texture2Dincrement🔗

Icon for the right arrow button that appears when there are too many tabs to fit in the container width. When the button is disabled (i.e. the last tab is visible) it appears semi-transparent.


Texture2Dincrement_highlight🔗

Icon for the right arrow button that appears when there are too many tabs to fit in the container width. Used when the button is being hovered with the cursor.


StyleBoxbutton_highlight🔗

Background of the tab and close buttons when they're being hovered with the cursor.


StyleBoxbutton_pressed🔗

Background of the tab and close buttons when it's being pressed.


StyleBoxtab_disabled🔗

The style of disabled tabs.


StyleBoxtab_focus🔗

StyleBox used when theTabBar is focused. Thetab_focusStyleBox is displayedover the baseStyleBox of the selected tab, so a partially transparentStyleBox should be used to ensure the baseStyleBox remains visible. AStyleBox that represents an outline or an underline works well for this purpose. To disable the focus visual effect, assign aStyleBoxEmpty resource. Note that disabling the focus visual effect will harm keyboard/controller navigation usability, so this is not recommended for accessibility reasons.


StyleBoxtab_hovered🔗

The style of the currently hovered tab. Does not apply to the selected tab.

Note: This style will be drawn with the same width astab_unselected at minimum.


StyleBoxtab_selected🔗

The style of the currently selected tab.


StyleBoxtab_unselected🔗

The style of the other, unselected tabs.


User-contributed notes

Please read theUser-contributed notes policy before submitting a comment.