From 02af7fe0bf05d734bd23ddc30995de0fe55aa222 Mon Sep 17 00:00:00 2001 From: kobewi Date: Sun, 7 Jun 2026 12:12:18 +0200 Subject: [PATCH] Allow negative indices in TreeItem's set_button_*() methods --- scene/gui/tree.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cpp index 203d924eec..02807f91b8 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 &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 &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) {