From ce116e4708f11fc97f61b95ff1a27b7002624e5d Mon Sep 17 00:00:00 2001 From: Rindbee Date: Sun, 30 Apr 2023 10:54:50 +0800 Subject: [PATCH] Fix calculation bug with `TextEdit::get_line_height()` When `get_line_height()` is less than `1`, there is no visible text. So limit the return value of `get_line_height()` to **not less** than `1` for calculation. (cherry picked from commit 391bce44b75b345e33347d28de49608d5850e7a6) --- doc/classes/TextEdit.xml | 3 ++- scene/gui/text_edit.cpp | 5 ++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/doc/classes/TextEdit.xml b/doc/classes/TextEdit.xml index 7a5c485419..fe4266fd48 100644 --- a/doc/classes/TextEdit.xml +++ b/doc/classes/TextEdit.xml @@ -347,7 +347,8 @@ - Returns the height of a largest line. + Returns the maximum value of the line height among all lines. + [b]Note:[/b] The return value is influenced by [theme_item line_spacing] and [theme_item font_size]. And it will not be less than [code]1[/code]. diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index 310177dda7..9eee517780 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -3001,6 +3001,9 @@ void TextEdit::_update_caches() { outline_color = get_theme_color(SNAME("font_outline_color")); line_spacing = get_theme_constant(SNAME("line_spacing")); + if (text.get_line_height() + line_spacing < 1) { + WARN_PRINT("Line height is too small, please increase font_size and/or line_spacing"); + } background_color = get_theme_color(SNAME("background_color")); current_line_color = get_theme_color(SNAME("current_line_color")); @@ -3470,7 +3473,7 @@ int TextEdit::get_line_width(int p_line, int p_wrap_index) const { } int TextEdit::get_line_height() const { - return text.get_line_height() + line_spacing; + return MAX(text.get_line_height() + line_spacing, 1); } int TextEdit::get_indent_level(int p_line) const {