From 55817704cf5d39b683affc457b1c2cfdbcdf90e3 Mon Sep 17 00:00:00 2001 From: Rahix <rahix@rahix.de> Date: Fri, 3 Jan 2020 21:02:36 +0100 Subject: [PATCH] fix(simple-menu): Properly draw menu entries Instead of an ugly hack where spaces are used to pad the entries background colors, properly draw a rectangle and the text above it. No visual change. Signed-off-by: Rahix <rahix@rahix.de> --- pycardium/modules/py/simple_menu.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/pycardium/modules/py/simple_menu.py b/pycardium/modules/py/simple_menu.py index 7bb05009..b4b27ef5 100644 --- a/pycardium/modules/py/simple_menu.py +++ b/pycardium/modules/py/simple_menu.py @@ -222,22 +222,24 @@ class Menu: """ string = self.entry2name(value) - if offset != 20 or len(string) < 10: - string = " " + string + " " * 9 - else: + if offset == 20 and len(string) >= 10: # Slowly scroll entry to the side time_offset = (utime.time_ms() - self.select_time) // int( self.scroll_speed * 1000 ) time_offset = time_offset % (len(string) - 7) - 1 time_offset = min(len(string) - 10, max(0, time_offset)) - string = " " + string[time_offset:] - + string = string[time_offset:] + + self.disp.rect( + 0, + offset, + 180, + offset + 20, + col=self.color_1 if index % 2 == 0 else self.color_2, + ) self.disp.print( - string, - posy=offset, - fg=self.color_text, - bg=self.color_1 if index % 2 == 0 else self.color_2, + string, posx=14, posy=offset, fg=self.color_text, bg=None, ) def draw_menu(self, offset=0): -- GitLab