From 727c7bfd5c9559425408d3eefc8a36ec9e11f680 Mon Sep 17 00:00:00 2001 From: EKNr1 Date: Fri, 22 Mar 2024 21:07:26 +0100 Subject: [PATCH] Improved MultilineText. --- pg.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pg.py b/pg.py index 3db3a17..a6e1700 100644 --- a/pg.py +++ b/pg.py @@ -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