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

LinkButton's text now is automatically translated #52145

Merged
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
16 changes: 13 additions & 3 deletions scene/gui/link_button.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,16 @@ void LinkButton::_shape() {
} else {
text_buf->set_direction((TextServer::Direction)text_direction);
}
TS->shaped_text_set_bidi_override(text_buf->get_rid(), structured_text_parser(st_parser, st_args, text));
text_buf->add_string(text, font, font_size, opentype_features, (language != "") ? language : TranslationServer::get_singleton()->get_tool_locale());
TS->shaped_text_set_bidi_override(text_buf->get_rid(), structured_text_parser(st_parser, st_args, xl_text));
text_buf->add_string(xl_text, font, font_size, opentype_features, (language != "") ? language : TranslationServer::get_singleton()->get_tool_locale());
}

void LinkButton::set_text(const String &p_text) {
if (text == p_text) {
return;
}
text = p_text;
xl_text = atr(text);
_shape();
minimum_size_changed();
update();
Expand Down Expand Up @@ -141,7 +145,13 @@ Size2 LinkButton::get_minimum_size() const {

void LinkButton::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_TRANSLATION_CHANGED:
case NOTIFICATION_TRANSLATION_CHANGED: {
xl_text = atr(text);
_shape();

minimum_size_changed();
update();
} break;
case NOTIFICATION_LAYOUT_DIRECTION_CHANGED: {
update();
} break;
Expand Down
1 change: 1 addition & 0 deletions scene/gui/link_button.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class LinkButton : public BaseButton {

private:
String text;
String xl_text;
Ref<TextLine> text_buf;
UnderlineMode underline_mode = UNDERLINE_MODE_ALWAYS;

Expand Down