summaryrefslogtreecommitdiffstats
path: root/scene/gui/tree.cpp
diff options
context:
space:
mode:
authorAndreas Haas <liu.gam3@gmail.com>2017-04-24 21:41:17 +0200
committerAndreas Haas <liu.gam3@gmail.com>2017-04-26 19:14:35 +0200
commit29999942a2957dd5f7fb308e0cfa6f3f4e26c253 (patch)
treed784ec8bc4afb3514811afda4841351d7a627d33 /scene/gui/tree.cpp
parent02c041904f7ced28cd2a006c09725fd9fd60520f (diff)
downloadredot-engine-29999942a2957dd5f7fb308e0cfa6f3f4e26c253.tar.gz
Tree: Ability to add tooltips to TreeItem buttons.
Adds a tooltip parameter to `TreeItem::add_button()` and set a few tooltips in the Project settings and SceneTree dock.
Diffstat (limited to 'scene/gui/tree.cpp')
-rw-r--r--scene/gui/tree.cpp18
1 files changed, 16 insertions, 2 deletions
diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cpp
index bc7b7485d8..6f2d725353 100644
--- a/scene/gui/tree.cpp
+++ b/scene/gui/tree.cpp
@@ -464,7 +464,7 @@ void TreeItem::deselect(int p_column) {
_cell_deselected(p_column);
}
-void TreeItem::add_button(int p_column, const Ref<Texture> &p_button, int p_id, bool p_disabled) {
+void TreeItem::add_button(int p_column, const Ref<Texture> &p_button, int p_id, bool p_disabled, const String &p_tooltip) {
ERR_FAIL_INDEX(p_column, cells.size());
ERR_FAIL_COND(!p_button.is_valid());
@@ -474,6 +474,7 @@ void TreeItem::add_button(int p_column, const Ref<Texture> &p_button, int p_id,
p_id = cells[p_column].buttons.size();
button.id = p_id;
button.disabled = p_disabled;
+ button.tooltip = p_tooltip;
cells[p_column].buttons.push_back(button);
_changed_notify(p_column);
}
@@ -669,7 +670,7 @@ void TreeItem::_bind_methods() {
ClassDB::bind_method(D_METHOD("clear_custom_bg_color", "column"), &TreeItem::clear_custom_bg_color);
ClassDB::bind_method(D_METHOD("get_custom_bg_color", "column"), &TreeItem::get_custom_bg_color);
- ClassDB::bind_method(D_METHOD("add_button", "column", "button:Texture", "button_idx", "disabled"), &TreeItem::add_button, DEFVAL(-1), DEFVAL(false));
+ ClassDB::bind_method(D_METHOD("add_button", "column", "button:Texture", "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:Texture", "column", "button_idx"), &TreeItem::get_button);
ClassDB::bind_method(D_METHOD("set_button", "column", "button_idx", "button:Texture"), &TreeItem::set_button);
@@ -3290,6 +3291,19 @@ String Tree::get_tooltip(const Point2 &p_pos) const {
if (it) {
+ TreeItem::Cell &c = it->cells[col];
+ int col_width = get_column_width(col);
+ for (int j = c.buttons.size() - 1; j >= 0; j--) {
+ Ref<Texture> b = c.buttons[j].texture;
+ Size2 size = b->get_size() + cache.button_pressed->get_minimum_size();
+ if (pos.x > col_width - size.width) {
+ String tooltip = c.buttons[j].tooltip;
+ if (tooltip != "") {
+ return tooltip;
+ }
+ }
+ col_width -= size.width;
+ }
String ret;
if (it->get_tooltip(col) == "")
ret = it->get_text(col);