[Tree] Allow disabling auto generated tooltip for TreeItem

This commit is contained in:
A Thousand Ships 2024-09-18 20:50:14 +02:00
parent 694d3c2930
commit fd2981b337
No known key found for this signature in database
GPG Key ID: 2033189A662F8BD7
3 changed files with 21 additions and 1 deletions

View File

@ -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 names as a 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.

View File

@ -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;
@ -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));
@ -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");
@ -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"));

View File

@ -682,6 +682,8 @@ private:
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;
@ -811,6 +813,9 @@ public:
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();