diff options
author | volzhs <volzhs@gmail.com> | 2020-01-06 01:06:26 +0900 |
---|---|---|
committer | volzhs <volzhs@gmail.com> | 2020-01-06 01:06:26 +0900 |
commit | 3f0c7b89ec8e2972b44c6d029d4aa515ca9e4129 (patch) | |
tree | 2f486ee042b4a5d57b427c759a971a6d15b4bd85 /scene/gui | |
parent | 2299fb819808f5cab5140d31abe7e4dc0b0707df (diff) |
Fix calculating label size
Diffstat (limited to 'scene/gui')
-rw-r--r-- | scene/gui/label.cpp | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/scene/gui/label.cpp b/scene/gui/label.cpp index 11172ac7a9..fa795361a8 100644 --- a/scene/gui/label.cpp +++ b/scene/gui/label.cpp @@ -313,8 +313,8 @@ Size2 Label::get_minimum_size() const { int Label::get_longest_line_width() const { Ref<Font> font = get_font("font"); - int max_line_width = 0; - int line_width = 0; + real_t max_line_width = 0; + real_t line_width = 0; for (int i = 0; i < xl_text.size(); i++) { @@ -332,8 +332,7 @@ int Label::get_longest_line_width() const { } } else { - // ceiling to ensure autowrapping does not cut text - int char_width = Math::ceil(font->get_char_size(current, xl_text[i + 1]).width); + real_t char_width = font->get_char_size(current, xl_text[i + 1]).width; line_width += char_width; } } @@ -341,7 +340,8 @@ int Label::get_longest_line_width() const { if (line_width > max_line_width) max_line_width = line_width; - return max_line_width; + // ceiling to ensure autowrapping does not cut text + return Math::ceil(max_line_width); } int Label::get_line_count() const { @@ -388,7 +388,7 @@ void Label::regenerate_word_cache() { Ref<Font> font = get_font("font"); - int current_word_size = 0; + real_t current_word_size = 0; int word_pos = 0; int line_width = 0; int space_count = 0; @@ -413,7 +413,7 @@ void Label::regenerate_word_cache() { bool separatable = (current >= 0x2E08 && current <= 0xFAFF) || (current >= 0xFE30 && current <= 0xFE4F); //current>=33 && (current < 65||current >90) && (current<97||current>122) && (current<48||current>57); bool insert_newline = false; - int char_width = 0; + real_t char_width = 0; if (current < 33) { @@ -455,9 +455,9 @@ void Label::regenerate_word_cache() { word_pos = i; } // ceiling to ensure autowrapping does not cut text - char_width = Math::ceil(font->get_char_size(current, xl_text[i + 1]).width); + char_width = font->get_char_size(current, xl_text[i + 1]).width; current_word_size += char_width; - line_width += char_width; + line_width += Math::ceil(char_width); total_char_cache++; // allow autowrap to cut words when they exceed line width |