summaryrefslogtreecommitdiff
path: root/scene/gui
diff options
context:
space:
mode:
authorRuslan Mustakov <r.mustakov@gmail.com>2018-05-14 20:18:44 +0700
committerRuslan Mustakov <r.mustakov@gmail.com>2018-05-14 20:32:14 +0700
commitd5a0b5f35b22658f5c575e2f494ebd3f3239b8cc (patch)
treedc07f1f58bbcffa6d66d1685663b3ff9771ccb21 /scene/gui
parent8c71cbbe3fcd45cc1459c24a712273d143ef6879 (diff)
Ceil char width within Label instead of Font
Some classes use Font::get_char_size directly and not only for autowrapping. RichTextLabel is one such example. So this commit reverts aa8561d (PR #17504) and instead ceils character width within Label. This makes sure Label autowraps correctly while not affecting other Font clients. Fixes #18835.
Diffstat (limited to 'scene/gui')
-rw-r--r--scene/gui/label.cpp13
1 files changed, 8 insertions, 5 deletions
diff --git a/scene/gui/label.cpp b/scene/gui/label.cpp
index f1b0d36f32..9af479c1cc 100644
--- a/scene/gui/label.cpp
+++ b/scene/gui/label.cpp
@@ -103,7 +103,8 @@ void Label::_notification(int p_what) {
int lines_visible = (size.y + line_spacing) / font_h;
- int space_w = font->get_char_size(' ').width;
+ // ceiling to ensure autowrapping does not cut text
+ int space_w = Math::ceil(font->get_char_size(' ').width);
int chars_total = 0;
int vbegin = 0, vsep = 0;
@@ -331,7 +332,8 @@ int Label::get_longest_line_width() const {
}
} else {
- int char_width = font->get_char_size(current, xl_text[i + 1]).width;
+ // ceiling to ensure autowrapping does not cut text
+ int char_width = Math::ceil(font->get_char_size(current, xl_text[i + 1]).width);
line_width += char_width;
}
}
@@ -384,7 +386,8 @@ void Label::regenerate_word_cache() {
int word_pos = 0;
int line_width = 0;
int space_count = 0;
- int space_width = font->get_char_size(' ').width;
+ // ceiling to ensure autowrapping does not cut text
+ int space_width = Math::ceil(font->get_char_size(' ').width);
int line_spacing = get_constant("line_spacing");
line_count = 1;
total_char_cache = 0;
@@ -446,8 +449,8 @@ void Label::regenerate_word_cache() {
if (current_word_size == 0) {
word_pos = i;
}
-
- char_width = font->get_char_size(current, xl_text[i + 1]).width;
+ // ceiling to ensure autowrapping does not cut text
+ char_width = Math::ceil(font->get_char_size(current, xl_text[i + 1]).width);
current_word_size += char_width;
line_width += char_width;
total_char_cache++;