diff options
author | bruvzg <7645683+bruvzg@users.noreply.github.com> | 2020-11-30 11:48:42 +0200 |
---|---|---|
committer | bruvzg <7645683+bruvzg@users.noreply.github.com> | 2020-12-06 20:30:59 +0200 |
commit | a458e901791818babe198c0177e0a2e851f821c1 (patch) | |
tree | e061646c16eadcc5c87a050698b4b33f660b709c /scene/gui/label.cpp | |
parent | d834789f475d431b10dcaef8804cd75dcd8b47dd (diff) |
[Complex Text Layouts] Adds missing Font::SPACING_* to the Label, LineEdit, TextEdit, TextLine and TextParagraph.
Fixes oversized editor control height (default editor spacing is negative) and control size changing when text is set.
Diffstat (limited to 'scene/gui/label.cpp')
-rw-r--r-- | scene/gui/label.cpp | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/scene/gui/label.cpp b/scene/gui/label.cpp index e83c062e8a..7570094ff5 100644 --- a/scene/gui/label.cpp +++ b/scene/gui/label.cpp @@ -64,16 +64,17 @@ bool Label::is_uppercase() const { } int Label::get_line_height(int p_line) const { + Ref<Font> font = get_theme_font("font"); if (p_line >= 0 && p_line < lines_rid.size()) { - return TS->shaped_text_get_size(lines_rid[p_line]).y; + return TS->shaped_text_get_size(lines_rid[p_line]).y + font->get_spacing(Font::SPACING_TOP) + font->get_spacing(Font::SPACING_BOTTOM); } else if (lines_rid.size() > 0) { int h = 0; for (int i = 0; i < lines_rid.size(); i++) { - h = MAX(h, TS->shaped_text_get_size(lines_rid[i]).y); + h = MAX(h, TS->shaped_text_get_size(lines_rid[i]).y) + font->get_spacing(Font::SPACING_TOP) + font->get_spacing(Font::SPACING_BOTTOM); } return h; } else { - return get_theme_font("font")->get_height(get_theme_font_size("font_size")); + return font->get_height(get_theme_font_size("font_size")); } } @@ -138,6 +139,7 @@ void Label::_shape() { void Label::_update_visible() { int line_spacing = get_theme_constant("line_spacing", "Label"); Ref<StyleBox> style = get_theme_stylebox("normal", "Label"); + Ref<Font> font = get_theme_font("font"); int lines_visible = lines_rid.size(); if (max_lines_visible >= 0 && lines_visible > max_lines_visible) { @@ -147,7 +149,7 @@ void Label::_update_visible() { minsize.height = 0; int last_line = MIN(lines_rid.size(), lines_visible + lines_skipped); for (int64_t i = lines_skipped; i < last_line; i++) { - minsize.height += TS->shaped_text_get_size(lines_rid[i]).y + line_spacing; + minsize.height += TS->shaped_text_get_size(lines_rid[i]).y + font->get_spacing(Font::SPACING_TOP) + font->get_spacing(Font::SPACING_BOTTOM) + line_spacing; if (minsize.height > (get_size().height - style->get_minimum_size().height + line_spacing)) { break; } @@ -197,7 +199,7 @@ void Label::_notification(int p_what) { // Get number of lines to fit to the height. for (int64_t i = lines_skipped; i < lines_rid.size(); i++) { - total_h += TS->shaped_text_get_size(lines_rid[i]).y + line_spacing; + total_h += TS->shaped_text_get_size(lines_rid[i]).y + font->get_spacing(Font::SPACING_TOP) + font->get_spacing(Font::SPACING_BOTTOM) + line_spacing; if (total_h > (get_size().height - style->get_minimum_size().height + line_spacing)) { break; } @@ -213,7 +215,7 @@ void Label::_notification(int p_what) { // Get real total height. total_h = 0; for (int64_t i = lines_skipped; i < last_line; i++) { - total_h += TS->shaped_text_get_size(lines_rid[i]).y + line_spacing; + total_h += TS->shaped_text_get_size(lines_rid[i]).y + font->get_spacing(Font::SPACING_TOP) + font->get_spacing(Font::SPACING_BOTTOM) + line_spacing; } int vbegin = 0, vsep = 0; @@ -263,7 +265,7 @@ void Label::_notification(int p_what) { ofs.y = style->get_offset().y + vbegin; for (int i = lines_skipped; i < last_line; i++) { ofs.x = 0; - ofs.y += TS->shaped_text_get_ascent(lines_rid[i]); + ofs.y += TS->shaped_text_get_ascent(lines_rid[i]) + font->get_spacing(Font::SPACING_TOP); switch (align) { case ALIGN_FILL: case ALIGN_LEFT: { @@ -337,7 +339,7 @@ void Label::_notification(int p_what) { } } - ofs.y += TS->shaped_text_get_descent(lines_rid[i]) + vsep + line_spacing; + ofs.y += TS->shaped_text_get_descent(lines_rid[i]) + vsep + line_spacing + font->get_spacing(Font::SPACING_BOTTOM); } } @@ -381,12 +383,13 @@ int Label::get_line_count() const { } int Label::get_visible_line_count() const { + Ref<Font> font = get_theme_font("font"); Ref<StyleBox> style = get_theme_stylebox("normal"); int line_spacing = get_theme_constant("line_spacing"); int lines_visible = 0; float total_h = 0; for (int64_t i = lines_skipped; i < lines_rid.size(); i++) { - total_h += TS->shaped_text_get_size(lines_rid[i]).y + line_spacing; + total_h += TS->shaped_text_get_size(lines_rid[i]).y + font->get_spacing(Font::SPACING_TOP) + font->get_spacing(Font::SPACING_BOTTOM) + line_spacing; if (total_h > (get_size().height - style->get_minimum_size().height + line_spacing)) { break; } |