Skip to content

Commit

Permalink
Add get_button_color(column, id)
Browse files Browse the repository at this point in the history
Docs should point to Color constuctor instead of just the class, but I unfortunately cannot.
  • Loading branch information
radzo73 committed Jan 29, 2024
1 parent 17e7f85 commit de5b0d7
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
8 changes: 8 additions & 0 deletions doc/classes/TreeItem.xml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,14 @@
Returns the button index if there is a button with ID [param id] in column [param column], otherwise returns -1.
</description>
</method>
<method name="get_button_color" qualifiers="const">
<return type="Color" />
<param index="0" name="column" type="int" />
<param index="1" name="id" type="int" />
<description>
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].
</description>
</method>
<method name="get_button_count" qualifiers="const">
<return type="int" />
<param index="0" name="column" type="int" />
Expand Down
7 changes: 7 additions & 0 deletions scene/gui/tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions scene/gui/tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ class TreeItem : public Object {
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<Texture2D> &p_button);
void set_button_color(int p_column, int p_index, const Color &p_color);
Expand Down

0 comments on commit de5b0d7

Please sign in to comment.