Merge pull request #34867 from volzhs/calculate-label-size-2
Calculate label size more accurately
This commit is contained in:
commit
e2a6cae0c7
1 changed files with 4 additions and 7 deletions
|
@ -103,8 +103,7 @@ void Label::_notification(int p_what) {
|
||||||
|
|
||||||
int lines_visible = (size.y + line_spacing) / font_h;
|
int lines_visible = (size.y + line_spacing) / font_h;
|
||||||
|
|
||||||
// ceiling to ensure autowrapping does not cut text
|
real_t space_w = font->get_char_size(' ').width;
|
||||||
int space_w = Math::ceil(font->get_char_size(' ').width);
|
|
||||||
int chars_total = 0;
|
int chars_total = 0;
|
||||||
|
|
||||||
int vbegin = 0, vsep = 0;
|
int vbegin = 0, vsep = 0;
|
||||||
|
@ -390,10 +389,9 @@ void Label::regenerate_word_cache() {
|
||||||
|
|
||||||
real_t current_word_size = 0;
|
real_t current_word_size = 0;
|
||||||
int word_pos = 0;
|
int word_pos = 0;
|
||||||
int line_width = 0;
|
real_t line_width = 0;
|
||||||
int space_count = 0;
|
int space_count = 0;
|
||||||
// ceiling to ensure autowrapping does not cut text
|
real_t space_width = font->get_char_size(' ').width;
|
||||||
int space_width = Math::ceil(font->get_char_size(' ').width);
|
|
||||||
int line_spacing = get_constant("line_spacing");
|
int line_spacing = get_constant("line_spacing");
|
||||||
line_count = 1;
|
line_count = 1;
|
||||||
total_char_cache = 0;
|
total_char_cache = 0;
|
||||||
|
@ -454,10 +452,9 @@ void Label::regenerate_word_cache() {
|
||||||
if (current_word_size == 0) {
|
if (current_word_size == 0) {
|
||||||
word_pos = i;
|
word_pos = i;
|
||||||
}
|
}
|
||||||
// ceiling to ensure autowrapping does not cut text
|
|
||||||
char_width = 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;
|
current_word_size += char_width;
|
||||||
line_width += Math::ceil(char_width);
|
line_width += char_width;
|
||||||
total_char_cache++;
|
total_char_cache++;
|
||||||
|
|
||||||
// allow autowrap to cut words when they exceed line width
|
// allow autowrap to cut words when they exceed line width
|
||||||
|
|
Loading…
Reference in a new issue