TabBar
繼承: Control < CanvasItem < Node < Object
提供水平分頁欄的控制項。
說明
提供水平分頁欄的控制項。類似於 TabContainer,但只負責繪製分頁,不與子節點互動。
屬性
|
||
|
||
|
||
|
||
|
||
focus_mode |
|
|
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
方法
主題屬性
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
訊號
active_tab_rearranged(idx_to: int) 🔗
通過滑鼠拖動重新排列活動分頁時發出。見 drag_to_rearrange_enabled。
tab_button_pressed(tab: int) 🔗
分頁的右側按鈕被按下時發出。見 set_tab_button_icon()。
切換到另一個分頁時發出。
按一下分頁時發出,即使它是目前分頁。
Emitted when a tab's close button is pressed or when middle-clicking on a tab, if close_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)
GetNode<TabBar>("TabBar").TabClosePressed += GetNode<TabBar>("TabBar").RemoveTab;
當滑鼠懸停分頁時發出。
按右鍵分頁時發出。必須啟用 select_with_rmb。
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
將分頁置於左側。
AlignmentMode ALIGNMENT_CENTER = 1
將分頁置於中間。
AlignmentMode ALIGNMENT_RIGHT = 2
將分頁置於右側。
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 列舉的大小。
屬性說明
如果為 true,則會隱藏超出該節點寬度的分頁,改為顯示兩個導覽按鈕。否則,會更新該節點的最小尺寸,讓所有分頁均可見。
bool close_with_middle_mouse = true 🔗
If true, middle clicking on the mouse will fire the tab_close_pressed signal.
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 🔗
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 🔗
如果為 true,可以通過滑鼠拖動重新排列分頁。
設定所有分頁應被限制的最大寬度。如果設定為 0,則無限制。
bool scroll_to_selected = true 🔗
如果為 true,則會更改分頁偏移量,從而保持目前選中的分頁可見。
bool scrolling_enabled = true 🔗
如果為 true,滑鼠的滾輪可用於導覽滾動視圖。
bool select_with_rmb = false 🔗
如果為 true,啟用滑鼠右鍵選擇分頁。
AlignmentMode tab_alignment = 0 🔗
void set_tab_alignment(value: AlignmentMode)
AlignmentMode get_tab_alignment()
The position at which tabs will be placed.
CloseButtonDisplayPolicy tab_close_display_policy = 0 🔗
void set_tab_close_display_policy(value: CloseButtonDisplayPolicy)
CloseButtonDisplayPolicy get_tab_close_display_policy()
When the close button will appear on the tabs.
分頁欄中目前的分頁數量。
int tabs_rearrange_group = -1 🔗
具有相同重新排列組 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。
返回向左偏移的隱藏分頁的數量。
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。
如果索引 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) 🔗
如果 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_language(tab_idx: int, language: String) 🔗
設定分頁標題的語言程式碼,用於斷行和文字塑形演算法,如果留空則使用目前區域設置。
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) 🔗
其他未被選中的分頁的字形顏色。
分頁內元素之間的水平分隔。
分頁圖示所允許的最大寬度。這個限制套用在該圖示預設大小之上,但是套用在 set_tab_icon_max_width() 所設定的值之前。高度會根據圖示比例調整。
分頁文字輪廓的大小。
注意:如果使用啟用了 FontFile.multichannel_signed_distance_field 的字形,其 FontFile.msdf_pixel_range 必須至少設定為 outline_size 的兩倍,輪廓算繪才能看起來正確。否則,輪廓可能會比預期的更早被切斷。
The space between tabs in the tab bar.
用於繪製分頁名稱的字形。
分頁名稱的字形大小。
關閉按鈕的圖示(見 tab_close_display_policy)。
左邊的箭頭按鈕的圖示,當有太多的標籤無法容納在容器的寬度內時出現。當該按鈕被禁用時(即第一個標籤是可見的),它顯示為半透明的。
Texture2D decrement_highlight 🔗
當標籤太多無法適應容器寬度時出現的左箭頭按鈕圖示。當滑鼠懸停在按鈕上時使用。
圖示,用於指示拖動的分頁將被放置到哪裡(見 drag_to_rearrange_enabled)。
右箭頭按鈕的圖示,當有太多的標籤無法容納在容器的寬度內時出現。當該按鈕被禁用時(即最後一個標籤是可見的),它顯示為半透明的。
Texture2D increment_highlight 🔗
當標籤太多無法適應容器寬度時出現的右箭頭按鈕圖示。當滑鼠懸停在按鈕上時使用。
分頁和關閉按鈕的背景,處於滑鼠懸停狀態時使用。
分頁和關閉按鈕的背景,處於按下狀態時使用。
分頁處於禁用狀態時的樣式。
該 Button 處於聚焦狀態時使用的 StyleBox。focus StyleBox 顯示在基礎 StyleBox 之上,所以應該使用部分透明的 StyleBox,確保基礎 StyleBox 仍然可見。代表輪廓或底線的 StyleBox 可以很好地實作這個目的。要禁用聚焦的視覺效果,請指定 StyleBoxEmpty 資源。請注意,禁用聚焦的視覺效果會影響使用鍵盤/手柄進行導覽的可用性,所以出於可存取性的原因,不建議這樣做。
目前懸停分頁的樣式。不適用於所選分頁。
注意:此樣式將至少以與tab_unselected相同的寬度繪製。
目前選中的分頁的樣式。
其他未被選中的分頁的樣式。