From 7a752215ba88142557f99b148772fd7bf1dd1c8b Mon Sep 17 00:00:00 2001 From: Haoyu Qiu Date: Thu, 26 Dec 2019 11:27:28 +0800 Subject: [PATCH] Improves ItemList * Adds range hint for integer properties * Adds missing descriptions in documentation * Updates some method descriptions to match the actual behavior * Fixes second param name of `set_item_icon_transposed` from `rect` to `transposed` --- doc/classes/ItemList.xml | 31 +++++++++++++++++++++++-------- scene/gui/item_list.cpp | 8 ++++---- 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/doc/classes/ItemList.xml b/doc/classes/ItemList.xml index c82d6a27c0e..51d13627ad2 100644 --- a/doc/classes/ItemList.xml +++ b/doc/classes/ItemList.xml @@ -6,6 +6,7 @@ This control provides a selectable list of items that may be in a single (or multiple columns) with option of text, icons, or both text and 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. [code]\n[/code]) in the string won't produce a newline. Text wrapping is enabled in [constant ICON_MODE_TOP] mode, but column's width is adjusted to fully fit its content by default. You need to set [member fixed_column_width] greater than zero to wrap the text. @@ -57,7 +58,8 @@ - Given a position within the control return the item (if any) at that point. + Returns the item index at the given [code]position[/code]. + When there is no item at that point, -1 will be returned if [code]exact[/code] is [code]true[/code], and the closest item index will be returned otherwise. @@ -109,6 +111,7 @@ + Returns the region of item's icon used. The whole icon will be used if the region has no area. @@ -174,6 +177,7 @@ + Returns [code]true[/code] if the item icon will be drawn transposed, i.e. the X and Y axes are swapped. @@ -307,6 +311,7 @@ + Sets the region of item's icon used. The whole icon will be used if the region has no area. @@ -314,9 +319,10 @@ - + + Sets whether the item icon will be drawn transposed. @@ -409,26 +415,33 @@ If [code]true[/code], the control will automatically resize the height to fit its content. - Sets the default column width in pixels. If left to default value, each item will have a width equal to the width of its content and the columns will have an uneven 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. - Sets the default icon size in pixels. + 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. - Sets the default position of the icon to either [constant ICON_MODE_LEFT] or [constant ICON_MODE_TOP]. + The icon position, whether above or to the left of the text. See the [enum IconMode] constants. - Sets the icon size to its initial size multiplied by the specified scale. + The scale of icon applied after [member fixed_icon_size] and transposing takes effect. - Sets the maximum columns the list will have. If set to anything other than the default, the content will be split among the specified 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. + Maximum lines of text allowed in each item. Space will be reserved even when there is not enough lines of text to display. + [b]Note:[/b] This property takes effect only when [member icon_mode] is [constant ICON_MODE_TOP]. To make the text wrap, [member fixed_column_width] should be greater than zero. - If set to [code]true[/code], all columns will have the same width specified by [member fixed_column_width]. + Whether all columns will have the same width. + If [code]true[/code], the width is equal to the largest column width of all columns. Allows single or multiple item selection. See the [enum SelectMode] constants. @@ -486,8 +499,10 @@ + Icon is drawn above the text. + Icon is drawn to the left of the text. Only allow selecting a single item. diff --git a/scene/gui/item_list.cpp b/scene/gui/item_list.cpp index 20bbcbde80b..91da395368f 100644 --- a/scene/gui/item_list.cpp +++ b/scene/gui/item_list.cpp @@ -1456,7 +1456,7 @@ void ItemList::_bind_methods() { ClassDB::bind_method(D_METHOD("set_item_icon", "idx", "icon"), &ItemList::set_item_icon); ClassDB::bind_method(D_METHOD("get_item_icon", "idx"), &ItemList::get_item_icon); - ClassDB::bind_method(D_METHOD("set_item_icon_transposed", "idx", "rect"), &ItemList::set_item_icon_transposed); + ClassDB::bind_method(D_METHOD("set_item_icon_transposed", "idx", "transposed"), &ItemList::set_item_icon_transposed); ClassDB::bind_method(D_METHOD("is_item_icon_transposed", "idx"), &ItemList::is_item_icon_transposed); ClassDB::bind_method(D_METHOD("set_item_icon_region", "idx", "rect"), &ItemList::set_item_icon_region); @@ -1553,12 +1553,12 @@ void ItemList::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::INT, "select_mode", PROPERTY_HINT_ENUM, "Single,Multi"), "set_select_mode", "get_select_mode"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "allow_reselect"), "set_allow_reselect", "get_allow_reselect"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "allow_rmb_select"), "set_allow_rmb_select", "get_allow_rmb_select"); - ADD_PROPERTY(PropertyInfo(Variant::INT, "max_text_lines"), "set_max_text_lines", "get_max_text_lines"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "max_text_lines", PROPERTY_HINT_RANGE, "1,10,1,or_greater"), "set_max_text_lines", "get_max_text_lines"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "auto_height"), "set_auto_height", "has_auto_height"); ADD_GROUP("Columns", ""); - ADD_PROPERTY(PropertyInfo(Variant::INT, "max_columns"), "set_max_columns", "get_max_columns"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "max_columns", PROPERTY_HINT_RANGE, "0,10,1,or_greater"), "set_max_columns", "get_max_columns"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "same_column_width"), "set_same_column_width", "is_same_column_width"); - ADD_PROPERTY(PropertyInfo(Variant::INT, "fixed_column_width"), "set_fixed_column_width", "get_fixed_column_width"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "fixed_column_width", PROPERTY_HINT_RANGE, "0,100,1,or_greater"), "set_fixed_column_width", "get_fixed_column_width"); ADD_GROUP("Icon", ""); ADD_PROPERTY(PropertyInfo(Variant::INT, "icon_mode", PROPERTY_HINT_ENUM, "Top,Left"), "set_icon_mode", "get_icon_mode"); ADD_PROPERTY(PropertyInfo(Variant::REAL, "icon_scale"), "set_icon_scale", "get_icon_scale");