diff --git a/docs/badge/application-programming.rst b/docs/badge/application-programming.rst index 028ad53a5ed9b1cbfff7ab1f33c7980ca7739f96..d8bc843116d9627234184aa096cb167030b462c9 100644 --- a/docs/badge/application-programming.rst +++ b/docs/badge/application-programming.rst @@ -294,20 +294,20 @@ Example 2b: Easier view management ---------------------------------- The idea that a button (physical or captouch) is used to enter / exit a view is so universal that -there is a special view which helps you with that: :py:class:`ViewWithInputState`. It integrates an +there is a special view which helps you with that: :py:class:`BaseView`. It integrates an `InputController` and handles the ignoring of extra presses: .. code-block:: python - from st3m.ui.view import ViewWithInputState + from st3m.ui.view import BaseView import st3m.run - class SecondScreen(ViewWithInputState): + class SecondScreen(BaseView): def __init__(self) -> None: super().__init__() def on_enter(self, vm: Optional[ViewManager]) -> None: - super().on_enter(vm) # Let ViewWithInputState do its thing + super().on_enter(vm) # Let BaseView do its thing def draw(self, ctx: Context) -> None: # Paint the background black @@ -316,13 +316,13 @@ there is a special view which helps you with that: :py:class:`ViewWithInputState ctx.rgb(0, 255, 0).rectangle(-20, -20, 40, 40).fill() def think(self, ins: InputState, delta_ms: int) -> None: - super().think(ins, delta_ms) # Let ViewWithInputState do its thing + super().think(ins, delta_ms) # Let BaseView do its thing if self.input.right_shoulder.middle.pressed: self.vm.pop() - class Example(ViewWithInputState): + class Example(BaseView): def __init__(self) -> None: super().__init__() @@ -334,10 +334,10 @@ there is a special view which helps you with that: :py:class:`ViewWithInputState def on_enter(self, vm: Optional[ViewManager]) -> None: - super().on_enter(vm) # Let ViewWithInputState do its thing + super().on_enter(vm) # Let BaseView do its thing def think(self, ins: InputState, delta_ms: int) -> None: - super().think(ins, delta_ms) # Let ViewWithInputState do its thing + super().think(ins, delta_ms) # Let BaseView do its thing if self.input.right_shoulder.middle.pressed: self.vm.push(SecondScreen()) @@ -360,12 +360,12 @@ Let's introduce the final class you should actually be using for application dev from st3m.application import Application import st3m.run - class SecondScreen(ViewWithInputState): + class SecondScreen(BaseView): def __init__(self) -> None: super().__init__() def on_enter(self, vm: Optional[ViewManager]) -> None: - super().on_enter(vm) # Let ViewWithInputState do its thing + super().on_enter(vm) # Let BaseView do its thing def draw(self, ctx: Context) -> None: # Paint the background black @@ -374,7 +374,7 @@ Let's introduce the final class you should actually be using for application dev ctx.rgb(0, 255, 0).rectangle(-20, -20, 40, 40).fill() def think(self, ins: InputState, delta_ms: int) -> None: - super().think(ins, delta_ms) # Let ViewWithInputState do its thing + super().think(ins, delta_ms) # Let BaseView do its thing if self.input.right_shoulder.middle.pressed: self.vm.pop() diff --git a/python_payload/st3m/application.py b/python_payload/st3m/application.py index 79842d1da1daabc6ef7e6dcc69732d5d9281b95b..576e7cfe54d0b270bd799a25ecd06698bd073294 100644 --- a/python_payload/st3m/application.py +++ b/python_payload/st3m/application.py @@ -1,5 +1,5 @@ from st3m.ui.view import ( - ViewWithInputState, + BaseView, ViewTransitionSwipeRight, ViewTransitionSwipeLeft, ViewManager, @@ -18,7 +18,7 @@ import sys log = Log(__name__) -class Application(ViewWithInputState): +class Application(BaseView): def __init__(self, name: str = __name__) -> None: self._name = name super().__init__() diff --git a/python_payload/st3m/ui/menu.py b/python_payload/st3m/ui/menu.py index 174d7a11069a12bbe0e7179524d48fed454b7484..da90f6583321b1abd491ffe60010dcb9dbd40efc 100644 --- a/python_payload/st3m/ui/menu.py +++ b/python_payload/st3m/ui/menu.py @@ -5,7 +5,7 @@ from st3m import logging from st3m.goose import ABCBase, abstractmethod, List, Optional from st3m.input import InputState, InputController from st3m.ui.view import ( - ViewWithInputState, + BaseView, View, ViewManager, ViewTransitionSwipeLeft, @@ -108,7 +108,7 @@ class MenuItemBack(MenuItem): ctx.text("\ue5c4") -class MenuController(ViewWithInputState): +class MenuController(BaseView): """ Base class for menus. Reacts to canonical inputs (left shoulder button) to move across and select actions from the menu. diff --git a/python_payload/st3m/ui/view.py b/python_payload/st3m/ui/view.py index 42c91a4b4338a8ab4175f363cd66b153e78b2873..c0b2ee5f11edcc46c0b6f7dc313b9b92260110b3 100644 --- a/python_payload/st3m/ui/view.py +++ b/python_payload/st3m/ui/view.py @@ -10,7 +10,7 @@ class View(Responder): lifecycle in terms of being foregrounded or backgrounded. These signals can be used to alter input processing, se the - ViewWithInputState class. + BaseView class. """ def on_enter(self, vm: Optional["ViewManager"]) -> None: @@ -21,7 +21,7 @@ class View(Responder): pass -class ViewWithInputState(View): +class BaseView(View): """ A base class helper for implementing views which respond to inputs and who want to do their own, separate input processing.