summaryrefslogtreecommitdiff
path: root/scene/gui
diff options
context:
space:
mode:
authorRedMser <redmser.jj2@gmail.com>2022-10-08 15:56:21 +0200
committerRedMser <redmser.jj2@gmail.com>2022-10-08 17:02:25 +0200
commit9579d49820af61f457f5fbf7097247059f5bd21b (patch)
tree6a91bf0d678ac923a6759dac8334e902b321e1cd /scene/gui
parentbbac8198f89c0cbf0da4293201e54aa847947370 (diff)
Add warning for missing characters in label font
Diffstat (limited to 'scene/gui')
-rw-r--r--scene/gui/label.cpp32
-rw-r--r--scene/gui/label.h1
2 files changed, 33 insertions, 0 deletions
diff --git a/scene/gui/label.cpp b/scene/gui/label.cpp
index bf7c59d1cd..d7d00b674e 100644
--- a/scene/gui/label.cpp
+++ b/scene/gui/label.cpp
@@ -288,6 +288,36 @@ void Label::_update_theme_item_cache() {
theme_cache.font_shadow_outline_size = get_theme_constant(SNAME("shadow_outline_size"));
}
+PackedStringArray Label::get_configuration_warnings() const {
+ PackedStringArray warnings = Control::get_configuration_warnings();
+
+ // Ensure that the font can render all of the required glyphs.
+ Ref<Font> font;
+ if (settings.is_valid()) {
+ font = settings->get_font();
+ }
+ if (font.is_null()) {
+ font = theme_cache.font;
+ }
+
+ if (font.is_valid()) {
+ if (dirty || font_dirty || lines_dirty) {
+ const_cast<Label *>(this)->_shape();
+ }
+
+ const Glyph *glyph = TS->shaped_text_get_glyphs(text_rid);
+ int64_t glyph_count = TS->shaped_text_get_glyph_count(text_rid);
+ for (int64_t i = 0; i < glyph_count; i++) {
+ if (glyph[i].font_rid == RID()) {
+ warnings.push_back(RTR("The current font does not support rendering one or more characters used in this Label's text."));
+ break;
+ }
+ }
+ }
+
+ return warnings;
+}
+
void Label::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_TRANSLATION_CHANGED: {
@@ -302,6 +332,7 @@ void Label::_notification(int p_what) {
dirty = true;
queue_redraw();
+ update_configuration_warnings();
} break;
case NOTIFICATION_LAYOUT_DIRECTION_CHANGED: {
@@ -674,6 +705,7 @@ void Label::set_text(const String &p_string) {
}
queue_redraw();
update_minimum_size();
+ update_configuration_warnings();
}
void Label::_invalidate() {
diff --git a/scene/gui/label.h b/scene/gui/label.h
index b79c94a5ba..41d7049b22 100644
--- a/scene/gui/label.h
+++ b/scene/gui/label.h
@@ -93,6 +93,7 @@ protected:
public:
virtual Size2 get_minimum_size() const override;
+ virtual PackedStringArray get_configuration_warnings() const override;
void set_horizontal_alignment(HorizontalAlignment p_alignment);
HorizontalAlignment get_horizontal_alignment() const;