Skip to content

Commit 09cbe05

Browse files
committed
Merge pull request #76231 from Calinou/inspector-text-show-tooltip
Show String properties' text in a tooltip in the inspector
2 parents f5d82af + e4106f8 commit 09cbe05

3 files changed

Lines changed: 18 additions & 0 deletions

File tree

editor/editor_inspector.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,12 @@ bool EditorInspector::_property_path_matches(const String &p_property_path, cons
6969
return false;
7070
}
7171

72+
String EditorProperty::get_tooltip_string(const String &p_string) const {
73+
// Trim to 100 characters to prevent the tooltip from being too long.
74+
constexpr int TOOLTIP_MAX_LENGTH = 100;
75+
return p_string.left(TOOLTIP_MAX_LENGTH).strip_edges() + String((p_string.length() > TOOLTIP_MAX_LENGTH) ? "..." : "");
76+
}
77+
7278
Size2 EditorProperty::get_minimum_size() const {
7379
Size2 ms;
7480
Ref<Font> font = get_theme_font(SceneStringName(font), SNAME("Tree"));

editor/editor_inspector.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,8 @@ class EditorProperty : public Container {
160160
public:
161161
void emit_changed(const StringName &p_property, const Variant &p_value, const StringName &p_field = StringName(), bool p_changing = false);
162162

163+
String get_tooltip_string(const String &p_string) const;
164+
163165
virtual Size2 get_minimum_size() const override;
164166

165167
void set_label(const String &p_label);

editor/editor_properties.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ void EditorPropertyText::_text_changed(const String &p_string) {
9191
return;
9292
}
9393

94+
// Set tooltip so that the full text is displayed in a tooltip if hovered.
95+
// This is useful when using a narrow inspector, as the text can be trimmed otherwise.
96+
text->set_tooltip_text(get_tooltip_string(text->get_text()));
97+
9498
if (string_name) {
9599
emit_changed(get_edited_property(), StringName(p_string));
96100
} else {
@@ -104,6 +108,7 @@ void EditorPropertyText::update_property() {
104108
if (text->get_text() != s) {
105109
int caret = text->get_caret_column();
106110
text->set_text(s);
111+
text->set_tooltip_text(get_tooltip_string(s));
107112
text->set_caret_column(caret);
108113
}
109114
text->set_editable(!is_read_only());
@@ -150,10 +155,14 @@ void EditorPropertyMultilineText::_set_read_only(bool p_read_only) {
150155

151156
void EditorPropertyMultilineText::_big_text_changed() {
152157
text->set_text(big_text->get_text());
158+
// Set tooltip so that the full text is displayed in a tooltip if hovered.
159+
// This is useful when using a narrow inspector, as the text can be trimmed otherwise.
160+
text->set_tooltip_text(get_tooltip_string(big_text->get_text()));
153161
emit_changed(get_edited_property(), big_text->get_text(), "", true);
154162
}
155163

156164
void EditorPropertyMultilineText::_text_changed() {
165+
text->set_tooltip_text(get_tooltip_string(text->get_text()));
157166
emit_changed(get_edited_property(), text->get_text(), "", true);
158167
}
159168

@@ -182,6 +191,7 @@ void EditorPropertyMultilineText::update_property() {
182191
String t = get_edited_property_value();
183192
if (text->get_text() != t) {
184193
text->set_text(t);
194+
text->set_tooltip_text(get_tooltip_string(t));
185195
if (big_text && big_text->is_visible_in_tree()) {
186196
big_text->set_text(t);
187197
}

0 commit comments

Comments
 (0)