Attention: Here be dragons

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

TabBar

繼承: Control < CanvasItem < Node < Object

提供水平分頁欄的控制項。

說明

提供水平分頁欄的控制項。類似於 TabContainer,但只負責繪製分頁,不與子節點互動。

屬性

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 (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

bool

tab_{index}/disabled

false

Texture2D

tab_{index}/icon

String

tab_{index}/title

""

String

tab_{index}/tooltip

""

int

tabs_rearrange_group

-1

方法

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)

主題屬性

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)

Color

icon_disabled_color

Color(1, 1, 1, 1)

Color

icon_hovered_color

Color(1, 1, 1, 1)

Color

icon_selected_color

Color(1, 1, 1, 1)

Color

icon_unselected_color

Color(1, 1, 1, 1)

int

h_separation

4

int

hover_switch_wait_msec

500

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


訊號

active_tab_rearranged(idx_to: int) 🔗

通過滑鼠拖動重新排列活動分頁時發出。見 drag_to_rearrange_enabled


tab_button_pressed(tab: int) 🔗

分頁的右側按鈕被按下時發出。見 set_tab_button_icon()


tab_changed(tab: int) 🔗

切換到另一個分頁時發出。


tab_clicked(tab: int) 🔗

按一下分頁時發出,即使它是目前分頁。


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:

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

tab_hovered(tab: int) 🔗

當滑鼠懸停分頁時發出。


tab_rmb_clicked(tab: int) 🔗

Emitted when a tab is right-clicked.


tab_selected(tab: int) 🔗

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


列舉

enum AlignmentMode: 🔗

AlignmentMode ALIGNMENT_LEFT = 0

Aligns tabs to the left.

AlignmentMode ALIGNMENT_CENTER = 1

Aligns tabs in the middle.

AlignmentMode ALIGNMENT_RIGHT = 2

Aligns tabs to the right.

AlignmentMode ALIGNMENT_MAX = 3

代表 AlignmentMode 列舉的大小。


enum CloseButtonDisplayPolicy: 🔗

CloseButtonDisplayPolicy CLOSE_BUTTON_SHOW_NEVER = 0

永遠不會顯示關閉按鈕。

CloseButtonDisplayPolicy CLOSE_BUTTON_SHOW_ACTIVE_ONLY = 1

僅在目前活動分頁上顯示關閉按鈕。

CloseButtonDisplayPolicy CLOSE_BUTTON_SHOW_ALWAYS = 2

在所有分頁上顯示關閉按鈕。

CloseButtonDisplayPolicy CLOSE_BUTTON_MAX = 3

代表 CloseButtonDisplayPolicy 列舉的大小。


屬性說明

bool clip_tabs = true 🔗

  • void set_clip_tabs(value: bool)

  • bool get_clip_tabs()

如果為 true,則會隱藏超出該節點寬度的分頁,改為顯示兩個導覽按鈕。否則,會更新該節點的最小尺寸,讓所有分頁均可見。


bool close_with_middle_mouse = true 🔗

  • void set_close_with_middle_mouse(value: bool)

  • bool get_close_with_middle_mouse()

If true, middle-clicking on a tab will emit the tab_close_pressed signal.


int current_tab = -1 🔗

  • void set_current_tab(value: int)

  • int get_current_tab()

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.


bool deselect_enabled = false 🔗

  • void set_deselect_enabled(value: bool)

  • bool get_deselect_enabled()

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


bool drag_to_rearrange_enabled = false 🔗

  • void set_drag_to_rearrange_enabled(value: bool)

  • bool get_drag_to_rearrange_enabled()

如果為 true,可以通過滑鼠拖動重新排列分頁。


int max_tab_width = 0 🔗

  • void set_max_tab_width(value: int)

  • int get_max_tab_width()

設定所有分頁應被限制的最大寬度。如果設定為 0,則無限制。


bool scroll_to_selected = true 🔗

  • void set_scroll_to_selected(value: bool)

  • bool get_scroll_to_selected()

如果為 true,則會更改分頁偏移量,從而保持目前選中的分頁可見。


bool scrolling_enabled = true 🔗

  • void set_scrolling_enabled(value: bool)

  • bool get_scrolling_enabled()

如果為 true,滑鼠的滾輪可用於導覽滾動視圖。


bool select_with_rmb = false 🔗

  • void set_select_with_rmb(value: bool)

  • bool get_select_with_rmb()

如果為 true,啟用滑鼠右鍵選擇分頁。


bool switch_on_drag_hover = true 🔗

  • void set_switch_on_drag_hover(value: bool)

  • bool get_switch_on_drag_hover()

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.


AlignmentMode tab_alignment = 0 🔗

The horizontal alignment of the tabs.


CloseButtonDisplayPolicy tab_close_display_policy = 0 🔗

When the close button will appear on the tabs.


int tab_count = 0 🔗

  • void set_tab_count(value: int)

  • int get_tab_count()

分頁欄中目前的分頁數量。


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.


Texture2D tab_{index}/icon 🔗

If true, the tab at index is hidden.

Note: index is a value in the 0 .. tab_count - 1 range.


String tab_{index}/title = "" 🔗

The title text of the tab at index.

Note: index is a value in the 0 .. tab_count - 1 range.


String tab_{index}/tooltip = "" 🔗

The tooltip text of the tab at index.

Note: index is a value in the 0 .. tab_count - 1 range.


int tabs_rearrange_group = -1 🔗

  • void set_tabs_rearrange_group(value: int)

  • int get_tabs_rearrange_group()

具有相同重新排列組 ID 的 TabBar 將允許在它們之間拖動分頁。使用 drag_to_rearrange_enabled 啟用拖動。

將該屬性設定為 -1 將禁用 TabBar 之間的重新排列。


方法說明

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

新增新分頁。


void clear_tabs() 🔗

清空所有分頁。


void ensure_tab_visible(idx: int) 🔗

移動滾動視圖,使標籤可見。


bool get_offset_buttons_visible() const 🔗

如果偏移按鈕(所有分頁沒有足夠空間時出現的按鈕)可見,則返回 true


int get_previous_tab() const 🔗

返回上一個活動分頁的索引。


Texture2D get_tab_button_icon(tab_idx: int) const 🔗

返回索引 tab_idx 處分頁右側按鈕的圖示,如果該按鈕沒有圖示,則返回 null


Texture2D get_tab_icon(tab_idx: int) const 🔗

返回索引 tab_idx 處分頁的圖示,如果該分頁沒有圖示,則返回 null


int get_tab_icon_max_width(tab_idx: int) const 🔗

設定索引為 tab_idx 處分頁所允許的最大圖示寬度。


int get_tab_idx_at_point(point: Vector2) const 🔗

返回位於局部座標 point 處的分頁的索引。如果該點在控制項邊界之外或查詢位置沒有分頁,則返回 -1


String get_tab_language(tab_idx: int) const 🔗

返回分頁標題的語言程式碼。


Variant get_tab_metadata(tab_idx: int) const 🔗

返回索引為 tab_idx 的分頁的中繼資料的值,由 set_tab_metadata() 設定。如果之前沒有設定中繼資料,則預設返回 null


int get_tab_offset() const 🔗

返回向左偏移的隱藏分頁的數量。


Rect2 get_tab_rect(tab_idx: int) const 🔗

返回帶有局部位置和大小的分頁 Rect2


TextDirection get_tab_text_direction(tab_idx: int) const 🔗

返回分頁標題文字的基礎書寫方向。


String get_tab_title(tab_idx: int) const 🔗

返回索引 tab_idx 處的分頁的標題。


String get_tab_tooltip(tab_idx: int) const 🔗

Returns the tooltip text of the tab at index tab_idx.


bool is_tab_disabled(tab_idx: int) const 🔗

如果索引 tab_idx 處的分頁被禁用,則返回 true


bool is_tab_hidden(tab_idx: int) const 🔗

如果索引 tab_idx 處的分頁被隱藏,則返回 true


void move_tab(from: int, to: int) 🔗

將分頁從 from 移動到 to


void remove_tab(tab_idx: int) 🔗

刪除索引 tab_idx 處的分頁。


bool select_next_available() 🔗

返回目前焦點專案的索引。如果沒有焦點,則返回 -1


bool select_previous_available() 🔗

返回目前焦點專案的索引。如果沒有焦點,則返回 -1


void set_tab_button_icon(tab_idx: int, icon: Texture2D) 🔗

設定索引為 tab_idx 的分頁按鈕的圖示 icon(位於右側,在關閉按鈕之前),會將該按鈕設為可見且可點擊(見 tab_button_pressed)。給定 null 值會隱藏該按鈕。


void set_tab_disabled(tab_idx: int, disabled: bool) 🔗

如果 disabledtrue,則禁用索引 tab_idx 處的選項卡,使其不可互動。


void set_tab_hidden(tab_idx: int, hidden: bool) 🔗

如果 hiddentrue,則隱藏索引 tab_idx 處的選項卡,使其從分頁區域消失。


void set_tab_icon(tab_idx: int, icon: Texture2D) 🔗

設定索引 tab_idx 處的分頁的圖示。


void set_tab_icon_max_width(tab_idx: int, width: int) 🔗

設定索引為 tab_idx 處分頁所允許的最大圖示寬度。這是在圖示的預設大小和 icon_max_width 的基礎上的限制。高度會根據圖示的長寬比調整。


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.


void set_tab_metadata(tab_idx: int, metadata: Variant) 🔗

tab_idx 的分頁設定中繼資料的值,之後可以使用 get_tab_metadata() 獲取。


void set_tab_text_direction(tab_idx: int, direction: TextDirection) 🔗

設定分頁標題的基礎書寫方向。


void set_tab_title(tab_idx: int, title: String) 🔗

設定索引 tab_idx 處的分頁的標題 title


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.


主題屬性說明

Color drop_mark_color = Color(1, 1, 1, 1) 🔗

drop_mark 圖示的調變顏色。


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) 🔗

其他未被選中的分頁的字形顏色。


Color icon_disabled_color = Color(1, 1, 1, 1) 🔗

Icon color of disabled tabs.


Color icon_hovered_color = Color(1, 1, 1, 1) 🔗

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


Color icon_selected_color = Color(1, 1, 1, 1) 🔗

Icon color of the currently selected tab.


Color icon_unselected_color = Color(1, 1, 1, 1) 🔗

Icon color of the other, unselected tabs.


int h_separation = 4 🔗

分頁內元素之間的水平分隔。


int hover_switch_wait_msec = 500 🔗

During a drag-and-drop, this is how many milliseconds to wait before switching the tab.


int icon_max_width = 0 🔗

分頁圖示所允許的最大寬度。這個限制套用在該圖示預設大小之上,但是套用在 set_tab_icon_max_width() 所設定的值之前。高度會根據圖示比例調整。


int outline_size = 0 🔗

分頁文字輪廓的大小。

注意:如果使用啟用了 FontFile.multichannel_signed_distance_field 的字形,其 FontFile.msdf_pixel_range 必須至少設定為 outline_size兩倍,輪廓算繪才能看起來正確。否則,輪廓可能會比預期的更早被切斷。


int tab_separation = 0 🔗

The space between tabs in the tab bar.


Font font 🔗

用於繪製分頁名稱的字形。


int font_size 🔗

分頁名稱的字形大小。


Texture2D close 🔗

關閉按鈕的圖示(見 tab_close_display_policy)。


Texture2D decrement 🔗

左邊的箭頭按鈕的圖示,當有太多的標籤無法容納在容器的寬度內時出現。當該按鈕被禁用時(即第一個標籤是可見的),它顯示為半透明的。


Texture2D decrement_highlight 🔗

當標籤太多無法適應容器寬度時出現的左箭頭按鈕圖示。當滑鼠懸停在按鈕上時使用。


Texture2D drop_mark 🔗

Icon shown to indicate where a dragged tab will be dropped (see drag_to_rearrange_enabled).


Texture2D increment 🔗

右箭頭按鈕的圖示,當有太多的標籤無法容納在容器的寬度內時出現。當該按鈕被禁用時(即最後一個標籤是可見的),它顯示為半透明的。


Texture2D increment_highlight 🔗

當標籤太多無法適應容器寬度時出現的右箭頭按鈕圖示。當滑鼠懸停在按鈕上時使用。


StyleBox button_highlight 🔗

分頁和關閉按鈕的背景,處於滑鼠懸停狀態時使用。


StyleBox button_pressed 🔗

分頁和關閉按鈕的背景,處於按下狀態時使用。


StyleBox tab_disabled 🔗

分頁處於禁用狀態時的樣式。


StyleBox tab_focus 🔗

Button 處於聚焦狀態時使用的 StyleBoxfocus StyleBox 顯示在基礎 StyleBox 之上,所以應該使用部分透明的 StyleBox,確保基礎 StyleBox 仍然可見。代表輪廓或底線的 StyleBox 可以很好地實作這個目的。要禁用聚焦的視覺效果,請指定 StyleBoxEmpty 資源。請注意,禁用聚焦的視覺效果會影響使用鍵盤/手柄進行導覽的可用性,所以出於可存取性的原因,不建議這樣做。


StyleBox tab_hovered 🔗

目前懸停分頁的樣式。不適用於所選分頁。

注意:此樣式將至少以與tab_unselected相同的寬度繪製。


StyleBox tab_selected 🔗

目前選中的分頁的樣式。


StyleBox tab_unselected 🔗

其他未被選中的分頁的樣式。