A generic UI system.
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) |
daisy::UI::UI | ( | ) |
daisy::UI::~UI | ( | ) |
|
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.
|
inline |
Returns the button IDs, encoder IDs and pot IDs used for special functions.
void daisy::UI::Init | ( | UiEventQueue & | inputQueue, |
const SpecialControlIds & | specialControlIds, | ||
std::initializer_list< UiCanvasDescriptor > | canvases, | ||
uint16_t | primaryOneBitGraphicsDisplayId = invalidCanvasId |
||
) |
Initializes the UI.
inputQueue | The UiEventQueue to read user input events from. |
specialControlIds | Information about the control IDs used for special buttons/encoders/pots. |
canvases | A list of UiCanvasDescriptor that define which canvases to use. |
primaryOneBitGraphicsDisplayId | The 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. |
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.
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.
Use this to denote a nonexistent / invalid canvas ID