From 0d436a104a4fbb7ea7e433c34fe89813ab098a77 Mon Sep 17 00:00:00 2001 From: Jonty Wareing Date: Tue, 2 Jun 2026 17:47:56 +0100 Subject: [PATCH] Wrap notifications based on words if we can Because it rea lly sucks when they are wrappe d in the middle of a word --- modules/app_components/notification.py | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/modules/app_components/notification.py b/modules/app_components/notification.py index fb02e2de..b466a378 100644 --- a/modules/app_components/notification.py +++ b/modules/app_components/notification.py @@ -44,18 +44,22 @@ def update(self, delta): def get_text_for_line(self, ctx, text, line): width_for_line = 240 - if line < (len(self.width_limits)): + if line < len(self.width_limits): width_for_line = self.width_limits[line] - extra_text = "" - text_that_fits = text - text_width = ctx.text_width(text_that_fits) - while text_width > width_for_line: - character = text_that_fits[-1] - text_that_fits = text_that_fits[:-1] - extra_text = character + extra_text - text_width = ctx.text_width(text_that_fits) - return text_that_fits, extra_text + split = len(text) + for i in range(1, len(text) + 1): + # Attempt to break on a word boundary + if i < len(text) and text[i] == " ": + split = i + 1 + + # But if there are no spaces, just hard break + if ctx.text_width(text[:i]) > width_for_line: + if split == len(text): + split = i + break + + return text[:split], text[split:] def draw(self, ctx): if not self._is_closed():