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...
ItemList
繼承: Control < CanvasItem < Node < Object
可選專案的垂直列表,可以有一列或多列。
說明
This control provides a vertical list of selectable items that may be in a single or in multiple columns, with each item having options for text and an icon. Tooltips are supported and may be different for every item in the list.
Selectable items in the list may be selected or deselected and multiple selection may be enabled. Selection with right mouse button may also be enabled to allow use of popup context menus. Items may also be "activated" by double-clicking them or by pressing Enter.
Item text only supports single-line strings. Newline characters (e.g. \n) in the string won't produce a newline. Text wrapping is enabled in ICON_MODE_TOP mode, but the column's width is adjusted to fully fit its content by default. You need to set fixed_column_width greater than zero to wrap the text.
All set_* methods allow negative item indices, i.e. -1 to access the last item, -2 to select the second-to-last item, and so on.
Incremental search: Like PopupMenu and Tree, ItemList supports searching within the list while the control is focused. Press a key that matches the first letter of an item's name to select the first item starting with the given letter. After that point, there are two ways to perform incremental search: 1) Press the same key again before the timeout duration to select the next item starting with the same letter. 2) Press letter keys that match the rest of the word before the timeout duration to match to select the item in question directly. Both of these actions will be reset to the beginning of the list if the timeout duration has passed since the last keystroke was registered. You can adjust the timeout duration by changing ProjectSettings.gui/timers/incremental_search_max_interval_msec.
屬性
|
||
|
||
|
||
|
||
|
||
clip_contents |
|
|
|
||
|
||
focus_mode |
|
|
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
方法
主題屬性
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
訊號
empty_clicked(at_position: Vector2, mouse_button_index: int) 🔗
在清單矩形內的非空白區域點選任意滑鼠按鍵時觸發。
at_position 為點選的位置,使用控制項的區域座標系。
通過雙擊或按Enter鍵啟用指定的清單項時觸發。
item_clicked(index: int, at_position: Vector2, mouse_button_index: int) 🔗
使用任意滑鼠按鍵按一下指定的清單項時觸發。
at_position 為點選的位置,使用控制項的區域座標系。
選擇指定項目時觸發。僅適用於單選模式。
allow_reselect 必須啟用才能重新選擇項目。
multi_selected(index: int, selected: bool) 🔗
在允許多選的清單上更改多選時觸發。
列舉
enum IconMode: 🔗
IconMode ICON_MODE_TOP = 0
圖示繪製在文字上方。
IconMode ICON_MODE_LEFT = 1
圖示繪製在文字的左側。
enum SelectMode: 🔗
SelectMode SELECT_SINGLE = 0
僅允許選擇單個專案。
SelectMode SELECT_MULTI = 1
允許通過按住 Ctrl 或 Shift 來選擇多個專案。
SelectMode SELECT_TOGGLE = 2
允許選擇多個項目,可以切換項目是否選中。
enum ScrollHintMode: 🔗
ScrollHintMode SCROLL_HINT_MODE_DISABLED = 0
捲動提示將永遠不會顯示。
ScrollHintMode SCROLL_HINT_MODE_BOTH = 1
捲動提示將顯示在頂部和底部。
ScrollHintMode SCROLL_HINT_MODE_TOP = 2
只會顯示頂部的捲動提示。
ScrollHintMode SCROLL_HINT_MODE_BOTTOM = 3
只會顯示底部的捲動提示。
屬性說明
如果為 true,則可以再次選擇目前選中的專案。
bool allow_rmb_select = false 🔗
如果為 true,點選滑鼠右鍵可以選中專案。
如果為 true,則允許用字母鍵通過差異量搜尋導覽 ItemList。
如果為 true,控制項將自動調整高度以適合其內容。
如果為 true,控制項將自動調整寬度以適合其內容。
所有列的寬度將調整為。
零值停用調整,每個專案的寬度將等於其內容的寬度,列的寬度將不均勻。
Vector2i fixed_icon_size = Vector2i(0, 0) 🔗
所有圖示將被調整到的尺寸。
如果 X 或 Y 分量不大於 0,圖示的大小將不會受到影響。
圖示的位置,是在文字的上方還是在文字的左邊。參閱 IconMode 常數。
在 fixed_icon_size 和轉置生效後套用的圖示比例。
目前列表中的專案數。
bool item_{index}/disabled = false 🔗
如果為 true,則停用位於 index 處的項目。
注意: index 的取值範圍為 0 .. item_count - 1。
位於 index 處的項目的圖示。
注意: index 的取值範圍為 0 .. item_count - 1。
bool item_{index}/selectable = true 🔗
如果為 true,則位於 index 處的項目可被選擇。
注意: index 的取值範圍為 0 .. item_count - 1。
String item_{index}/text = "" 🔗
位於 index 處的項目的文字。
注意: index 的取值範圍為 0 .. item_count - 1。
列表將具有的最大列。
如果大於零,內容將被拆分為指定列。
零值意味著無限列,即所有專案將放在同一行中。
每個子項中允許的最大文字行數。即使沒有足夠的文字行數來顯示,也會保留空間。
注意:這個屬性只有在 icon_mode 是 ICON_MODE_TOP 時才會生效。要使文字自動換行,fixed_column_width應大於零。
bool same_column_width = false 🔗
是否所有列的寬度相同。
如果為 true,則寬度等於所有列的最大列寬度。
ScrollHintMode scroll_hint_mode = 0 🔗
void set_scroll_hint_mode(value: ScrollHintMode)
ScrollHintMode get_scroll_hint_mode()
捲動提示(指示內容仍可沿特定方向捲動的指示器)的顯示方式。
SelectMode select_mode = 0 🔗
void set_select_mode(value: SelectMode)
SelectMode get_select_mode()
允許單選或多選。參閱SelectMode常數。
OverrunBehavior text_overrun_behavior = 3 🔗
void set_text_overrun_behavior(value: OverrunBehavior)
OverrunBehavior get_text_overrun_behavior()
當文字超出項目的邊界矩形時的裁剪行為。
bool tile_scroll_hint = false 🔗
如果為 true,則捲動提示紋理將平鋪而不是拉伸。見 scroll_hint_mode。
bool wraparound_items = true 🔗
如果為 true,則控制項會自動將項目移動至新的一行,適配內容。另見 HFlowContainer 的這一行為。
如果為 false,控制項會新增水平捲動條,使所有項目都可見。
方法說明
int add_icon_item(icon: Texture2D, selectable: bool = true) 🔗
將一個專案新增到專案列表中,沒有文字,只有一個圖示。返回新增的項的索引。
int add_item(text: String, icon: Texture2D = null, selectable: bool = true) 🔗
在項目清單中新增一個項目並指定文字。回傳新增項目的索引。
使用 icon 指定圖示,清單項不帶圖示時請為 icon 指定 null。
如果 selectable 為 true,則該清單項可被選中。
void center_on_current(center_verically: bool = true, center_horizontally: bool = true) 🔗
確保目前選定的項目(如果啟用了多項選擇,則為第一個選定的項目)可見,必要時調整捲動位置,盡可能將該項目放置在清單的中心。另見 ensure_current_is_visible()。
如果兩個參數均為 false,則該方法將失敗並輸出錯誤訊息。
void clear() 🔗
移除列表中的所有專案。
確保與指定索引相關的專案不被選中。
void deselect_all() 🔗
確保沒有選擇任何專案。
void ensure_current_is_visible() 🔗
確保目前選定的項目(如果啟用了多項選擇,則為第一個選定的項目)可見,必要時調整捲動位置。另見 center_on_current()。
void force_update_list_size() 🔗
根據其專案強制更新列表大小。只要專案的大小或其他相關設定(例如 auto_height)發生更改,這種情況就會自動發生。該方法可用於在下方一次繪圖前觸發更新。
HScrollBar get_h_scroll_bar() 🔗
回傳水平捲動條。
警告:這是一個必需的內部節點,刪除和釋放它可能會導致崩潰。如果你希望隱藏它或其任何子項,請使用它們的 CanvasItem.visible 屬性。
int get_item_at_position(position: Vector2, exact: bool = false) const 🔗
返回位於給定位置 position 的專案的索引。
這個位置沒有專案時,如果 exact 為 true 則會返回 -1,否則會返回距離最近的專案的索引。
注意:如果修改 ItemList 後立即呼叫,尚未在下一影格中重繪,則返回值不可靠。
AutoTranslateMode get_item_auto_translate_mode(idx: int) const 🔗
回傳項目的自動翻譯模式。
Color get_item_custom_bg_color(idx: int) const 🔗
返回專案的自訂背景色,專案由索引 idx 指定。
Color get_item_custom_fg_color(idx: int) const 🔗
返回專案的自訂前景色,專案由索引 idx 指定。
Texture2D get_item_icon(idx: int) const 🔗
返回與指定索引相關的圖示。
Color get_item_icon_modulate(idx: int) const 🔗
返回指定索引處的 Color 顏色調變項的圖示。
Rect2 get_item_icon_region(idx: int) const 🔗
返回專案圖示的使用區域。如果該區域大小為 0,整個圖示將被使用。
String get_item_language(idx: int) const 🔗
返回專案文字的語言程式碼。
Variant get_item_metadata(idx: int) const 🔗
返回指定索引的中繼資料值。
Rect2 get_item_rect(idx: int, expand: bool = true) const 🔗
返回具有給定索引的專案的位置和大小,使用 ItemList 節點的座標系。如果 expand 為 true,則會將最後一列進行擴充,充滿該行剩餘的大小。
注意:如果修改 ItemList 後立即呼叫,尚未在下一影格中重繪,則返回值不可靠。
String get_item_text(idx: int) const 🔗
返回與指定索引關聯的文字。
TextDirection get_item_text_direction(idx: int) const 🔗
返回專案文字的基礎書寫方向。
String get_item_tooltip(idx: int) const 🔗
返回與指定索引關聯的工具提示。
PackedInt32Array get_selected_items() 🔗
返回一個包含所選專案索引的陣列。
VScrollBar get_v_scroll_bar() 🔗
返回垂直捲動條。
警告:這是一個必需的內部節點,刪除和釋放它可能會導致當機。如果你希望隱藏它或其任何子項,請使用它們的 CanvasItem.visible 屬性。
選中了一個或多個專案時,返回 true。
bool is_item_disabled(idx: int) const 🔗
索引所對應的專案被停用時,返回 true。
bool is_item_icon_transposed(idx: int) const 🔗
專案圖示被轉置繪製,即 X 和 Y 軸互換時,返回 true。
bool is_item_selectable(idx: int) const 🔗
索引所對應的專案可以被選中時,返回 true。
bool is_item_tooltip_enabled(idx: int) const 🔗
索引所對應的專案已啟用工具提示時,返回 true。
bool is_selected(idx: int) const 🔗
索引所對應的專案被選中時,返回 true。
void move_item(from_idx: int, to_idx: int) 🔗
將專案從索引 from_idx 移到 to_idx。
從列表中刪除索引 idx 指定的專案。
void select(idx: int, single: bool = true) 🔗
選擇指定索引(index)處的項目。
注意: 此方法不會觸發項目選擇的訊號。
void set_item_auto_translate_mode(idx: int, mode: AutoTranslateMode) 🔗
設定與給定索引關聯的項目的自動翻譯模式。
項目預設使用 Node.AUTO_TRANSLATE_MODE_INHERIT,表示使用與 ItemList 相同的自動翻譯模式。
void set_item_custom_bg_color(idx: int, custom_bg_color: Color) 🔗
將索引 idx 指定的專案的背景色設定為指定的 Color。
void set_item_custom_fg_color(idx: int, custom_fg_color: Color) 🔗
將索引 idx 指定的專案的前景色設定為指定的 Color。
void set_item_disabled(idx: int, disabled: bool) 🔗
停用(或啟用)指定索引處的專案。
停用的專案不能被選中,也不會觸發(雙擊或按 Enter 時的)啟動訊號。
void set_item_icon(idx: int, icon: Texture2D) 🔗
設定(或替換)與指定索引關聯的圖示 Texture2D。
void set_item_icon_modulate(idx: int, modulate: Color) 🔗
設定與指定索引相關的專案的調變顏色 Color。
void set_item_icon_region(idx: int, rect: Rect2) 🔗
設定專案圖示的使用區域。如果該區域大小為 0,將使用整個圖示。
void set_item_icon_transposed(idx: int, transposed: bool) 🔗
設定專案圖示是否將被轉置繪製。
void set_item_language(idx: int, language: String) 🔗
將給定索引處項目的文字語言程式碼設定為 language。這是用於換行和文字塑形算法的。如果 language 為空,則使用目前區域設定。
void set_item_metadata(idx: int, metadata: Variant) 🔗
設定與指定索引相關的專案儲存的值(任何型別的值)。
void set_item_selectable(idx: int, selectable: bool) 🔗
允許或禁止選擇與指定索引關聯的專案。
void set_item_text(idx: int, text: String) 🔗
設定與指定索引相關的專案的文字。
void set_item_text_direction(idx: int, direction: TextDirection) 🔗
設定專案文字的基礎書寫方向。
void set_item_tooltip(idx: int, tooltip: String) 🔗
設定與指定索引相關的專案的工具提示。
void set_item_tooltip_enabled(idx: int, enable: bool) 🔗
設定是否為指定的專案索引啟用工具提示。
void sort_items_by_text() 🔗
按文字對列表中的專案進行排序。
主題屬性說明
Color font_color = Color(0.65, 0.65, 0.65, 1) 🔗
專案的預設文字顏色 Color。
Color font_disabled_color = Color(0.875, 0.875, 0.875, 0.5) 🔗
Text Color used when the item is disabled.
Color font_disabled_hovered_color = Color(0.875, 0.875, 0.875, 0.5) 🔗
Text Color used when the item is disabled and hovered.
Color font_hovered_color = Color(0.95, 0.95, 0.95, 1) 🔗
專案處於懸停但未選中狀態時使用的文字 Color。
Color font_hovered_selected_color = Color(1, 1, 1, 1) 🔗
項目處於懸停且已選中狀態時使用的文字 Color。
Color font_outline_color = Color(0, 0, 0, 1) 🔗
專案文字輪廓的色調。
Color font_selected_color = Color(1, 1, 1, 1) 🔗
項目處於選中但未懸停狀態時使用的文字 Color。
Color guide_color = Color(0.7, 0.7, 0.7, 0.25) 🔗
輔助線的顏色 Color。輔助線是在每行專案之間畫的一條線。
Color scroll_hint_color = Color(0, 0, 0, 1) 🔗
用於調制 scroll_hint 紋理的 Color。
專案之間的水平間距。
專案的圖示和文字之間的間距。
每行文字之間的行距。
專案文字輪廓的大小。
注意:如果使用啟用了 FontFile.multichannel_signed_distance_field 的字形,其 FontFile.msdf_pixel_range 必須至少設定為 outline_size 的兩倍,輪廓渲染才能看起來正確。否則,輪廓可能會比預期的更早被切斷。
int scrollbar_h_separation = 4 🔗
The horizontal separation of items and the vertical scrollbar.
int scrollbar_margin_bottom = -1 🔗
The bottom margin of the horizontal scrollbar. When negative, uses panel's bottom margin.
int scrollbar_margin_left = -1 🔗
The left margin of the horizontal scrollbar. When negative, uses panel's left margin.
int scrollbar_margin_right = -1 🔗
The right margin of the horizontal scrollbar. When negative, uses panel's right margin.
int scrollbar_margin_top = -1 🔗
The top margin of the horizontal scrollbar. When negative, uses panel's top margin.
專案選單之間的垂直間距。
專案文字的字形 Font 。
專案文字的字形大小。
內容仍可捲動時將顯示的指示器。見 scroll_hint_mode。
AudioStream focus_sound 🔗
Played when this ItemList receives keyboard or gamepad-induced focus. Mouse or touch-induced focus does not play a focus sound.
AudioStream item_hovered_sound 🔗
Played when an item is hovered. Disabled items do not play a hover sound.
AudioStream item_selected_disabled_sound 🔗
Played when selecting a disabled item is attempted.
AudioStream item_selected_sound 🔗
Played when an item is selected.
當該 ItemList 獲得焦點時,用作游標的樣式盒 StyleBox。
當該 ItemList 未獲得焦點時,用作游標的樣式盒 StyleBox。
StyleBox for items that are disabled.
StyleBox for items that are disabled, hovered, but not selected.
ItemList 的聚焦樣式,繪製在所有內容之上。
懸停但未被選中的專案的 StyleBox。
項目處於懸停且選中狀態時的 StyleBox,在 ItemList 未獲得焦點時使用。
StyleBox hovered_selected_focus 🔗
項目處於懸停且選中狀態時的 StyleBox,在 ItemList 獲得焦點時使用。
該 ItemList 的預設背景。
所選項的樣式盒 StyleBox,當該 ItemList 未獲得焦點時使用。
所選項的樣式盒 StyleBox,當該 ItemList 獲得焦點時使用。