Improved MultilineText.

This commit is contained in:
The Wobbler 2024-03-22 21:07:26 +01:00
parent 3aa6cd9904
commit 727c7bfd5c

7
pg.py
View file

@ -264,10 +264,10 @@ class MultilineText:
self.max_chars = max_chars
if char_width is None:
char_width = font.render(".", True, white).get_width() # get the width of a character by the font
char_width = font.render(text, True, white).get_width() // len(text) # get the width of a character by the font
if max_chars is None and not max_width is None:
self.max_width = max_width // char_width
self.max_width = max_width // char_width - 10
self.surface = self.generate_surface()
@ -282,6 +282,7 @@ class MultilineText:
if char == "\n":
lines.append(line)
length = 1
line = ""
else:
line += char
@ -294,6 +295,8 @@ class MultilineText:
lines.append(line)
length = 1
line = ""
if not char == "\n":
line = char