sw: Implement text centering and fix short text

This commit is contained in:
Markus Koch 2020-08-08 18:17:10 +02:00
parent 91af51f51b
commit 69ae7e5d42

View File

@ -40,9 +40,10 @@ class display_playback(display):
self.title_img = Image.new('1', (0, 0), color = not self.fg) self.title_img = Image.new('1', (0, 0), color = not self.fg)
self.bar_redraw = True self.bar_redraw = True
def update_text(self, title): def update_text(self, title, center=False):
self.title = title self.title = title
font_shift = 5
w,h = self.d.textsize(self.title, font=self.font_title) w,h = self.d.textsize(self.title, font=self.font_title)
if (w > self.width): # Check the text is short enough to be static if (w > self.width): # Check the text is short enough to be static
self.title += "." self.title += "."
@ -53,11 +54,17 @@ class display_playback(display):
# Prerender # Prerender
fw = w + self.width fw = w + self.width
self.title_img = Image.new('1', (fw, h), color = not self.fg) self.title_img = Image.new('1', (fw, h), color = not self.fg)
font_shift = 5
ImageDraw.Draw(self.title_img).text((0,-font_shift), self.title, font=self.font_title, fill=self.fg) ImageDraw.Draw(self.title_img).text((0,-font_shift), self.title, font=self.font_title, fill=self.fg)
self.title_img.paste(self.title_img, (w,0)) self.title_img.paste(self.title_img, (w,0))
self.title_img = self.title_img.crop((0,0,fw,h-font_shift)) self.title_img = self.title_img.crop((0,0,fw,h-font_shift))
else: else:
if (center):
x_shift = (self.width - w) / 2
else:
x_shift = 0;
w = self.width
self.title_img = Image.new('1', (w, h), color = not self.fg)
ImageDraw.Draw(self.title_img).text((x_shift,-font_shift), self.title, font=self.font_title, fill=self.fg)
self.title_scroll = 0 self.title_scroll = 0
self.title_scroll_max = -1 self.title_scroll_max = -1