LinkButton's text now is automatically translated
This commit is contained in:
parent
7f1543256d
commit
9cecabb186
|
@ -30,9 +30,16 @@
|
||||||
|
|
||||||
#include "link_button.h"
|
#include "link_button.h"
|
||||||
|
|
||||||
|
#include "core/translation.h"
|
||||||
|
|
||||||
void LinkButton::set_text(const String &p_text) {
|
void LinkButton::set_text(const String &p_text) {
|
||||||
|
if (text == p_text) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
text = p_text;
|
text = p_text;
|
||||||
|
xl_text = tr(p_text);
|
||||||
update();
|
update();
|
||||||
|
_change_notify("text");
|
||||||
minimum_size_changed();
|
minimum_size_changed();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,11 +57,16 @@ LinkButton::UnderlineMode LinkButton::get_underline_mode() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
Size2 LinkButton::get_minimum_size() 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) {
|
void LinkButton::_notification(int p_what) {
|
||||||
switch (p_what) {
|
switch (p_what) {
|
||||||
|
case NOTIFICATION_TRANSLATION_CHANGED: {
|
||||||
|
xl_text = tr(text);
|
||||||
|
minimum_size_changed();
|
||||||
|
update();
|
||||||
|
} break;
|
||||||
case NOTIFICATION_DRAW: {
|
case NOTIFICATION_DRAW: {
|
||||||
RID ci = get_canvas_item();
|
RID ci = get_canvas_item();
|
||||||
Size2 size = get_size();
|
Size2 size = get_size();
|
||||||
|
@ -96,11 +108,11 @@ void LinkButton::_notification(int p_what) {
|
||||||
|
|
||||||
Ref<Font> font = get_font("font");
|
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) {
|
if (do_underline) {
|
||||||
int underline_spacing = get_constant("underline_spacing");
|
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;
|
int y = font->get_ascent() + underline_spacing;
|
||||||
|
|
||||||
draw_line(Vector2(0, y), Vector2(width, y), color);
|
draw_line(Vector2(0, y), Vector2(width, y), color);
|
||||||
|
|
|
@ -46,6 +46,7 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
String text;
|
String text;
|
||||||
|
String xl_text;
|
||||||
UnderlineMode underline_mode;
|
UnderlineMode underline_mode;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
Loading…
Reference in a new issue