TabBar
Inherits: Control < CanvasItem < Entity < Object
Description
Section titled “Description”A control that provides a horizontal bar with tabs.
A control that provides a horizontal bar with tabs. Similar to TabContainer but is only in charge of drawing tabs, not interacting with children.
Properties
Section titled “Properties”| Type | Name | Default |
|---|---|---|
| bool | clip_tabs |
true |
| bool | close_with_middle_mouse |
true |
| int | current_tab |
-1 |
| bool | deselect_enabled |
false |
| bool | drag_to_rearrange_enabled |
false |
| Control.FocusMode | focus_mode |
2 (overrides Control) |
| int | max_tab_width |
0 |
| bool | scroll_to_selected |
true |
| bool | scrolling_enabled |
true |
| bool | select_with_rmb |
false |
| bool | switch_on_drag_hover |
true |
| AlignmentMode | tab_alignment |
0 |
| CloseButtonDisplayPolicy | tab_close_display_policy |
0 |
| int | tab_count |
0 |
| SizingMode | tab_sizing |
0 |
| bool | tab_{index}/disabled |
false |
| Texture2D | tab_{index}/icon |
|
| String | tab_{index}/title |
"" |
| String | tab_{index}/tooltip |
"" |
| int | tabs_rearrange_group |
-1 |
Methods
Section titled “Methods”Signals
Section titled “Signals”active_tab_rearranged
active_tab_rearranged(idx_to: int)
Emitted when the active tab is rearranged via mouse drag. See drag_to_rearrange_enabled.
tab_button_pressed
tab_button_pressed(tab: int)
Emitted when a tab’s right button is pressed. See set_tab_button_icon().
tab_changed
tab_changed(tab: int)
Emitted when switching to another tab.
tab_clicked
tab_clicked(tab: int)
Emitted when a tab is clicked, even if it is the current tab.
tab_close_pressed
tab_close_pressed(tab: int)
Emitted when a tab’s close button is pressed or, if close_with_middle_mouse is true, when middle-clicking on a tab.
Note: Tabs are not removed automatically; this behavior needs to be coded manually. For example:
GetEntity<TabBar>("TabBar").TabClosePressed += GetEntity<TabBar>("TabBar").RemoveTab;tab_hovered
tab_hovered(tab: int)
Emitted when a tab is hovered by the mouse.
tab_rmb_clicked
tab_rmb_clicked(tab: int)
Emitted when a tab is right-clicked.
tab_selected
tab_selected(tab: int)
Emitted when a tab is selected via click, directional input, or script, even if it is the current tab.
Enumerations
Section titled “Enumerations”AlignmentMode
enum AlignmentMode
ALIGNMENT_LEFT = 0
Aligns tabs to the left.
ALIGNMENT_CENTER = 1
Aligns tabs in the middle.
ALIGNMENT_RIGHT = 2
Aligns tabs to the right.
ALIGNMENT_MAX = 3
Represents the size of the AlignmentMode enum.
SizingMode
enum SizingMode
TAB_SIZING_FIT_CONTENT = 0
Size tabs individually according to the size of their content.
TAB_SIZING_UNIFORM = 1
Size tabs uniformly, with the widest tab determining the size of all tabs. This may trigger clipping sooner than other sizing modes due to increased tab sizes.
TAB_SIZING_JUSTIFY = 2
Size tabs individually according to their content, expanding to the full width of the tab bar.
TAB_SIZING_EXPAND = 3
Size tabs equally, expanding to the full width of the tab bar if there is room, otherwise fall back to TAB_SIZING_FIT_CONTENT.
TAB_SIZING_MAX = 4
Represents the size of the SizingMode enum.
CloseButtonDisplayPolicy
enum CloseButtonDisplayPolicy
CLOSE_BUTTON_SHOW_NEVER = 0
Never show the close buttons.
CLOSE_BUTTON_SHOW_ACTIVE_ONLY = 1
Only show the close button on the currently active tab.
CLOSE_BUTTON_SHOW_ALWAYS = 2
Show the close button on all tabs.
CLOSE_BUTTON_MAX = 3
Represents the size of the CloseButtonDisplayPolicy enum.
Theme items
Section titled “Theme items”drop_mark_color
Color drop_mark_color (color) = Color(1, 1, 1, 1)
font_disabled_color
Color font_disabled_color (color) = Color(0.875, 0.875, 0.875, 0.5)
font_hovered_color
Color font_hovered_color (color) = Color(0.95, 0.95, 0.95, 1)
font_outline_color
Color font_outline_color (color) = Color(0, 0, 0, 1)
font_selected_color
Color font_selected_color (color) = Color(0.95, 0.95, 0.95, 1)
font_unselected_color
Color font_unselected_color (color) = Color(0.7, 0.7, 0.7, 1)
icon_disabled_color
Color icon_disabled_color (color) = Color(1, 1, 1, 1)
icon_hovered_color
Color icon_hovered_color (color) = Color(1, 1, 1, 1)
icon_selected_color
Color icon_selected_color (color) = Color(1, 1, 1, 1)
icon_unselected_color
Color icon_unselected_color (color) = Color(1, 1, 1, 1)
h_separation
int h_separation (constant) = 4
hover_switch_wait_msec
int hover_switch_wait_msec (constant) = 500
icon_max_width
int icon_max_width (constant) = 0
outline_size
int outline_size (constant) = 0
tab_separation
int tab_separation (constant) = 0
font
Font font (font)
font_size
int font_size (font_size)
close
Texture2D close (icon)
decrement
Texture2D decrement (icon)
decrement_highlight
Texture2D decrement_highlight (icon)
drop_mark
Texture2D drop_mark (icon)
increment
Texture2D increment (icon)
increment_highlight
Texture2D increment_highlight (icon)
drag_ended_sound
AudioStream drag_ended_sound (sound)
drag_started_sound
AudioStream drag_started_sound (sound)
focus_sound
AudioStream focus_sound (sound)
hover_sound
AudioStream hover_sound (sound)
pressed_disabled_sound
AudioStream pressed_disabled_sound (sound)
pressed_sound
AudioStream pressed_sound (sound)
button_highlight
StyleBox button_highlight (style)
button_pressed
StyleBox button_pressed (style)
tab_disabled
StyleBox tab_disabled (style)
tab_focus
StyleBox tab_focus (style)
tab_hovered
StyleBox tab_hovered (style)
tab_selected
StyleBox tab_selected (style)
tab_unselected
StyleBox tab_unselected (style)
Property descriptions
Section titled “Property descriptions”clip_tabs
bool clip_tabs = true
If true, 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.
close_with_middle_mouse
bool close_with_middle_mouse = true
If true, middle-clicking on a tab will emit the tab_close_pressed signal.
current_tab
int current_tab = -1
The index of the current selected tab. A value of -1 means that no tab is selected and can only be set when deselect_enabled is true or if all tabs are hidden or disabled.
deselect_enabled
bool deselect_enabled = false
If true, all tabs can be deselected so that no tab is selected. Click on the current tab to deselect it.
drag_to_rearrange_enabled
bool drag_to_rearrange_enabled = false
If true, tabs can be rearranged with mouse drag.
max_tab_width
int max_tab_width = 0
Sets the maximum width which all tabs should be limited to. Unlimited if set to 0.
scroll_to_selected
bool scroll_to_selected = true
If true, the tab offset will be changed to keep the currently selected tab visible.
scrolling_enabled
bool scrolling_enabled = true
if true, the mouse’s scroll wheel can be used to navigate the scroll view.
select_with_rmb
bool select_with_rmb = false
If true, enables selecting a tab with the right mouse button.
switch_on_drag_hover
bool switch_on_drag_hover = true
If true, hovering over a tab while dragging something will switch to that tab. Does not have effect when hovering another tab to rearrange. The delay for when this happens is dictated by hover_switch_wait_msec.
tab_alignment
AlignmentMode tab_alignment = 0
The horizontal alignment of the tabs.
tab_close_display_policy
CloseButtonDisplayPolicy tab_close_display_policy = 0
When the close button will appear on the tabs.
tab_count
int tab_count = 0
The number of tabs currently in the bar.
tab_sizing
SizingMode tab_sizing = 0
The sizing strategy used to determine tab widths.
tab_{index}/disabled
bool tab_{index}/disabled = false
If true, the tab at index is disabled.
Note: index is a value in the 0 .. tab_count - 1 range.
tab_{index}/icon
Texture2D tab_{index}/icon
If true, the tab at index is hidden.
Note: index is a value in the 0 .. tab_count - 1 range.
tab_{index}/title
String tab_{index}/title = ""
The title text of the tab at index.
Note: index is a value in the 0 .. tab_count - 1 range.
tab_{index}/tooltip
String tab_{index}/tooltip = ""
The tooltip text of the tab at index.
Note: index is a value in the 0 .. tab_count - 1 range.
tabs_rearrange_group
int tabs_rearrange_group = -1
TabBars with the same rearrange group ID will allow dragging the tabs between them. Enable drag with drag_to_rearrange_enabled.
Setting this to -1 will disable rearranging between TabBars.
Method descriptions
Section titled “Method descriptions”add_tab
void add_tab(title: String = "", icon: Texture2D = null)
Adds a new tab.
clear_tabs
void clear_tabs()
Clears all tabs.
ensure_tab_visible
void ensure_tab_visible(idx: int)
Moves the scroll view to make the tab visible.
get_offset_buttons_visible
bool get_offset_buttons_visible() const
Returns true if the offset buttons (the ones that appear when there’s not enough space for all tabs) are visible.
get_previous_tab
int get_previous_tab() const
Returns the previously active tab index.
get_tab_button_icon
Texture2D get_tab_button_icon(tab_idx: int) const
Returns the icon for the right button of the tab at index tab_idx or null if the right button has no icon.
get_tab_icon
Texture2D get_tab_icon(tab_idx: int) const
Returns the icon for the tab at index tab_idx or null if the tab has no icon.
get_tab_icon_max_width
int get_tab_icon_max_width(tab_idx: int) const
Returns the maximum allowed width of the icon for the tab at index tab_idx.
get_tab_idx_at_point
int get_tab_idx_at_point(point: Vector2) const
Returns the index of the tab at local coordinates point. Returns -1 if the point is outside the control boundaries or if there’s no tab at the queried position.
get_tab_language
String get_tab_language(tab_idx: int) const
Returns tab title language code.
get_tab_metadata
Variant get_tab_metadata(tab_idx: int) const
Returns the metadata value set to the tab at index tab_idx using set_tab_metadata(). If no metadata was previously set, returns null by default.
get_tab_offset
int get_tab_offset() const
Returns the number of hidden tabs offsetted to the left.
get_tab_rect
Rect2 get_tab_rect(tab_idx: int) const
Returns tab Rect2 with local position and size.
get_tab_text_direction
Control.TextDirection get_tab_text_direction(tab_idx: int) const
Returns tab title text base writing direction.
get_tab_title
String get_tab_title(tab_idx: int) const
Returns the title of the tab at index tab_idx.
get_tab_tooltip
String get_tab_tooltip(tab_idx: int) const
Returns the tooltip text of the tab at index tab_idx.
is_tab_disabled
bool is_tab_disabled(tab_idx: int) const
Returns true if the tab at index tab_idx is disabled.
is_tab_hidden
bool is_tab_hidden(tab_idx: int) const
Returns true if the tab at index tab_idx is hidden.
move_tab
void move_tab(from: int, to: int)
Moves a tab from from to to.
remove_tab
void remove_tab(tab_idx: int)
Removes the tab at index tab_idx.
select_next_available
bool select_next_available()
Selects the first available tab with greater index than the currently selected. Returns true if tab selection changed.
select_previous_available
bool select_previous_available()
Selects the first available tab with lower index than the currently selected. Returns true if tab selection changed.
set_tab_button_icon
void set_tab_button_icon(tab_idx: int, icon: Texture2D)
Sets an icon for the button of the tab at index tab_idx (located to the right, before the close button), making it visible and clickable (See tab_button_pressed). Giving it a null value will hide the button.
set_tab_disabled
void set_tab_disabled(tab_idx: int, disabled: bool)
If disabled is true, disables the tab at index tab_idx, making it non-interactable.
set_tab_hidden
void set_tab_hidden(tab_idx: int, hidden: bool)
If hidden is true, hides the tab at index tab_idx, making it disappear from the tab area.
set_tab_icon
void set_tab_icon(tab_idx: int, icon: Texture2D)
Sets an icon for the tab at index tab_idx.
set_tab_icon_max_width
void set_tab_icon_max_width(tab_idx: int, width: int)
Sets the maximum allowed width of the icon for the tab at index tab_idx. This limit is applied on top of the default size of the icon and on top of icon_max_width. The height is adjusted according to the icon’s ratio.
set_tab_language
void set_tab_language(tab_idx: int, language: String)
Sets the language code of the title for the tab at index tab_idx to language. This is used for line-breaking and text shaping algorithms. If language is empty, the current locale is used.
set_tab_metadata
void set_tab_metadata(tab_idx: int, metadata: Variant)
Sets the metadata value for the tab at index tab_idx, which can be retrieved later using get_tab_metadata().
set_tab_text_direction
void set_tab_text_direction(tab_idx: int, direction: Control.TextDirection)
Sets tab title base writing direction.
set_tab_title
void set_tab_title(tab_idx: int, title: String)
Sets a title for the tab at index tab_idx.
set_tab_tooltip
void set_tab_tooltip(tab_idx: int, tooltip: String)
Sets a tooltip for tab at index tab_idx.
Note: By default, if the tooltip 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 the tooltip text.
