Up to date

This page is up to date for Godot 4.0. If you still find outdated information, please open an issue.

ItemList

Inherits: Control < CanvasItem < Node < Object

A vertical list of selectable items with one or multiple columns.

Description

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.

Properties

bool

allow_reselect

false

bool

allow_rmb_select

false

bool

auto_height

false

bool

clip_contents

true (overrides Control)

int

fixed_column_width

0

Vector2i

fixed_icon_size

Vector2i(0, 0)

FocusMode

focus_mode

2 (overrides Control)

IconMode

icon_mode

1

float

icon_scale

1.0

int

item_count

0

int

max_columns

1

int

max_text_lines

1

bool

same_column_width

false

SelectMode

select_mode

0

OverrunBehavior

text_overrun_behavior

3

Methods

int

add_icon_item ( Texture2D icon, bool selectable=true )

int

add_item ( String text, Texture2D icon=null, bool selectable=true )

void

clear ( )

void

deselect ( int idx )

void

deselect_all ( )

void

ensure_current_is_visible ( )

int

get_item_at_position ( Vector2 position, bool exact=false ) const

Color

get_item_custom_bg_color ( int idx ) const

Color

get_item_custom_fg_color ( int idx ) const

Texture2D

get_item_icon ( int idx ) const

Color

get_item_icon_modulate ( int idx ) const

Rect2

get_item_icon_region ( int idx ) const

String

get_item_language ( int idx ) const

Variant

get_item_metadata ( int idx ) const

String

get_item_text ( int idx ) const

TextDirection

get_item_text_direction ( int idx ) const

String

get_item_tooltip ( int idx ) const

PackedInt32Array

get_selected_items ( )

VScrollBar

get_v_scroll_bar ( )

bool

is_anything_selected ( )

bool

is_item_disabled ( int idx ) const

bool

is_item_icon_transposed ( int idx ) const

bool

is_item_selectable ( int idx ) const

bool

is_item_tooltip_enabled ( int idx ) const

bool

is_selected ( int idx ) const

void

move_item ( int from_idx, int to_idx )

void

remove_item ( int idx )

void

select ( int idx, bool single=true )

void

set_item_custom_bg_color ( int idx, Color custom_bg_color )

void

set_item_custom_fg_color ( int idx, Color custom_fg_color )

void

set_item_disabled ( int idx, bool disabled )

void

set_item_icon ( int idx, Texture2D icon )

void

set_item_icon_modulate ( int idx, Color modulate )

void

set_item_icon_region ( int idx, Rect2 rect )

void

set_item_icon_transposed ( int idx, bool transposed )

void

set_item_language ( int idx, String language )

void

set_item_metadata ( int idx, Variant metadata )

void

set_item_selectable ( int idx, bool selectable )

void

set_item_text ( int idx, String text )

void

set_item_text_direction ( int idx, TextDirection direction )

void

set_item_tooltip ( int idx, String tooltip )

void

set_item_tooltip_enabled ( int idx, bool enable )

void

sort_items_by_text ( )

Theme Properties

Color

font_color

Color(0.65, 0.65, 0.65, 1)

Color

font_outline_color

Color(1, 1, 1, 1)

Color

font_selected_color

Color(1, 1, 1, 1)

Color

guide_color

Color(0.7, 0.7, 0.7, 0.25)

int

h_separation

4

int

icon_margin

4

int

line_separation

2

int

outline_size

0

int

v_separation

2

Font

font

int

font_size

StyleBox

cursor

StyleBox

cursor_unfocused

StyleBox

focus

StyleBox

panel

StyleBox

selected

StyleBox

selected_focus


Signals

empty_clicked ( Vector2 at_position, int mouse_button_index )

Triggered when any mouse click is issued within the rect of the list but on empty space.


item_activated ( int index )

Triggered when specified list item is activated via double-clicking or by pressing Enter.


item_clicked ( int index, Vector2 at_position, int mouse_button_index )

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.


item_selected ( int index )

Triggered when specified item has been selected.

allow_reselect must be enabled to reselect an item.


multi_selected ( int index, bool selected )

Triggered when a multiple selection is altered on a list allowing multiple selection.


Enumerations

enum IconMode:

IconMode ICON_MODE_TOP = 0

Icon is drawn above the text.

IconMode ICON_MODE_LEFT = 1

Icon is drawn to the left of the text.


enum SelectMode:

SelectMode SELECT_SINGLE = 0

Only allow selecting a single item.

SelectMode SELECT_MULTI = 1

Allows selecting multiple items by holding Ctrl or Shift.


Property Descriptions

bool allow_reselect = false

  • void set_allow_reselect ( bool value )

  • bool get_allow_reselect ( )

If true, the currently selected item can be selected again.


bool allow_rmb_select = false

  • void set_allow_rmb_select ( bool value )

  • bool get_allow_rmb_select ( )

If true, right mouse button click can select items.


bool auto_height = false

  • void set_auto_height ( bool value )

  • bool has_auto_height ( )

If true, the control will automatically resize the height to fit its content.


int fixed_column_width = 0

  • void set_fixed_column_width ( int value )

  • int get_fixed_column_width ( )

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.


Vector2i fixed_icon_size = Vector2i(0, 0)

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.


IconMode icon_mode = 1

The icon position, whether above or to the left of the text. See the IconMode constants.


float icon_scale = 1.0

  • void set_icon_scale ( float value )

  • float get_icon_scale ( )

The scale of icon applied after fixed_icon_size and transposing takes effect.


int item_count = 0

  • void set_item_count ( int value )

  • int get_item_count ( )

The number of items currently in the list.


int max_columns = 1

  • void set_max_columns ( int value )

  • int get_max_columns ( )

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.


int max_text_lines = 1

  • void set_max_text_lines ( int value )

  • int get_max_text_lines ( )

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 icon_mode is ICON_MODE_TOP. To make the text wrap, fixed_column_width should be greater than zero.


bool same_column_width = false

  • void set_same_column_width ( bool value )

  • bool is_same_column_width ( )

Whether all columns will have the same width.

If true, the width is equal to the largest column width of all columns.


SelectMode select_mode = 0

Allows single or multiple item selection. See the SelectMode constants.


OverrunBehavior text_overrun_behavior = 3

Sets the clipping behavior when the text exceeds an item's bounding rectangle. See OverrunBehavior for a description of all modes.


Method Descriptions

int add_icon_item ( Texture2D icon, bool selectable=true )

Adds an item to the item list with no text, only an icon. Returns the index of an added item.


int add_item ( String text, Texture2D icon=null, bool selectable=true )

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.


void clear ( )

Removes all items from the list.


void deselect ( int idx )

Ensures the item associated with the specified index is not selected.


void deselect_all ( )

Ensures there are no items selected.


void ensure_current_is_visible ( )

Ensure current selection is visible, adjusting the scroll position as necessary.


int get_item_at_position ( Vector2 position, bool exact=false ) const

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 wi