libDaisy
Hardware Library for Daisy
Loading...
Searching...
No Matches
daisy::UI Class Reference

A generic UI system. More...

Detailed Description

A generic UI system.

Author
jelliesen

This system allows you to create complex and dynamic user interfaces with menus, pages and dialogs. It holds a stack of pages. Each page can react to user input on buttons, potentiometers, and encoders while drawing to one or multiple displays, leds or other output devices.

User input is consumed from a UiEventQueue and distributed to the pages from the top down. If a page doesn't handle an event, it will be forwarded to the next page below.

Pages are drawn from the bottom up. Multiple abstract canvases can be used for the drawing, where each canvas could be a graphics display, LEDs, alphanumeric displays, etc. The UI system makes sure that drawing is executed with a constant refresh rate that can be individually specified for each canvas.

#include <UI.h>

Classes

struct  SpecialControlIds
 

Public Member Functions

 UI ()
 
 ~UI ()
 
void Init (UiEventQueue &inputQueue, const SpecialControlIds &specialControlIds, std::initializer_list< UiCanvasDescriptor > canvases, uint16_t primaryOneBitGraphicsDisplayId=invalidCanvasId)
 
void Process ()
 
void Mute (bool shouldBeMuted, bool queueEvents=false)
 
void OpenPage (UiPage &page)
 
void ClosePage (UiPage &page)
 
uint16_t GetPrimaryOneBitGraphicsDisplayId () const
 
SpecialControlIds GetSpecialControlIds () const
 

Static Public Attributes

static constexpr uint16_t invalidCanvasId = uint16_t(-1)
 

Constructor & Destructor Documentation

◆ UI()

daisy::UI::UI ( )

◆ ~UI()

daisy::UI::~UI ( )

Member Function Documentation

◆ ClosePage()

void daisy::UI::ClosePage ( UiPage page)

Called to close a page.

◆ GetPrimaryOneBitGraphicsDisplayId()

uint16_t daisy::UI::GetPrimaryOneBitGraphicsDisplayId ( ) const
inline

If this UI has a canvas that uses a OneBitGraphicsDisplay AND this canvas should be used as the main display for menus, etc. then this function returns the canvas ID of this display. If no such canvas exists, this function returns UI::invalidCanvasId.

◆ GetSpecialControlIds()

SpecialControlIds daisy::UI::GetSpecialControlIds ( ) const
inline

Returns the button IDs, encoder IDs and pot IDs used for special functions.

◆ Init()

void daisy::UI::Init ( UiEventQueue inputQueue,
const SpecialControlIds specialControlIds,
std::initializer_list< UiCanvasDescriptor canvases,
uint16_t  primaryOneBitGraphicsDisplayId = invalidCanvasId 
)

Initializes the UI.

Parameters
inputQueueThe UiEventQueue to read user input events from.
specialControlIdsInformation about the control IDs used for special buttons/encoders/pots.
canvasesA list of UiCanvasDescriptor that define which canvases to use.
primaryOneBitGraphicsDisplayIdThe ID of a OneBitGraphicsDisplay canvas that should be used as the main display. Menus will draw to this canvas. If no such dispaly is available, use Ui::invalidCanvasId.

◆ Mute()

void daisy::UI::Mute ( bool  shouldBeMuted,
bool  queueEvents = false 
)

Call this to temporarily disable processing of user input, e.g. while a project is loading. If queueEvents==true, all user input that happens while muted will be queued up and processed when the mute state is removed. If queueEvents==false, all user input that happens while muted will be discarded.

◆ OpenPage()

void daisy::UI::OpenPage ( UiPage page)

Adds a new UIPage on the top of the stack of UI pages without taking ownership of the object. The new page is set to be visible. The page must stay alive until it was removed from the UI. It's best to have each page statically allocated as a global variable.

◆ Process()

void daisy::UI::Process ( )

Call this regularly to allow processing user input, redraw canvases and do other "housekeeping" work. This is best done from a low priority context, ideally from your main() idle loop.

Member Data Documentation

◆ invalidCanvasId

constexpr uint16_t daisy::UI::invalidCanvasId = uint16_t(-1)
staticconstexpr

Use this to denote a nonexistent / invalid canvas ID


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