Class ItemList
- Namespace
- Godot
- Assembly
- GodotSharp.dll
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 Top mode, but the column's width is adjusted to fully fit its content by default. You need to set FixedColumnWidth 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
.
public class ItemList : Control, IDisposable
- Inheritance
-
ItemList
- Implements
- Inherited Members
Constructors
ItemList()
public ItemList()
Properties
AllowReselect
If true
, the currently selected item can be selected again.
public bool AllowReselect { get; set; }
Property Value
AllowRmbSelect
If true
, right mouse button click can select items.
public bool AllowRmbSelect { get; set; }
Property Value
AllowSearch
If true
, allows navigating the ItemList with letter keys through incremental search.
public bool AllowSearch { get; set; }
Property Value
AutoHeight
If true
, the control will automatically resize the height to fit its content.
public bool AutoHeight { get; set; }
Property Value
FixedColumnWidth
The width all columns will be adjusted to.
A value of zero disables the adjustment, each item will have a width equal to the width of its content and the columns will have an uneven width.
public int FixedColumnWidth { get; set; }
Property Value
FixedIconSize
The size all icons will be adjusted to.
If either X or Y component is not greater than zero, icon size won't be affected.
public Vector2I FixedIconSize { get; set; }
Property Value
IconMode
The icon position, whether above or to the left of the text. See the ItemList.IconModeEnum constants.
public ItemList.IconModeEnum IconMode { get; set; }
Property Value
IconScale
The scale of icon applied after FixedIconSize and transposing takes effect.
public float IconScale { get; set; }
Property Value
ItemCount
The number of items currently in the list.
public int ItemCount { get; set; }
Property Value
MaxColumns
Maximum columns the list will have.
If greater than zero, the content will be split among the specified columns.
A value of zero means unlimited columns, i.e. all items will be put in the same row.
public int MaxColumns { get; set; }
Property Value
MaxTextLines
Maximum lines of text allowed in each item. Space will be reserved even when there is not enough lines of text to display.
Note: This property takes effect only when IconMode is Top. To make the text wrap, FixedColumnWidth should be greater than zero.
public int MaxTextLines { get; set; }
Property Value
SameColumnWidth
Whether all columns will have the same width.
If true
, the width is equal to the largest column width of all columns.
public bool SameColumnWidth { get; set; }
Property Value
SelectMode
Allows single or multiple item selection. See the ItemList.SelectModeEnum constants.
public ItemList.SelectModeEnum SelectMode { get; set; }
Property Value
TextOverrunBehavior
Sets the clipping behavior when the text exceeds an item's bounding rectangle. See TextServer.OverrunBehavior for a description of all modes.
public TextServer.OverrunBehavior TextOverrunBehavior { get; set; }
Property Value
Methods
AddIconItem(Texture2D, bool)
Adds an item to the item list with no text, only an icon. Returns the index of an added item.
public int AddIconItem(Texture2D icon, bool selectable = true)
Parameters
Returns
AddItem(string, Texture2D, bool)
Adds an item to the item list with specified text. Returns the index of an added item.
Specify an icon
, or use null
as the icon
for a list item with no icon.
If selectable is true
, the list item will be selectable.
public int AddItem(string text, Texture2D icon = null, bool selectable = true)
Parameters
Returns
Clear()
Removes all items from the list.
public void Clear()
Deselect(int)
Ensures the item associated with the specified index is not selected.
public void Deselect(int idx)
Parameters
idx
int
DeselectAll()
Ensures there are no items selected.
public void DeselectAll()
EnsureCurrentIsVisible()
Ensure current selection is visible, adjusting the scroll position as necessary.
public void EnsureCurrentIsVisible()
ForceUpdateListSize()
Forces an update to the list size based on its items. This happens automatically whenever size of the items, or other relevant settings like AutoHeight, change. The method can be used to trigger the update ahead of next drawing pass.
public void ForceUpdateListSize()
GetItemAtPosition(Vector2, bool)
Returns the item index at the given position
.
When there is no item at that point, -1 will be returned if exact
is true
, and the closest item index will be returned otherwise.
Note: The returned value is unreliable if called right after modifying the ItemList, before it redraws in the next frame.
public int GetItemAtPosition(Vector2 position, bool exact = false)
Parameters
Returns
GetItemCustomBgColor(int)
Returns the custom background color of the item specified by idx
index.
public Color GetItemCustomBgColor(int idx)
Parameters
idx
int
Returns
GetItemCustomFgColor(int)
Returns the custom foreground color of the item specified by idx
index.
public Color GetItemCustomFgColor(int idx)
Parameters
idx
int
Returns
GetItemIcon(int)
Returns the icon associated with the specified index.
public Texture2D GetItemIcon(int idx)
Parameters
idx
int
Returns
GetItemIconModulate(int)
Returns a Color modulating item's icon at the specified index.
public Color GetItemIconModulate(int idx)
Parameters
idx
int
Returns
GetItemIconRegion(int)
Returns the region of item's icon used. The whole icon will be used if the region has no area.
public Rect2 GetItemIconRegion(int idx)
Parameters
idx
int
Returns
GetItemLanguage(int)
Returns item's text language code.
public string GetItemLanguage(int idx)
Parameters
idx
int
Returns
GetItemMetadata(int)
Returns the metadata value of the specified index.
public Variant GetItemMetadata(int idx)
Parameters
idx
int
Returns
GetItemRect(int, bool)
Returns the position and size of the item with the specified index, in the coordinate system of the ItemList node. If expand
is true
the last column expands to fill the rest of the row.
Note: The returned value is unreliable if called right after modifying the ItemList, before it redraws in the next frame.
public Rect2 GetItemRect(int idx, bool expand = true)
Parameters
Returns
GetItemText(int)
Returns the text associated with the specified index.
public string GetItemText(int idx)
Parameters
idx
int
Returns
GetItemTextDirection(int)
Returns item's text base writing direction.
public Control.TextDirection GetItemTextDirection(int idx)
Parameters
idx
int
Returns
GetItemTooltip(int)
Returns the tooltip hint associated with the specified index.
public string GetItemTooltip(int idx)
Parameters
idx
int
Returns
GetSelectedItems()
Returns an array with the indexes of the selected items.
public int[] GetSelectedItems()
Returns
- int[]
GetVScrollBar()
Returns the vertical scrollbar.
Warning: This is a required internal node, removing and freeing it may cause a crash. If you wish to hide it or any of its children, use their Visible property.
public VScrollBar GetVScrollBar()
Returns
HasGodotClassMethod(in godot_string_name)
Check if the type contains a method with the given name. This method is used by Godot to check if a method exists before invoking it. Do not call or override this method.
protected override bool HasGodotClassMethod(in godot_string_name method)
Parameters
method
godot_string_nameName of the method to check for.
Returns
HasGodotClassSignal(in godot_string_name)
Check if the type contains a signal with the given name. This method is used by Godot to check if a signal exists before raising it. Do not call or override this method.
protected override bool HasGodotClassSignal(in godot_string_name signal)
Parameters
signal
godot_string_nameName of the signal to check for.
Returns
InvokeGodotClassMethod(in godot_string_name, NativeVariantPtrArgs, out godot_variant)
Invokes the method with the given name, using the given arguments. This method is used by Godot to invoke methods from the engine side. Do not call or override this method.
protected override bool InvokeGodotClassMethod(in godot_string_name method, NativeVariantPtrArgs args, out godot_variant ret)
Parameters
method
godot_string_nameName of the method to invoke.
args
NativeVariantPtrArgsArguments to use with the invoked method.
ret
godot_variantValue returned by the invoked method.
Returns
IsAnythingSelected()
Returns true
if one or more items are selected.
public bool IsAnythingSelected()
Returns
IsItemDisabled(int)
Returns true
if the item at the specified index is disabled.
public bool IsItemDisabled(int idx)
Parameters
idx
int
Returns
IsItemIconTransposed(int)
Returns true
if the item icon will be drawn transposed, i.e. the X and Y axes are swapped.
public bool IsItemIconTransposed(int idx)
Parameters
idx
int
Returns
IsItemSelectable(int)
Returns true
if the item at the specified index is selectable.
public bool IsItemSelectable(int idx)
Parameters
idx
int
Returns
IsItemTooltipEnabled(int)
Returns true
if the tooltip is enabled for specified item index.
public bool IsItemTooltipEnabled(int idx)
Parameters
idx
int
Returns
IsSelected(int)
Returns true
if the item at the specified index is currently selected.
public bool IsSelected(int idx)
Parameters
idx
int
Returns
MoveItem(int, int)
Moves item from index fromIdx
to toIdx
.
public void MoveItem(int fromIdx, int toIdx)
Parameters
RemoveItem(int)
Removes the item specified by idx
index from the list.
public void RemoveItem(int idx)
Parameters
idx
int
Select(int, bool)
Select the item at the specified index.
Note: This method does not trigger the item selection signal.
public void Select(int idx, bool single = true)
Parameters
SetItemCustomBgColor(int, Color)
Sets the background color of the item specified by idx
index to the specified Color.
public void SetItemCustomBgColor(int idx, Color customBgColor)
Parameters
SetItemCustomFgColor(int, Color)
Sets the foreground color of the item specified by idx
index to the specified Color.
public void SetItemCustomFgColor(int idx, Color customFgColor)
Parameters
SetItemDisabled(int, bool)
Disables (or enables) the item at the specified index.
Disabled items cannot be selected and do not trigger activation signals (when double-clicking or pressing Enter).
public void SetItemDisabled(int idx, bool disabled)
Parameters
SetItemIcon(int, Texture2D)
Sets (or replaces) the icon's Texture2D associated with the specified index.
public void SetItemIcon(int idx, Texture2D icon)
Parameters
SetItemIconModulate(int, Color)
Sets a modulating Color of the item associated with the specified index.
public void SetItemIconModulate(int idx, Color modulate)
Parameters
SetItemIconRegion(int, Rect2)
Sets the region of item's icon used. The whole icon will be used if the region has no area.
public void SetItemIconRegion(int idx, Rect2 rect)
Parameters
SetItemIconTransposed(int, bool)
Sets whether the item icon will be drawn transposed.
public void SetItemIconTransposed(int idx, bool transposed)
Parameters
SetItemLanguage(int, string)
Sets language code of item's text used for line-breaking and text shaping algorithms, if left empty current locale is used instead.
public void SetItemLanguage(int idx, string language)
Parameters
SetItemMetadata(int, Variant)
Sets a value (of any type) to be stored with the item associated with the specified index.
public void SetItemMetadata(int idx, Variant metadata)
Parameters
SetItemSelectable(int, bool)
Allows or disallows selection of the item associated with the specified index.
public void SetItemSelectable(int idx, bool selectable)
Parameters
SetItemText(int, string)
Sets text of the item associated with the specified index.
public void SetItemText(int idx, string text)
Parameters
SetItemTextDirection(int, TextDirection)
Sets item's text base writing direction.
public void SetItemTextDirection(int idx, Control.TextDirection direction)
Parameters
idx
intdirection
Control.TextDirection
SetItemTooltip(int, string)
Sets the tooltip hint for the item associated with the specified index.
public void SetItemTooltip(int idx, string tooltip)
Parameters
SetItemTooltipEnabled(int, bool)
Sets whether the tooltip hint is enabled for specified item index.
public void SetItemTooltipEnabled(int idx, bool enable)
Parameters
SortItemsByText()
Sorts items in the list by their text.
public void SortItemsByText()
Events
EmptyClicked
Triggered when any mouse click is issued within the rect of the list but on empty space.
public event ItemList.EmptyClickedEventHandler EmptyClicked
Event Type
ItemActivated
Triggered when specified list item is activated via double-clicking or by pressing Enter.
public event ItemList.ItemActivatedEventHandler ItemActivated
Event Type
ItemClicked
Triggered when specified list item has been clicked with any mouse button.
The click position is also provided to allow appropriate popup of context menus at the correct location.
public event ItemList.ItemClickedEventHandler ItemClicked
Event Type
ItemSelected
Triggered when specified item has been selected.
AllowReselect must be enabled to reselect an item.
public event ItemList.ItemSelectedEventHandler ItemSelected
Event Type
MultiSelected
Triggered when a multiple selection is altered on a list allowing multiple selection.
public event ItemList.MultiSelectedEventHandler MultiSelected