From 50a8a541541cbe11a666f294dffaaadfc59fc83a Mon Sep 17 00:00:00 2001
From: Sebastian Krzyszkowiak <dos@dosowisko.net>
Date: Sun, 10 Sep 2023 19:50:51 +0200
Subject: [PATCH] py,st3m: MenuController: Let MenuItems know whether they're
 highlighted

---
 python_payload/st3m/ui/menu.py | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/python_payload/st3m/ui/menu.py b/python_payload/st3m/ui/menu.py
index efcc8c5920..a502b69c36 100644
--- a/python_payload/st3m/ui/menu.py
+++ b/python_payload/st3m/ui/menu.py
@@ -46,6 +46,12 @@ class MenuItem(Responder):
         """
         pass
 
+    def highlight(self, active: bool) -> None:
+        """
+        Called when the item starts or stops being highlighted.
+        """
+        pass
+
     def draw(self, ctx: Context) -> None:
         ctx.text(self.label())
 
@@ -197,10 +203,16 @@ class MenuController(BaseView):
 
         self._scroll_controller.think(ins, delta_ms)
 
+        target = self._scroll_controller.target_position()
+
         if self.input.buttons.app.middle.pressed:
             self.select()
         self._parse_state()
 
+        if self._scroll_controller.target_position() != target:
+            self._items[target].highlight(False)
+            self._items[self._scroll_controller.target_position()].highlight(True)
+
     def draw(self, ctx: Context) -> None:
         pass
 
-- 
GitLab