diff options
author | Rindbee <idleman@yeah.net> | 2022-09-21 19:31:24 +0800 |
---|---|---|
committer | Rindbee <idleman@yeah.net> | 2022-09-21 19:47:36 +0800 |
commit | 332c566a6c8a79c14a5336f1ed80b66bbf9b51bc (patch) | |
tree | b48fb3e978f62b870961f21053ce9f81aa0d203a | |
parent | 307f560b39439042614f206cc28c80dd543b69cf (diff) |
Let the cached `TextLine` reset the width in `get_string_size`
Previously, the cached `TextLine` would set the width in `draw_string`, but not in `get_string_size`,
which resulted in unexpected results returned by `get_string_size` in some cases.
-rw-r--r-- | scene/resources/font.cpp | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/scene/resources/font.cpp b/scene/resources/font.cpp index 3d9e4e4a63..bbc4029764 100644 --- a/scene/resources/font.cpp +++ b/scene/resources/font.cpp @@ -272,13 +272,15 @@ Size2 Font::get_string_size(const String &p_text, HorizontalAlignment p_alignmen buffer->set_direction(p_direction); buffer->set_orientation(p_orientation); buffer->add_string(p_text, Ref<Font>(this), p_font_size); - if (p_alignment == HORIZONTAL_ALIGNMENT_FILL) { - buffer->set_horizontal_alignment(p_alignment); - buffer->set_width(p_width); - buffer->set_flags(p_jst_flags); - } cache.insert(hash, buffer); } + + buffer->set_width(p_width); + buffer->set_horizontal_alignment(p_alignment); + if (p_alignment == HORIZONTAL_ALIGNMENT_FILL) { + buffer->set_flags(p_jst_flags); + } + return buffer->get_size(); } |