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

Show String properties' text in a tooltip in the inspector #76231

Merged
merged 1 commit into from
Dec 5, 2024
Merged
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
6 changes: 6 additions & 0 deletions editor/editor_inspector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ bool EditorInspector::_property_path_matches(const String &p_property_path, cons
return false;
}

String EditorProperty::get_tooltip_string(const String &p_string) const {
// Trim to 100 characters to prevent the tooltip from being too long.
constexpr int TOOLTIP_MAX_LENGTH = 100;
return p_string.left(TOOLTIP_MAX_LENGTH).strip_edges() + String((p_string.length() > TOOLTIP_MAX_LENGTH) ? "..." : "");
}

Size2 EditorProperty::get_minimum_size() const {
Size2 ms;
Ref<Font> font = get_theme_font(SceneStringName(font), SNAME("Tree"));
Expand Down
2 changes: 2 additions & 0 deletions editor/editor_inspector.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ class EditorProperty : public Container {
public:
void emit_changed(const StringName &p_property, const Variant &p_value, const StringName &p_field = StringName(), bool p_changing = false);

String get_tooltip_string(const String &p_string) const;

virtual Size2 get_minimum_size() const override;

void set_label(const String &p_label);
Expand Down
10 changes: 10 additions & 0 deletions editor/editor_properties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ void EditorPropertyText::_text_changed(const String &p_string) {
return;
}

// Set tooltip so that the full text is displayed in a tooltip if hovered.
// This is useful when using a narrow inspector, as the text can be trimmed otherwise.
text->set_tooltip_text(get_tooltip_string(text->get_text()));

if (string_name) {
emit_changed(get_edited_property(), StringName(p_string));
} else {
Expand All @@ -104,6 +108,7 @@ void EditorPropertyText::update_property() {
if (text->get_text() != s) {
int caret = text->get_caret_column();
text->set_text(s);
text->set_tooltip_text(get_tooltip_string(s));
text->set_caret_column(caret);
}
text->set_editable(!is_read_only());
Expand Down Expand Up @@ -150,10 +155,14 @@ void EditorPropertyMultilineText::_set_read_only(bool p_read_only) {

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

void EditorPropertyMultilineText::_text_changed() {
text->set_tooltip_text(get_tooltip_string(text->get_text()));
emit_changed(get_edited_property(), text->get_text(), "", true);
}

Expand Down Expand Up @@ -182,6 +191,7 @@ void EditorPropertyMultilineText::update_property() {
String t = get_edited_property_value();
if (text->get_text() != t) {
text->set_text(t);
text->set_tooltip_text(get_tooltip_string(t));
if (big_text && big_text->is_visible_in_tree()) {
big_text->set_text(t);
}
Expand Down