From 338809575ea62ea1c1280931c1ba7bbaea63eb6e Mon Sep 17 00:00:00 2001
From: Rahix <rahix@rahix.de>
Date: Sun, 11 Apr 2021 23:00:20 +0200
Subject: [PATCH] fix(personal_state): Use simple_menu drawing method

Instead of duplicating the drawing code in the personal state menu,
reuse the method from the parent class.  This reduces code duplication
but most importantly means the personal state app can benefit from fixes
in the "upstream" code.

Concretely, due to the changes related to ctx, this fixes visual
artifacts produced by the "custom" rendering code (black areas to the
right of the text).
---
 preload/apps/personal_state/__init__.py | 30 ++++++++++++++++---------
 1 file changed, 19 insertions(+), 11 deletions(-)

diff --git a/preload/apps/personal_state/__init__.py b/preload/apps/personal_state/__init__.py
index f636e0c4..98dfbe80 100644
--- a/preload/apps/personal_state/__init__.py
+++ b/preload/apps/personal_state/__init__.py
@@ -26,24 +26,32 @@ class StateMenu(simple_menu.Menu):
         personal_state.set(item[1], True)
         os.exit()
 
+    def entry2name(self, value):
+        return value[0]
+
     def draw_entry(self, item, index, offset):
         if item[1] == personal_state.NO_CONTACT:
-            bg = color.RED
-            fg = color.WHITE
+            self.color_1 = color.RED
+            self.color_2 = color.RED
+            self.color_text = color.WHITE
         elif item[1] == personal_state.CHAOS:
-            bg = color.CHAOSBLUE
-            fg = color.CHAOSBLUE_DARK
+            self.color_1 = color.CHAOSBLUE
+            self.color_2 = color.CHAOSBLUE
+            self.color_text = color.CHAOSBLUE_DARK
         elif item[1] == personal_state.COMMUNICATION:
-            bg = color.COMMYELLOW
-            fg = color.COMMYELLOW_DARK
+            self.color_1 = color.COMMYELLOW
+            self.color_2 = color.COMMYELLOW
+            self.color_text = color.COMMYELLOW_DARK
         elif item[1] == personal_state.CAMP:
-            bg = color.CAMPGREEN
-            fg = color.CAMPGREEN_DARK
+            self.color_1 = color.CAMPGREEN
+            self.color_2 = color.CAMPGREEN
+            self.color_text = color.CAMPGREEN_DARK
         else:
-            bg = color.Color(100, 100, 100)
-            fg = color.Color(200, 200, 200)
+            self.color_1 = color.Color(100, 100, 100)
+            self.color_2 = color.Color(100, 100, 100)
+            self.color_text = color.Color(200, 200, 200)
 
-        self.disp.print(" " + str(item[0]) + " " * 9, posy=offset, fg=fg, bg=bg)
+        super().draw_entry(item, index, offset)
 
 
 if __name__ == "__main__":
-- 
GitLab