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.

TabContainer

繼承: Container < Control < CanvasItem < Node < Object

會為每個子控制項建立一個分頁的容器,只會顯示活動分頁對應的控制項。

說明

以分頁視圖排列子控制項,為每個子控制項建立一個分頁。活動分頁對應的控制項可見,其他子控制項都會被隱藏。非控制項子節點會被忽略。

注意:可點擊的分頁是由這個節點負責繪製的;不需要 TabBar

教學

屬性

bool

all_tabs_in_front

bool

clip_tabs

true

int

current_tab

-1

bool

deselect_enabled

false

bool

drag_to_rearrange_enabled

false

bool

switch_on_drag_hover

true

AlignmentMode

tab_alignment

0

FocusMode

tab_focus_mode

2

bool

tab_{index}/disabled

false

bool

tab_{index}/hidden

false

Texture2D

tab_{index}/icon

String

tab_{index}/title

""

TabPosition

tabs_position

0

int

tabs_rearrange_group

-1

bool

tabs_visible

true

bool

use_hidden_tabs_for_min_size

false

方法

Control

get_current_tab_control() const

Popup

get_popup() const

int

get_previous_tab() const

TabBar

get_tab_bar() const

Texture2D

get_tab_button_icon(tab_idx: int) const

Control

get_tab_control(tab_idx: int) const

int

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

int

get_tab_idx_from_control(control: Control) const

Variant

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

bool

select_next_available()

bool

select_previous_available()

void

set_popup(popup: Node)

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_metadata(tab_idx: int, metadata: Variant)

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

icon_max_width

0

int

icon_separation

4

int

outline_size

0

int

side_margin

8

int

tab_separation

0

Font

font

int

font_size

Texture2D

decrement

Texture2D

decrement_highlight

Texture2D

drop_mark

Texture2D

increment

Texture2D

increment_highlight

Texture2D

menu

Texture2D

menu_highlight

StyleBox

panel

StyleBox

tab_disabled

StyleBox

tab_focus

StyleBox

tab_hovered

StyleBox

tab_selected

StyleBox

tab_unselected

StyleBox

tabbar_background


訊號

active_tab_rearranged(idx_to: int) 🔗

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


pre_popup_pressed() 🔗

按一下 TabContainerPopup 按鈕時發出。有關詳細資訊,請參閱 set_popup()


tab_button_pressed(tab: int) 🔗

使用者點擊該分頁上的按鈕圖示時發出。


tab_changed(tab: int) 🔗

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


tab_clicked(tab: int) 🔗

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


tab_hovered(tab: int) 🔗

當滑鼠懸停分頁時發出。


tab_selected(tab: int) 🔗

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


列舉

enum TabPosition: 🔗

TabPosition POSITION_TOP = 0

Places the tab bar at the top.

TabPosition POSITION_BOTTOM = 1

Places the tab bar at the bottom. The tab bar's StyleBox will be flipped vertically.

TabPosition POSITION_MAX = 2

Represents the size of the TabPosition enum.


屬性說明

bool all_tabs_in_front 🔗

  • void set_all_tabs_in_front(value: bool)

  • bool is_all_tabs_in_front()

已棄用: Due to internal changes this doesn't do anything anymore, as they're always in front.

This doesn't do anything.


bool clip_tabs = true 🔗

  • void set_clip_tabs(value: bool)

  • bool get_clip_tabs()

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


int current_tab = -1 🔗

  • void set_current_tab(value: int)

  • int get_current_tab()

The current tab index. When set, this index's Control node's visible property is set to true and all others are set to false.

A value of -1 means that no tab is selected.


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.

Only the tab header will be shown if no tabs are selected.


bool drag_to_rearrange_enabled = false 🔗

  • void set_drag_to_rearrange_enabled(value: bool)

  • bool get_drag_to_rearrange_enabled()

如果為 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.


AlignmentMode tab_alignment = 0 🔗

The position at which tabs will be placed.


FocusMode tab_focus_mode = 2 🔗

該介面的遊玩區域模式。


bool tab_{index}/disabled = false 🔗

If true, the tab at index is disabled.

Note: index is a value in the 0 .. get_tab_count() - 1 range.


bool tab_{index}/hidden = false 🔗

If true, the tab at index is hidden.

Note: index is a value in the 0 .. get_tab_count() - 1 range.


Texture2D tab_{index}/icon 🔗

The title text of the tab at index.

Note: index is a value in the 0 .. get_tab_count() - 1 range.


String tab_{index}/title = "" 🔗

The tooltip text of the tab at index.

Note: index is a value in the 0 .. get_tab_count() - 1 range.


TabPosition tabs_position = 0 🔗

The horizontal alignment of the tabs.


int tabs_rearrange_group = -1 🔗

  • void set_tabs_rearrange_group(value: int)

  • int get_tabs_rearrange_group()

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

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


bool tabs_visible = true 🔗

  • void set_tabs_visible(value: bool)

  • bool are_tabs_visible()

如果為 true,分頁可見。如果 false,分頁的內容和標題被隱藏。


bool use_hidden_tabs_for_min_size = false 🔗

  • void set_use_hidden_tabs_for_min_size(value: bool)

  • bool get_use_hidden_tabs_for_min_size()

If true, child Control nodes that are hidden have their minimum size take into account in the total, instead of only the currently visible one.


方法說明

Control get_current_tab_control() const 🔗

返回位於活動分頁索引處的子 Control 節點。


Popup get_popup() const 🔗

如果已經使用 set_popup() 設定了 Popup 節點實例,則返回該節點實例。

警告:這是一個必需的內部節點,移除和釋放它可能會導致當機。如果希望隱藏它或它的任何子項,請使用它們的 Window.visible 屬性。


int get_previous_tab() const 🔗

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


TabBar get_tab_bar() const 🔗

返回這個按鈕中包含的 PopupMenu

警告:這是一個必需的內部節點,移除和釋放它可能會導致當機。如果你想隱藏它或它的任何子節點,請使用其 Window.visible 屬性。


Texture2D get_tab_button_icon(tab_idx: int) const 🔗

返回索引為 tab_idx 的分頁的按鈕圖示。


Control get_tab_control(tab_idx: int) const 🔗

返回索引為 tab_idx 的分頁的 Control 節點。


int get_tab_count() const 🔗

返回分頁的數量。


Texture2D get_tab_icon(tab_idx: int) const 🔗

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


int get_tab_icon_max_width(tab_idx: int) const 🔗

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


int get_tab_idx_at_point(point: Vector2) const 🔗

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


int get_tab_idx_from_control(control: Control) const 🔗

返回與給定的 control 綁定的標籤的索引。該控制項必須為 TabContainer 的子節點。


Variant get_tab_metadata(tab_idx: int) const 🔗

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


String get_tab_title(tab_idx: int) const 🔗

返回索引 tab_idx 處分頁的標題。分頁的標題預設為索引子節點的名稱,但可以用 set_tab_title() 覆蓋。


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


bool select_next_available() 🔗

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


bool select_previous_available() 🔗

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


void set_popup(popup: Node) 🔗

如果在一個 Popup 節點實例上設定,則一個彈出功能表圖示會出現在該 TabContainer 的右上角(將其設定為 null 將使其消失)。點擊它將展開該 Popup 節點。


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

設定索引為 tab_idx 的分頁的按鈕圖示。


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_metadata(tab_idx: int, metadata: Variant) 🔗

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


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

為索引 tab_idx 處的分頁設定自訂標題(分頁標題預設為索引子節點的名稱)。將其設定回孩子的名字,使分頁再次預設為該名字。


void set_tab_tooltip(tab_idx: int, tooltip: String) 🔗

Sets a custom tooltip text 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 icon_max_width = 0 🔗

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


int icon_separation = 4 🔗

分頁名稱與其圖示之間的間距。


int outline_size = 0 🔗

分頁文字輪廓的大小。

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


int side_margin = 8 🔗

標籤欄左側或右側邊緣的間距,取決於目前的 tab_alignment

如果標籤頁被裁剪(見 clip_tabs)或者設定了彈出框(見 set_popup()),則會忽略 TabBar.ALIGNMENT_RIGHT 的邊距。使用 TabBar.ALIGNMENT_CENTER 時始終忽略邊距。


int tab_separation = 0 🔗

The space between tabs in the tab bar.


Font font 🔗

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


int font_size 🔗

分頁名稱的字形大小。


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 🔗

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


Texture2D menu 🔗

功能表按鈕的圖示(見 set_popup())。


Texture2D menu_highlight 🔗

當游標懸停時功能表按鈕的圖示(見 set_popup())。


StyleBox panel 🔗

背景填充的樣式。


StyleBox tab_disabled 🔗

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


StyleBox tab_focus 🔗

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


StyleBox tab_hovered 🔗

目前懸停的分頁的樣式。不會套用於選中的分頁。


StyleBox tab_selected 🔗

目前選中的分頁的樣式。


StyleBox tab_unselected 🔗

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


StyleBox tabbar_background 🔗

TabBar 區域的背景填充樣式。