Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Tree] Allow disabling auto generated tooltip for TreeItem #97158

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions doc/classes/Tree.xml
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,9 @@
<member name="allow_search" type="bool" setter="set_allow_search" getter="get_allow_search" default="true">
If [code]true[/code], allows navigating the [Tree] with letter keys through incremental search.
</member>
<member name="auto_tooltip" type="bool" setter="set_auto_tooltip" getter="is_auto_tooltip_enabled" default="true">
If [code]true[/code], tree items with no tooltip assigned display their title as their tooltip.
</member>
<member name="clip_contents" type="bool" setter="set_clip_contents" getter="is_clipping_contents" overrides="Control" default="true" />
<member name="column_titles_visible" type="bool" setter="set_column_titles_visible" getter="are_column_titles_visible" default="false">
If [code]true[/code], column titles are visible.
Expand Down
14 changes: 13 additions & 1 deletion scene/gui/tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5552,7 +5552,7 @@ String Tree::get_tooltip(const Point2 &p_pos) const {

if (it) {
const String item_tooltip = it->get_tooltip_text(col);
if (item_tooltip.is_empty()) {
if (enable_auto_tooltip && item_tooltip.is_empty()) {
return it->get_text(col);
}
return item_tooltip;
Expand Down Expand Up @@ -5634,6 +5634,14 @@ bool Tree::get_allow_search() const {
return allow_search;
}

void Tree::set_auto_tooltip(bool p_enable) {
enable_auto_tooltip = p_enable;
}

bool Tree::is_auto_tooltip_enabled() const {
return enable_auto_tooltip;
}

void Tree::_bind_methods() {
ClassDB::bind_method(D_METHOD("clear"), &Tree::clear);
ClassDB::bind_method(D_METHOD("create_item", "parent", "index"), &Tree::create_item, DEFVAL(Variant()), DEFVAL(-1));
Expand Down Expand Up @@ -5717,6 +5725,9 @@ void Tree::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_allow_search", "allow"), &Tree::set_allow_search);
ClassDB::bind_method(D_METHOD("get_allow_search"), &Tree::get_allow_search);

ClassDB::bind_method(D_METHOD("set_auto_tooltip", "enable"), &Tree::set_auto_tooltip);
ClassDB::bind_method(D_METHOD("is_auto_tooltip_enabled"), &Tree::is_auto_tooltip_enabled);

ADD_PROPERTY(PropertyInfo(Variant::INT, "columns"), "set_columns", "get_columns");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "column_titles_visible"), "set_column_titles_visible", "are_column_titles_visible");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "allow_reselect"), "set_allow_reselect", "get_allow_reselect");
Expand All @@ -5729,6 +5740,7 @@ void Tree::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::INT, "select_mode", PROPERTY_HINT_ENUM, "Single,Row,Multi"), "set_select_mode", "get_select_mode");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "scroll_horizontal_enabled"), "set_h_scroll_enabled", "is_h_scroll_enabled");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "scroll_vertical_enabled"), "set_v_scroll_enabled", "is_v_scroll_enabled");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "auto_tooltip"), "set_auto_tooltip", "is_auto_tooltip_enabled");

ADD_SIGNAL(MethodInfo("item_selected"));
ADD_SIGNAL(MethodInfo("cell_selected"));
Expand Down
5 changes: 5 additions & 0 deletions scene/gui/tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,8 @@ class Tree : public Control {

bool enable_recursive_folding = true;

bool enable_auto_tooltip = true;

int _count_selected_items(TreeItem *p_from) const;
bool _is_branch_selected(TreeItem *p_from) const;
bool _is_sibling_branch_selected(TreeItem *p_from) const;
Expand Down Expand Up @@ -811,6 +813,9 @@ class Tree : public Control {
void set_allow_search(bool p_allow);
bool get_allow_search() const;

void set_auto_tooltip(bool p_enable);
bool is_auto_tooltip_enabled() const;

Size2 get_minimum_size() const override;

Tree();
Expand Down
Loading