diff options
Diffstat (limited to 'scene/gui/label.cpp')
-rw-r--r-- | scene/gui/label.cpp | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/scene/gui/label.cpp b/scene/gui/label.cpp index 510f1b18ad..9e2cd9e941 100644 --- a/scene/gui/label.cpp +++ b/scene/gui/label.cpp @@ -296,8 +296,9 @@ Size2 Label::get_minimum_size() const { Size2 min_style = get_stylebox("normal")->get_minimum_size(); // don't want to mutable everything - if (word_cache_dirty) + if (word_cache_dirty) { const_cast<Label *>(this)->regenerate_word_cache(); + } if (autowrap) return Size2(1, clip ? 1 : minsize.height) + min_style; @@ -377,8 +378,14 @@ void Label::regenerate_word_cache() { memdelete(current); } - Ref<StyleBox> style = get_stylebox("normal"); - int width = autowrap ? (get_size().width - style->get_minimum_size().width) : get_longest_line_width(); + int width; + if (autowrap) { + Ref<StyleBox> style = get_stylebox("normal"); + width = MAX(get_size().width, get_custom_minimum_size().width) - style->get_minimum_size().width; + } else { + width = get_longest_line_width(); + } + Ref<Font> font = get_font("font"); int current_word_size = 0; @@ -452,6 +459,11 @@ void Label::regenerate_word_cache() { current_word_size += char_width; line_width += char_width; total_char_cache++; + + // allow autowrap to cut words when they exceed line width + if (autowrap && (current_word_size > width)) { + separatable = true; + } } if ((autowrap && (line_width >= width) && ((last && last->char_pos >= 0) || separatable)) || insert_newline) { |