From 899034a4df379867f2f7189a9012c7c802a5106a Mon Sep 17 00:00:00 2001 From: Nolan Darilek Date: Wed, 4 Sep 2019 09:47:47 -0500 Subject: [PATCH] #14011: Implement `TreeItem.get_button_tooltip(column, idx)`. When added to `TreeItem`, buttons are given tooltips. When returned via `get_button(...)`, however, the button is a `Texture` and the tooltip information isn't included. For accessibility purposes, it is useful to have access to the tooltip text. As such, we can retrieve a button's tooltip to use as a button label. --- doc/classes/TreeItem.xml | 9 +++++++++ scene/gui/tree.cpp | 6 ++++++ scene/gui/tree.h | 1 + 3 files changed, 16 insertions(+) diff --git a/doc/classes/TreeItem.xml b/doc/classes/TreeItem.xml index 4e61f5c49fc7..92016f5ea03a 100644 --- a/doc/classes/TreeItem.xml +++ b/doc/classes/TreeItem.xml @@ -84,6 +84,15 @@ Returns the number of buttons in column [code]column[/code]. May be used to get the most recently added button's index, if no index was specified. + + + + + + + Returns the tooltip for the button in column [code]column[/code]. + + diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cpp index df2c3cd66c45..d9d255f5407d 100644 --- a/scene/gui/tree.cpp +++ b/scene/gui/tree.cpp @@ -547,6 +547,11 @@ Ref TreeItem::get_button(int p_column, int p_idx) const { ERR_FAIL_INDEX_V(p_idx, cells[p_column].buttons.size(), Ref()); return cells[p_column].buttons[p_idx].texture; } +String TreeItem::get_button_tooltip(int p_column, int p_idx) const { + ERR_FAIL_INDEX_V(p_column, cells.size(), String()); + ERR_FAIL_INDEX_V(p_idx, cells[p_column].buttons.size(), String()); + return cells[p_column].buttons[p_idx].tooltip; +} int TreeItem::get_button_id(int p_column, int p_idx) const { ERR_FAIL_INDEX_V(p_column, cells.size(), -1); ERR_FAIL_INDEX_V(p_idx, cells[p_column].buttons.size(), -1); @@ -832,6 +837,7 @@ void TreeItem::_bind_methods() { ClassDB::bind_method(D_METHOD("add_button", "column", "button", "button_idx", "disabled", "tooltip"), &TreeItem::add_button, DEFVAL(-1), DEFVAL(false), DEFVAL("")); ClassDB::bind_method(D_METHOD("get_button_count", "column"), &TreeItem::get_button_count); + ClassDB::bind_method(D_METHOD("get_button_tooltip", "column"), &TreeItem::get_button_tooltip); ClassDB::bind_method(D_METHOD("get_button", "column", "button_idx"), &TreeItem::get_button); ClassDB::bind_method(D_METHOD("set_button", "column", "button_idx", "button"), &TreeItem::set_button); ClassDB::bind_method(D_METHOD("erase_button", "column", "button_idx"), &TreeItem::erase_button); diff --git a/scene/gui/tree.h b/scene/gui/tree.h index 68f68299174d..361830173b1e 100644 --- a/scene/gui/tree.h +++ b/scene/gui/tree.h @@ -203,6 +203,7 @@ class TreeItem : public Object { void add_button(int p_column, const Ref &p_button, int p_id = -1, bool p_disabled = false, const String &p_tooltip = ""); int get_button_count(int p_column) const; + String get_button_tooltip(int p_column, int p_idx) const; Ref get_button(int p_column, int p_idx) const; int get_button_id(int p_column, int p_idx) const; void erase_button(int p_column, int p_idx);