![]() |
ScreenManager v1.1.0
A lightweight C++ library for managing application screens, navigation, transitions and display timing.
|
The core class that handles registration, transitions and of course, calling the screen's draw() method.
#include <ScreenManager.h>
Public Member Functions | |
| void | begin () |
Called once during setup(). Will call the IManagedScreen::begin() method of all external screens.that have been registered. | |
| void | update (uint32_t nowMs) |
Called from your loop(). Checks if a screen transition has been requested and calls current screen's draw() at set FPS. More... | |
| bool | registerScreen (ScreenId id, IManagedScreen *screen) |
| Register a screen created externally with a unique ID greater than 0. More... | |
| template<typename T > | |
| bool | registerScreen (ScreenId id) |
| Register a managed screen with a unique ID greater than 0 (ScreenManager will create and delete the screen) More... | |
| void | setFps (uint8_t fps) |
| Set the FPS (Frames Per Second) for draw() to be called (default is 10) More... | |
| uint8_t | getFps () const |
| Get the currently set Fps. More... | |
| bool | isCurrent (const ScreenId id) const |
| Return true if passed id is that of the current screen. More... | |
| bool | isPrevious (const ScreenId id) const |
| Return true if passed id is that of the previous screen. More... | |
| IManagedScreen * | getCurrent () const |
Get the current screen or nullptr. ScreenManager::update()` must be called before the initial screen becomes current. More... | |
| ScreenId | getPreviousId () const |
| Get the previous screen ID. More... | |
| bool | haveScreen (const ScreenId id) const |
| Check if a screen has been added and exists. More... | |
| void | requestScreen (const ScreenId nextScreen) |
| Request a transition to a named screen. More... | |
| void | requestScreen (const TransitionIntent &intent) |
| Request a screen transition. More... | |
| void | addRouter (ScreenRouter *router) |
| Add a new router for screen transitions. Routers are called in the order they are added. First to answer wins. More... | |
| bool | setInitialScreen (const ScreenId id) |
| Set the Initial Screen. More... | |
| void ScreenManager::addRouter | ( | ScreenRouter * | router | ) |
Add a new router for screen transitions. Routers are called in the order they are added. First to answer wins.
| router |
| IManagedScreen * ScreenManager::getCurrent | ( | ) | const |
Get the current screen or nullptr. ScreenManager::update()` must be called before the initial screen becomes current.
|
inline |
Get the currently set Fps.
| ScreenId ScreenManager::getPreviousId | ( | ) | const |
Get the previous screen ID.
| bool ScreenManager::haveScreen | ( | const ScreenId | id | ) | const |
Check if a screen has been added and exists.
| id | The name or id used to register the screen |
| bool ScreenManager::isCurrent | ( | const ScreenId | id | ) | const |
Return true if passed id is that of the current screen.
| id |
| bool ScreenManager::isPrevious | ( | const ScreenId | id | ) | const |
Return true if passed id is that of the previous screen.
| id |
|
inline |
Register a managed screen with a unique ID greater than 0 (ScreenManager will create and delete the screen)
Usage: screenManager.registerScreen<SettingsScreen>(20);
| T |
| id | A uint8_t used to identify this screen. Must be > 0 |
|
inline |
Register a screen created externally with a unique ID greater than 0.
Usage: screenManager.registerScreen(11, &home);
| id | A ScreenId (uint8_t) used to identify this screen. Must be > 0 |
| screen |
| void ScreenManager::requestScreen | ( | const ScreenId | nextScreen | ) |
Request a transition to a named screen.
Will be passed to the screen routers (if any) for validation and/or redirect.
| nextScreen |
| void ScreenManager::requestScreen | ( | const TransitionIntent & | intent | ) |
Request a screen transition.
The request will be passed to the screen routers (if any) for validation and/or redirect.
| intent | Can be Init, Back, Next, Auto or a specific screen name. Screen router resolves screen name. |
|
inline |
Set the FPS (Frames Per Second) for draw() to be called (default is 10)
| fps | 1-250 FPS. 0 means IManagedScreen::draw() will never be called. |
| bool ScreenManager::setInitialScreen | ( | const ScreenId | id | ) |
Set the Initial Screen.
By default the first registered screen is the init screen
| id |
| void ScreenManager::update | ( | uint32_t | nowMs | ) |
Called from your loop(). Checks if a screen transition has been requested and calls current screen's draw() at set FPS.
Receives a timer value - in the Arduino Framework this would be millis().
Must be called before trying to access
currentScreen()
| nowMs | A timer value used to determine when draw() is called (based on the setFps()) |