ScreenManager v1.1.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...
 
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...
 

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

Get the current screen or nullptr. ScreenManager::update()` must be called before the initial screen becomes current.

Returns
IManagedScreen* or nullptr

◆ getFps()

uint8_t ScreenManager::getFps ( ) const
inline

Get the currently set Fps.

Returns
uint8_t

◆ getPreviousId()

ScreenId ScreenManager::getPreviousId ( ) const

Get the previous screen ID.

Returns
Previous screen ID or 0

◆ haveScreen()

bool ScreenManager::haveScreen ( const ScreenId  id) const

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) const

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

Parameters
id
Returns
true
false

◆ isPrevious()

bool ScreenManager::isPrevious ( const ScreenId  id) const

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 with a unique ID greater than 0 (ScreenManager will create and delete the screen)

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

Template Parameters
T
Parameters
idA uint8_t used to identify this screen. Must be > 0

◆ registerScreen() [2/2]

bool ScreenManager::registerScreen ( ScreenId  id,
IManagedScreen *  screen 
)
inline

Register a screen created externally with a unique ID greater than 0.

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

Parameters
idA ScreenId (uint8_t) used to identify this screen. Must be > 0
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-250 FPS. 0 means IManagedScreen::draw() will never be called.

◆ setInitialScreen()

bool ScreenManager::setInitialScreen ( const 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().

‍Must be called before trying to access currentScreen()

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: