Skip to content
Snippets Groups Projects
Commit d2b100d3 authored by schneider's avatar schneider
Browse files

ui: rename ViewWithInputState to BaseView

parent 48b33096
No related branches found
No related tags found
No related merge requests found
...@@ -294,20 +294,20 @@ Example 2b: Easier view management ...@@ -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 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: `InputController` and handles the ignoring of extra presses:
.. code-block:: python .. code-block:: python
from st3m.ui.view import ViewWithInputState from st3m.ui.view import BaseView
import st3m.run import st3m.run
class SecondScreen(ViewWithInputState): class SecondScreen(BaseView):
def __init__(self) -> None: def __init__(self) -> None:
super().__init__() super().__init__()
def on_enter(self, vm: Optional[ViewManager]) -> None: 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: def draw(self, ctx: Context) -> None:
# Paint the background black # Paint the background black
...@@ -316,13 +316,13 @@ there is a special view which helps you with that: :py:class:`ViewWithInputState ...@@ -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() ctx.rgb(0, 255, 0).rectangle(-20, -20, 40, 40).fill()
def think(self, ins: InputState, delta_ms: int) -> None: 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: if self.input.right_shoulder.middle.pressed:
self.vm.pop() self.vm.pop()
class Example(ViewWithInputState): class Example(BaseView):
def __init__(self) -> None: def __init__(self) -> None:
super().__init__() super().__init__()
...@@ -334,10 +334,10 @@ there is a special view which helps you with that: :py:class:`ViewWithInputState ...@@ -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: 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: 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: if self.input.right_shoulder.middle.pressed:
self.vm.push(SecondScreen()) self.vm.push(SecondScreen())
...@@ -360,12 +360,12 @@ Let's introduce the final class you should actually be using for application dev ...@@ -360,12 +360,12 @@ Let's introduce the final class you should actually be using for application dev
from st3m.application import Application from st3m.application import Application
import st3m.run import st3m.run
class SecondScreen(ViewWithInputState): class SecondScreen(BaseView):
def __init__(self) -> None: def __init__(self) -> None:
super().__init__() super().__init__()
def on_enter(self, vm: Optional[ViewManager]) -> None: 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: def draw(self, ctx: Context) -> None:
# Paint the background black # Paint the background black
...@@ -374,7 +374,7 @@ Let's introduce the final class you should actually be using for application dev ...@@ -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() ctx.rgb(0, 255, 0).rectangle(-20, -20, 40, 40).fill()
def think(self, ins: InputState, delta_ms: int) -> None: 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: if self.input.right_shoulder.middle.pressed:
self.vm.pop() self.vm.pop()
......
from st3m.ui.view import ( from st3m.ui.view import (
ViewWithInputState, BaseView,
ViewTransitionSwipeRight, ViewTransitionSwipeRight,
ViewTransitionSwipeLeft, ViewTransitionSwipeLeft,
ViewManager, ViewManager,
...@@ -18,7 +18,7 @@ import sys ...@@ -18,7 +18,7 @@ import sys
log = Log(__name__) log = Log(__name__)
class Application(ViewWithInputState): class Application(BaseView):
def __init__(self, name: str = __name__) -> None: def __init__(self, name: str = __name__) -> None:
self._name = name self._name = name
super().__init__() super().__init__()
......
...@@ -5,7 +5,7 @@ from st3m import logging ...@@ -5,7 +5,7 @@ from st3m import logging
from st3m.goose import ABCBase, abstractmethod, List, Optional from st3m.goose import ABCBase, abstractmethod, List, Optional
from st3m.input import InputState, InputController from st3m.input import InputState, InputController
from st3m.ui.view import ( from st3m.ui.view import (
ViewWithInputState, BaseView,
View, View,
ViewManager, ViewManager,
ViewTransitionSwipeLeft, ViewTransitionSwipeLeft,
...@@ -108,7 +108,7 @@ class MenuItemBack(MenuItem): ...@@ -108,7 +108,7 @@ class MenuItemBack(MenuItem):
ctx.text("\ue5c4") ctx.text("\ue5c4")
class MenuController(ViewWithInputState): class MenuController(BaseView):
""" """
Base class for menus. Reacts to canonical inputs (left shoulder button) to Base class for menus. Reacts to canonical inputs (left shoulder button) to
move across and select actions from the menu. move across and select actions from the menu.
......
...@@ -10,7 +10,7 @@ class View(Responder): ...@@ -10,7 +10,7 @@ class View(Responder):
lifecycle in terms of being foregrounded or backgrounded. lifecycle in terms of being foregrounded or backgrounded.
These signals can be used to alter input processing, se the These signals can be used to alter input processing, se the
ViewWithInputState class. BaseView class.
""" """
def on_enter(self, vm: Optional["ViewManager"]) -> None: def on_enter(self, vm: Optional["ViewManager"]) -> None:
...@@ -21,7 +21,7 @@ class View(Responder): ...@@ -21,7 +21,7 @@ class View(Responder):
pass pass
class ViewWithInputState(View): class BaseView(View):
""" """
A base class helper for implementing views which respond to inputs and who A base class helper for implementing views which respond to inputs and who
want to do their own, separate input processing. want to do their own, separate input processing.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment