summaryrefslogtreecommitdiff
path: root/scene/gui/label.cpp
diff options
context:
space:
mode:
authorThomas ten Cate <ttencate@gmail.com>2018-11-15 12:34:08 +0100
committerThomas ten Cate <ttencate@gmail.com>2018-11-15 12:34:08 +0100
commit922f2d613ff53d6de09e1756525226de06db6a9c (patch)
treee85eb0657432dca9863f0a53bbc13fee622bcb6d /scene/gui/label.cpp
parent397b12727cf65a111717142efddb55fd751b1528 (diff)
Fix return value of get_total_character_count
Also document that it only counts visible characters. Fixes #23720
Diffstat (limited to 'scene/gui/label.cpp')
-rw-r--r--scene/gui/label.cpp5
1 files changed, 2 insertions, 3 deletions
diff --git a/scene/gui/label.cpp b/scene/gui/label.cpp
index 8009a96a4f..a7f88514e0 100644
--- a/scene/gui/label.cpp
+++ b/scene/gui/label.cpp
@@ -393,7 +393,7 @@ void Label::regenerate_word_cache() {
WordCache *last = NULL;
- for (int i = 0; i < xl_text.size() + 1; i++) {
+ for (int i = 0; i <= xl_text.length(); i++) {
CharType current = i < xl_text.length() ? xl_text[i] : ' '; //always a space at the end, so the algo works
@@ -429,12 +429,11 @@ void Label::regenerate_word_cache() {
if (current == '\n') {
insert_newline = true;
- } else {
+ } else if (current != ' ') {
total_char_cache++;
}
if (i < xl_text.length() && xl_text[i] == ' ') {
- total_char_cache--; // do not count spaces
if (line_width > 0 || last == NULL || last->char_pos != WordCache::CHAR_WRAPLINE) {
space_count++;
line_width += space_width;