From de5b0d71036c6e412de89f77eca57a4e35ffd3a3 Mon Sep 17 00:00:00 2001 From: radzo73 Date: Sun, 28 Jan 2024 14:55:48 -0500 Subject: [PATCH] Add `get_button_color(column, id)` Docs should point to Color constuctor instead of just the class, but I unfortunately cannot. --- doc/classes/TreeItem.xml | 8 ++++++++ scene/gui/tree.cpp | 7 +++++++ scene/gui/tree.h | 1 + 3 files changed, 16 insertions(+) diff --git a/doc/classes/TreeItem.xml b/doc/classes/TreeItem.xml index 3b8a4c8872e..e94fa0c0614 100644 --- a/doc/classes/TreeItem.xml +++ b/doc/classes/TreeItem.xml @@ -96,6 +96,14 @@ Returns the button index if there is a button with ID [param id] in column [param column], otherwise returns -1. + + + + + + Returns the color of the button with ID [param id] in column [param column]. If the specified button does not exist, returns [constant Color.BLACK]. + + diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cpp index 4ecbc173b7f..2d1da7da361 100644 --- a/scene/gui/tree.cpp +++ b/scene/gui/tree.cpp @@ -1222,6 +1222,12 @@ int TreeItem::get_button_by_id(int p_column, int p_id) const { return -1; } +Color TreeItem::get_button_color(int p_column, int p_index) const { + ERR_FAIL_INDEX_V(p_column, cells.size(), Color()); + ERR_FAIL_INDEX_V(p_index, cells[p_column].buttons.size(), Color()); + return cells[p_column].buttons[p_index].color; +} + void TreeItem::set_button_tooltip_text(int p_column, int p_index, const String &p_tooltip) { ERR_FAIL_INDEX(p_column, cells.size()); ERR_FAIL_INDEX(p_index, cells[p_column].buttons.size()); @@ -1662,6 +1668,7 @@ void TreeItem::_bind_methods() { ClassDB::bind_method(D_METHOD("get_button_tooltip_text", "column", "button_index"), &TreeItem::get_button_tooltip_text); ClassDB::bind_method(D_METHOD("get_button_id", "column", "button_index"), &TreeItem::get_button_id); ClassDB::bind_method(D_METHOD("get_button_by_id", "column", "id"), &TreeItem::get_button_by_id); + ClassDB::bind_method(D_METHOD("get_button_color", "column", "id"), &TreeItem::get_button_color); ClassDB::bind_method(D_METHOD("get_button", "column", "button_index"), &TreeItem::get_button); ClassDB::bind_method(D_METHOD("set_button_tooltip_text", "column", "button_index", "tooltip"), &TreeItem::set_button_tooltip_text); ClassDB::bind_method(D_METHOD("set_button", "column", "button_index", "button"), &TreeItem::set_button); diff --git a/scene/gui/tree.h b/scene/gui/tree.h index 8ec003be9c7..ee5f0d420ba 100644 --- a/scene/gui/tree.h +++ b/scene/gui/tree.h @@ -266,6 +266,7 @@ public: int get_button_id(int p_column, int p_index) const; void erase_button(int p_column, int p_index); int get_button_by_id(int p_column, int p_id) const; + Color get_button_color(int p_column, int p_index) const; void set_button_tooltip_text(int p_column, int p_index, const String &p_tooltip); void set_button(int p_column, int p_index, const Ref &p_button); void set_button_color(int p_column, int p_index, const Color &p_color);