ScreenManager v1.0.0
A lightweight C++ library for managing application screens, navigation, transitions and display timing.
Public Member Functions | List of all members
ScreenManager Class Reference

Description

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...
 
template<typename T >
bool registerScreen (ScreenId id, T *screen)
 Register a screen created externally. More...
 
template<typename T >
bool registerScreen (ScreenId id)
 Register a managed screen (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 ()
 Get the currently set Fps. More...
 
bool isCurrent (const ScreenId id)
 Return true if passed id is that of the current screen. More...
 
bool isPrevious (ScreenId id)
 Return true if passed id is that of the previous screen. More...
 
IManagedScreengetCurrent ()
 Get the current screen. More...
 
ScreenId getPreviousId ()
 Get the previous screen ID. More...
 
bool haveScreen (ScreenId id)
 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 (ScreenId id)
 Set the Initial Screen. More...
 

Member Function Documentation

◆ addRouter()

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.

Parameters
router

◆ getCurrent()

IManagedScreen * ScreenManager::getCurrent ( )

Get the current screen.

Returns
IManagedScreen* or nullptr

◆ getFps()

uint8_t ScreenManager::getFps ( )
inline

Get the currently set Fps.

Returns
uint8_t

◆ getPreviousId()

ScreenId ScreenManager::getPreviousId ( )

Get the previous screen ID.

Returns
Previous screen ID or 0

◆ haveScreen()

bool ScreenManager::haveScreen ( ScreenId  id)

Check if a screen has been added and exists.

Parameters
idThe name or id used to register the screen
Returns
true Screen is available to get.
false Screen does not exist/

◆ isCurrent()

bool ScreenManager::isCurrent ( const ScreenId  id)

Return true if passed id is that of the current screen.

Parameters
id
Returns
true
false

◆ isPrevious()

bool ScreenManager::isPrevious ( ScreenId  id)

Return true if passed id is that of the previous screen.

Parameters
id
Returns
true
false

◆ registerScreen() [1/2]

template<typename T >
bool ScreenManager::registerScreen ( ScreenId  id)
inline

Register a managed screen (ScreenManager will create and delete the screen)

Usage: screenManager.registerScreen<SettingsScreen>(20);

Template Parameters
T
Parameters
idA uint8_t used to identify this screen

◆ registerScreen() [2/2]

template<typename T >
bool ScreenManager::registerScreen ( ScreenId  id,
T *  screen 
)
inline

Register a screen created externally.

Usage: screenManager.registerScreen(&home, 11);

Template Parameters
T
Parameters
screen
idA uint8_t used to identify this screen

◆ requestScreen() [1/2]

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.

Parameters
nextScreen

◆ requestScreen() [2/2]

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.

Parameters
intentCan be Init, Back, Next, Auto or a specific screen name. Screen router resolves screen name.

◆ setFps()

void ScreenManager::setFps ( uint8_t  fps)
inline

Set the FPS (Frames Per Second) for draw() to be called (default is 10)

Parameters
fps1-255 FPS. 0 means IManagedScreen::draw() will never be called.

◆ setInitialScreen()

bool ScreenManager::setInitialScreen ( ScreenId  id)

Set the Initial Screen.

By default the first registered screen is the init screen

Parameters
id
Returns
true Initial screen has been set
false Initial screen not set (is not a registered screen)

◆ update()

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().

Parameters
nowMsA timer value used to determine when draw() is called (based on the setFps())

The documentation for this class was generated from the following files: