From 93e13a9f7cc5612fea1dd9328ead7bcfa901be04 Mon Sep 17 00:00:00 2001
From: Sebastian Krzyszkowiak <dos@dosowisko.net>
Date: Sun, 10 Sep 2023 19:50:58 +0200
Subject: [PATCH] py,st3m: MenuItemAppLaunch: Scroll too long labels into view

I believe this concludes the scrolling label saga.
---
 python_payload/st3m/application.py | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/python_payload/st3m/application.py b/python_payload/st3m/application.py
index aeea0dbcac..560f1f0d7c 100644
--- a/python_payload/st3m/application.py
+++ b/python_payload/st3m/application.py
@@ -18,6 +18,7 @@ import stat
 import sys
 import sys_display
 import random
+from math import sin
 
 log = Log(__name__)
 
@@ -320,6 +321,8 @@ class MenuItemAppLaunch(MenuItem):
     def __init__(self, bundle: BundleMetadata):
         self._bundle = bundle
         self._instance: Optional[Application] = None
+        self._scroll_pos = 0.0
+        self._highlighted = False
 
     def press(self, vm: Optional[ViewManager]) -> None:
         if vm is None:
@@ -340,6 +343,21 @@ class MenuItemAppLaunch(MenuItem):
     def label(self) -> str:
         return self._bundle.name
 
+    def highlight(self, active: bool) -> None:
+        self._highlighted = active
+        self._scroll_pos = 0.0
+
+    def draw(self, ctx: Context) -> None:
+        ctx.save()
+        if self._highlighted and (width := ctx.text_width(self.label())) > 220:
+            ctx.translate(sin(self._scroll_pos) * (width - 220) / 2, 0)
+        super().draw(ctx)
+        ctx.restore()
+
+    def think(self, ins: InputState, delta_ms: int) -> None:
+        if self._highlighted:
+            self._scroll_pos += delta_ms / 1000
+
 
 class BundleManager:
     """
-- 
GitLab