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 in 3.x #52138

Merged
merged 1 commit into from
Aug 26, 2021
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
18 changes: 15 additions & 3 deletions scene/gui/link_button.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,16 @@

#include "link_button.h"

#include "core/translation.h"

void LinkButton::set_text(const String &p_text) {
if (text == p_text) {
return;
}
text = p_text;
xl_text = tr(p_text);
update();
_change_notify("text");
minimum_size_changed();
}

Expand All @@ -50,11 +57,16 @@ LinkButton::UnderlineMode LinkButton::get_underline_mode() const {
}

Size2 LinkButton::get_minimum_size() const {
return get_font("font")->get_string_size(text);
return get_font("font")->get_string_size(xl_text);
}

void LinkButton::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_TRANSLATION_CHANGED: {
xl_text = tr(text);
minimum_size_changed();
update();
} break;
case NOTIFICATION_DRAW: {
RID ci = get_canvas_item();
Size2 size = get_size();
Expand Down Expand Up @@ -96,11 +108,11 @@ void LinkButton::_notification(int p_what) {

Ref<Font> font = get_font("font");

draw_string(font, Vector2(0, font->get_ascent()), text, color);
draw_string(font, Vector2(0, font->get_ascent()), xl_text, color);

if (do_underline) {
int underline_spacing = get_constant("underline_spacing");
int width = font->get_string_size(text).width;
int width = font->get_string_size(xl_text).width;
int y = font->get_ascent() + underline_spacing;

draw_line(Vector2(0, y), Vector2(width, y), color);
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 @@ -46,6 +46,7 @@ class LinkButton : public BaseButton {

private:
String text;
String xl_text;
UnderlineMode underline_mode;

protected:
Expand Down