Skip to content

armgit / godot

Public Imported from GitHub
0

Godot Engine – Multi-platform 2D and 3D game engine

Allow negative indices in TreeItem's set_button_*() methods

kobewi02af7fe0bf05
diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cpp
index 203d924eec3..02807f91b88 100644
--- a/scene/gui/tree.cpp
+++ b/scene/gui/tree.cpp
@@ -1474,6 +1474,9 @@ void TreeItem::set_button_tooltip_text(int p_column, int p_index, const String &
void TreeItem::set_button(int p_column, int p_index, const Ref<Texture2D> &p_button) {
ERR_FAIL_COND(p_button.is_null());
ERR_FAIL_INDEX(p_column, cells.size());
+ if (p_index < 0) {
+ p_index += cells[p_column].buttons.size();
+ }
ERR_FAIL_INDEX(p_index, cells[p_column].buttons.size());
if (cells[p_column].buttons[p_index].texture == p_button) {
@@ -1488,6 +1491,9 @@ void TreeItem::set_button(int p_column, int p_index, const Ref<Texture2D> &p_but
void TreeItem::set_button_description(int p_column, int p_index, const String &p_description) {
ERR_FAIL_INDEX(p_column, cells.size());
+ if (p_index < 0) {
+ p_index += cells[p_column].buttons.size();
+ }
ERR_FAIL_INDEX(p_index, cells[p_column].buttons.size());
if (cells[p_column].buttons[p_index].description == p_description) {
@@ -1503,6 +1509,9 @@ void TreeItem::set_button_description(int p_column, int p_index, const String &p
void TreeItem::set_button_color(int p_column, int p_index, const Color &p_color) {
ERR_FAIL_INDEX(p_column, cells.size());
+ if (p_index < 0) {
+ p_index += cells[p_column].buttons.size();
+ }
ERR_FAIL_INDEX(p_index, cells[p_column].buttons.size());
if (cells[p_column].buttons[p_index].color == p_color) {
@@ -1515,6 +1524,9 @@ void TreeItem::set_button_color(int p_column, int p_index, const Color &p_color)
void TreeItem::set_button_disabled(int p_column, int p_index, bool p_disabled) {
ERR_FAIL_INDEX(p_column, cells.size());
+ if (p_index < 0) {
+ p_index += cells[p_column].buttons.size();
+ }
ERR_FAIL_INDEX(p_index, cells[p_column].buttons.size());
if (cells[p_column].buttons[p_index].disabled == p_disabled) {