Allow multiline summaries
This commit is contained in:
parent
0ba08f3d09
commit
f8c6d00257
@ -39,6 +39,31 @@ def draw_format_infos(infos, width, height, fnt_R, fnt_B, label_margin, align_he
|
||||
|
||||
return image
|
||||
|
||||
def display_longtext(draw, pos, text, font, maxwidth=9999, **kwargs):
|
||||
x,y = pos
|
||||
words = text.split(" ")
|
||||
|
||||
lines = []
|
||||
cur = ""
|
||||
while len(words) > 0:
|
||||
added = (" " if len(cur) > 0 else "") + words[0]
|
||||
width = font.getsize(cur + added)[0]
|
||||
if width < maxwidth:
|
||||
words.pop(0)
|
||||
cur += added
|
||||
else:
|
||||
lines.append(cur)
|
||||
cur = words.pop(0)
|
||||
|
||||
if len(cur) > 0:
|
||||
lines.append(cur)
|
||||
|
||||
line_height = font.getsize("test")[1]
|
||||
y -= line_height * len(lines) / 2
|
||||
for line in lines:
|
||||
draw.text((x,y), line, font=font, **kwargs)
|
||||
y += line_height
|
||||
|
||||
class WeatherToolbarModule:
|
||||
|
||||
def __init__(self):
|
||||
@ -106,11 +131,7 @@ class WeatherJumboCurrentModule:
|
||||
|
||||
dayweather = WeatherAPI().get_hourly()
|
||||
|
||||
draw.text(
|
||||
(width*self.middle_align, height/1.6),
|
||||
dayweather["summary"],
|
||||
fill="black", anchor="lt", font=fnt_Rig
|
||||
)
|
||||
display_longtext(draw, (width*self.middle_align, height/1.28), dayweather["summary"], fill="black", anchor="lm", font=fnt_Rig, maxwidth=(1-self.middle_align)*width)
|
||||
|
||||
return image
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user