Flutter Engine
The Flutter Engine
|
#include <CommandSet.h>
Public Member Functions | |
CommandSet () | |
void | attach (Window *window) |
bool | onKey (skui::Key key, skui::InputState state, skui::ModifierKey modifiers) |
bool | onChar (SkUnichar, skui::ModifierKey modifiers) |
bool | onSoftkey (const SkString &softkey) |
void | addCommand (SkUnichar c, const char *group, const char *description, std::function< void(void)> function) |
void | addCommand (skui::Key k, const char *keyName, const char *group, const char *description, std::function< void(void)> function) |
void | drawHelp (SkCanvas *canvas) |
std::vector< SkString > | getCommandsAsSoftkeys () const |
Helper class used by applications that want to hook keypresses to trigger events.
An app can simply store an instance of CommandSet and then use it as follows: 1) Attach to the Window at initialization time. 2) Register commands to be executed for characters or keys. Each command needs a Group and a description (both just strings). Commands attached to Keys (rather than characters) also need a displayable name for the Key. Finally, a function to execute when the key or character is pressed must be supplied. The easiest option to is pass in a lambda that captures [this] (your application object), and performs whatever action is desired. 3) Register key and char handlers with the Window, and - depending on your state - forward those events to the CommandSet's onKey, onChar, and onSoftKey. 4) At the end of your onPaint, call drawHelp, and pass in the application's canvas.
The CommandSet always binds 'h' to cycle through two different help screens. The first shows all commands, organized by Group (with headings for each Group). The second shows all commands alphabetically by key/character.
Definition at line 44 of file CommandSet.h.
sk_app::CommandSet::CommandSet | ( | ) |
Definition at line 23 of file CommandSet.cpp.
void sk_app::CommandSet::addCommand | ( | skui::Key | k, |
const char * | keyName, | ||
const char * | group, | ||
const char * | description, | ||
std::function< void(void)> | function | ||
) |
Definition at line 84 of file CommandSet.cpp.
void sk_app::CommandSet::addCommand | ( | SkUnichar | c, |
const char * | group, | ||
const char * | description, | ||
std::function< void(void)> | function | ||
) |
void sk_app::CommandSet::attach | ( | Window * | window | ) |
Definition at line 41 of file CommandSet.cpp.
void sk_app::CommandSet::drawHelp | ( | SkCanvas * | canvas | ) |
Definition at line 97 of file CommandSet.cpp.
std::vector< SkString > sk_app::CommandSet::getCommandsAsSoftkeys | ( | ) | const |
Definition at line 162 of file CommandSet.cpp.
bool sk_app::CommandSet::onChar | ( | SkUnichar | c, |
skui::ModifierKey | modifiers | ||
) |
bool sk_app::CommandSet::onKey | ( | skui::Key | key, |
skui::InputState | state, | ||
skui::ModifierKey | modifiers | ||
) |
Definition at line 45 of file CommandSet.cpp.
bool sk_app::CommandSet::onSoftkey | ( | const SkString & | softkey | ) |