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.
Checking the stable version of the documentation...
TabContainer
繼承: Container < Control < CanvasItem < Node < Object
會為每個子控制項建立一個分頁的容器,只會顯示活動分頁對應的控制項。
說明
以分頁視圖排列子控制項,為每個子控制項建立一個分頁。活動分頁對應的控制項可見,其他子控制項都會被隱藏。非控制項子節點會被忽略。
注意:可點擊的分頁是由這個節點負責繪製的;不需要 TabBar。
教學
屬性
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
方法
get_current_tab_control() const |
|
get_popup() const |
|
get_previous_tab() const |
|
get_tab_bar() const |
|
get_tab_button_icon(tab_idx: int) const |
|
get_tab_control(tab_idx: int) const |
|
get_tab_count() const |
|
get_tab_icon(tab_idx: int) const |
|
get_tab_icon_max_width(tab_idx: int) const |
|
get_tab_idx_at_point(point: Vector2) const |
|
get_tab_idx_from_control(control: Control) const |
|
get_tab_metadata(tab_idx: int) const |
|
get_tab_title(tab_idx: int) const |
|
get_tab_tooltip(tab_idx: int) const |
|
is_tab_disabled(tab_idx: int) const |
|
is_tab_hidden(tab_idx: int) const |
|
void |
|
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) |
主題屬性
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
訊號
active_tab_rearranged(idx_to: int) 🔗
通過滑鼠拖動重新排列活動分頁時發出。見 drag_to_rearrange_enabled。
pre_popup_pressed() 🔗
按一下 TabContainer 的 Popup 按鈕時發出。有關詳細資訊,請參閱 set_popup()。
tab_button_pressed(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.
屬性說明
已棄用: Due to internal changes this doesn't do anything anymore, as they're always in front.
This doesn't do anything.
如果為 true,則會隱藏超出該節點寬度的分頁,改為顯示兩個導覽按鈕。否則,會更新該節點的最小尺寸,讓所有分頁均可見。
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 🔗
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 🔗
如果為 true,可以通過滑鼠拖動重新排列分頁。
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.
AlignmentMode tab_alignment = 0 🔗
void set_tab_alignment(value: AlignmentMode)
AlignmentMode get_tab_alignment()
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.
If true, the tab at index is hidden.
Note: index is a value in the 0 .. get_tab_count() - 1 range.
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 🔗
void set_tabs_position(value: TabPosition)
TabPosition get_tabs_position()
The horizontal alignment of the tabs.
int tabs_rearrange_group = -1 🔗
具有相同重新排列組 ID 的 TabContainer 將允許在它們之間拖動分頁。使用 drag_to_rearrange_enabled 啟用拖動。
將該屬性設定為 -1 將禁用 TabContainer 之間的重新排列。
如果為 true,分頁可見。如果 false,分頁的內容和標題被隱藏。
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 節點。
如果已經使用 set_popup() 設定了 Popup 節點實例,則返回該節點實例。
警告:這是一個必需的內部節點,移除和釋放它可能會導致當機。如果希望隱藏它或它的任何子項,請使用它們的 Window.visible 屬性。
int get_previous_tab() 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 節點。
返回分頁的數量。
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。
如果索引 tab_idx 處的分頁被隱藏,則返回 true。
bool select_next_available() 🔗
返回目前焦點專案的索引。如果沒有焦點,則返回 -1。
bool select_previous_available() 🔗
返回目前焦點專案的索引。如果沒有焦點,則返回 -1。
如果在一個 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) 🔗
如果 disabled 為 true,則禁用索引 tab_idx 處的選項卡,使其不可互動。
如果 hidden 為 true,則隱藏索引 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.
分頁圖示所允許的最大寬度。這個限制套用在該圖示預設大小之上,但是套用在 TabBar.set_tab_icon_max_width() 所設定的值之前。高度會根據圖示比例調整。
分頁名稱與其圖示之間的間距。
分頁文字輪廓的大小。
注意:如果使用啟用了 FontFile.multichannel_signed_distance_field 的字形,其 FontFile.msdf_pixel_range 必須至少設定為 outline_size 的兩倍,輪廓算繪才能看起來正確。否則,輪廓可能會比預期的更早被切斷。
標籤欄左側或右側邊緣的間距,取決於目前的 tab_alignment。
如果標籤頁被裁剪(見 clip_tabs)或者設定了彈出框(見 set_popup()),則會忽略 TabBar.ALIGNMENT_RIGHT 的邊距。使用 TabBar.ALIGNMENT_CENTER 時始終忽略邊距。
The space between tabs in the tab bar.
用於繪製分頁名稱的字形。
分頁名稱的字形大小。
左邊的箭頭按鈕的圖示,當有太多的標籤無法容納在容器的寬度內時出現。當該按鈕被禁用時(即第一個標籤是可見的),它顯示為半透明的。
Texture2D decrement_highlight 🔗
當標籤太多無法適應容器寬度時出現的左箭頭按鈕圖示。當滑鼠懸停在按鈕上時使用。
Icon shown to indicate where a dragged tab will be dropped (see drag_to_rearrange_enabled).
右箭頭按鈕的圖示,當有太多的標籤無法容納在容器的寬度內時出現。當該按鈕被禁用時(即最後一個標籤是可見的),它顯示為半透明的。
Texture2D increment_highlight 🔗
當標籤太多無法適應容器寬度時出現的右箭頭按鈕圖示。當滑鼠懸停在按鈕上時使用。
功能表按鈕的圖示(見 set_popup())。
當游標懸停時功能表按鈕的圖示(見 set_popup())。
背景填充的樣式。
分頁處於禁用狀態時的樣式。
該 Button 處於聚焦狀態時使用的 StyleBox。focus StyleBox 顯示在基礎 StyleBox 之上,所以應該使用部分透明的 StyleBox,確保基礎 StyleBox 仍然可見。代表輪廓或底線的 StyleBox 可以很好地實作這個目的。要禁用聚焦的視覺效果,請指定 StyleBoxEmpty 資源。請注意,禁用聚焦的視覺效果會影響使用鍵盤/手柄進行導覽的可用性,所以出於可存取性的原因,不建議這樣做。
目前懸停的分頁的樣式。不會套用於選中的分頁。
目前選中的分頁的樣式。
其他未被選中的分頁的樣式。
TabBar 區域的背景填充樣式。