diff options
-rw-r--r-- | doc/classes/ItemList.xml | 10 | ||||
-rw-r--r-- | scene/gui/item_list.cpp | 14 | ||||
-rw-r--r-- | scene/gui/item_list.h | 2 |
3 files changed, 26 insertions, 0 deletions
diff --git a/doc/classes/ItemList.xml b/doc/classes/ItemList.xml index 2da5ad3cac..4aca92776f 100644 --- a/doc/classes/ItemList.xml +++ b/doc/classes/ItemList.xml @@ -64,6 +64,7 @@ <description> Returns the item index at the given [param position]. When there is no item at that point, -1 will be returned if [param exact] is [code]true[/code], and the closest item index will be returned otherwise. + [b]Note:[/b] The returned value is unreliable if called right after modifying the [ItemList], before it redraws in the next frame. </description> </method> <method name="get_item_custom_bg_color" qualifiers="const"> @@ -115,6 +116,15 @@ Returns the metadata value of the specified index. </description> </method> + <method name="get_item_rect" qualifiers="const"> + <return type="Rect2" /> + <param index="0" name="idx" type="int" /> + <param index="1" name="expand" type="bool" default="true" /> + <description> + Returns the position and size of the item with the specified index, in the coordinate system of the [ItemList] node. If [param expand] is [code]true[/code] the last column expands to fill the rest of the row. + [b]Note:[/b] The returned value is unreliable if called right after modifying the [ItemList], before it redraws in the next frame. + </description> + </method> <method name="get_item_text" qualifiers="const"> <return type="String" /> <param index="0" name="idx" type="int" /> diff --git a/scene/gui/item_list.cpp b/scene/gui/item_list.cpp index cafc7c5e51..594276a428 100644 --- a/scene/gui/item_list.cpp +++ b/scene/gui/item_list.cpp @@ -294,6 +294,18 @@ Color ItemList::get_item_custom_fg_color(int p_idx) const { return items[p_idx].custom_fg; } +Rect2 ItemList::get_item_rect(int p_idx, bool p_expand) const { + ERR_FAIL_INDEX_V(p_idx, items.size(), Rect2()); + + Rect2 ret = items[p_idx].rect_cache; + ret.position += theme_cache.panel_style->get_offset(); + + if (p_expand && p_idx % current_columns == current_columns - 1) { + ret.size.width = get_size().width - ret.position.x; + } + return ret; +} + void ItemList::set_item_tag_icon(int p_idx, const Ref<Texture2D> &p_tag_icon) { if (p_idx < 0) { p_idx += get_item_count(); @@ -1778,6 +1790,8 @@ void ItemList::_bind_methods() { ClassDB::bind_method(D_METHOD("set_item_custom_fg_color", "idx", "custom_fg_color"), &ItemList::set_item_custom_fg_color); ClassDB::bind_method(D_METHOD("get_item_custom_fg_color", "idx"), &ItemList::get_item_custom_fg_color); + ClassDB::bind_method(D_METHOD("get_item_rect", "idx", "expand"), &ItemList::get_item_rect, DEFVAL(true)); + ClassDB::bind_method(D_METHOD("set_item_tooltip_enabled", "idx", "enable"), &ItemList::set_item_tooltip_enabled); ClassDB::bind_method(D_METHOD("is_item_tooltip_enabled", "idx"), &ItemList::is_item_tooltip_enabled); diff --git a/scene/gui/item_list.h b/scene/gui/item_list.h index cd91f97410..ced04f8718 100644 --- a/scene/gui/item_list.h +++ b/scene/gui/item_list.h @@ -211,6 +211,8 @@ public: void set_item_custom_fg_color(int p_idx, const Color &p_custom_fg_color); Color get_item_custom_fg_color(int p_idx) const; + Rect2 get_item_rect(int p_idx, bool p_expand = true) const; + void set_text_overrun_behavior(TextServer::OverrunBehavior p_behavior); TextServer::OverrunBehavior get_text_overrun_behavior() const; |