summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <rverschelde@gmail.com>2020-09-05 12:38:26 +0200
committerGitHub <noreply@github.com>2020-09-05 12:38:26 +0200
commitff9195a905d6fc2b85cf36d2d19d1021b6740211 (patch)
treefef1bf9e43cd58a1265d017fc73957e24c17db62
parent2163e81fea7aac048ee023ae8a5b2f01762d45a4 (diff)
parent4318ad94acb2f1f3dabfed1d5159da6fe013b529 (diff)
Merge pull request #40649 from themvl/master
Fix bug where leading and trailing spaces werent taken into account with center and right allignment
-rw-r--r--scene/gui/label.cpp18
1 files changed, 17 insertions, 1 deletions
diff --git a/scene/gui/label.cpp b/scene/gui/label.cpp
index 9f3db2ba20..9e3418a5c9 100644
--- a/scene/gui/label.cpp
+++ b/scene/gui/label.cpp
@@ -188,7 +188,7 @@ void Label::_notification(int p_what) {
int spaces = 0;
while (to && to->char_pos >= 0) {
taken += to->pixel_width;
- if (to != from && to->space_count) {
+ if (to->space_count) {
spaces += to->space_count;
}
to = to->next;
@@ -420,6 +420,22 @@ void Label::regenerate_word_cache() {
wc->space_count = space_count;
current_word_size = 0;
space_count = 0;
+ } else if ((i == xl_text.length() || current == '\n') && last != nullptr && space_count != 0) {
+ //in case there are trailing white spaces we add a placeholder word cache with just the spaces
+ WordCache *wc = memnew(WordCache);
+ if (word_cache) {
+ last->next = wc;
+ } else {
+ word_cache = wc;
+ }
+ last = wc;
+
+ wc->pixel_width = 0;
+ wc->char_pos = 0;
+ wc->word_len = 0;
+ wc->space_count = space_count;
+ current_word_size = 0;
+ space_count = 0;
}
if (current == '\n') {