Fix jumpy text

Fixes #2.
This commit is contained in:
Markus Koch 2020-07-13 18:10:48 +02:00
parent eb968ec16f
commit 368ceb4373

View File

@ -44,17 +44,19 @@ class display_playback(display):
self.title = title self.title = title
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): if (w > self.width): # Check the text is short enough to be static
self.title += ". " # Wraparound for scrolling (pt1) self.title += "."
self.title_scroll_max,h = self.d.textsize(self.title, font=self.font_title)
self.title_scroll = self.title_scroll_max - 10
self.title += self.title # Wraparound for scrolling (pt2)
# Prerender
w,h = self.d.textsize(self.title, font=self.font_title) w,h = self.d.textsize(self.title, font=self.font_title)
self.title_img = Image.new('1', (w, h), color = not self.fg) w += 10 # Spacing between repetitions
self.title_scroll_max = w
self.title_scroll = self.title_scroll_max - 10
# Prerender
fw = w + self.width
self.title_img = Image.new('1', (fw, h), color = not self.fg)
font_shift = 5 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 = self.title_img.crop((0,0,w,h-font_shift)) self.title_img.paste(self.title_img, (w,0))
self.title_img = self.title_img.crop((0,0,fw,h-font_shift))
else: else:
self.title_scroll = 0 self.title_scroll = 0
self.title_scroll_max = -1 self.title_scroll_max = -1