Introduce maxlines for alerts

This commit is contained in:
nemunaire 2023-08-30 16:00:52 +02:00
parent 1cae3824b2
commit 67008b9c57
1 changed files with 8 additions and 2 deletions

View File

@ -135,7 +135,8 @@ class AlertsModule:
(self.icon_size - 5, align),
alert["description"],
fill="white", font=fnt_R,
maxwidth=width-self.icon_size-5
maxwidth=width-self.icon_size-5,
maxlines=1 if "oneline" in alert and alert["oneline"] else 99,
)
return align + 7
@ -196,7 +197,7 @@ class AlertsModule:
return image, more_alerts
def display_longtext(draw, pos, text, font, anchor="lt", maxwidth=9999, **kwargs):
def display_longtext(draw, pos, text, font, anchor="lt", maxwidth=9999, maxlines=999, **kwargs):
x,y = pos
lines = []
@ -218,6 +219,11 @@ def display_longtext(draw, pos, text, font, anchor="lt", maxwidth=9999, **kwargs
if len(cur) > 0:
lines.append(cur)
maxlines -= 1
if maxlines <= 0:
lines[-1] += ""
break
line_height = font.getsize("test")[1]
if anchor[1] == "m":
y -= line_height * len(lines) / 2