figments: input: support creating input handlers via lambdas

This commit is contained in:
Torrie Fischer 2020-01-28 13:48:06 -08:00
parent 15682ae9d2
commit 91183b5eed

View File

@ -81,6 +81,20 @@ public:
virtual InputEvent read() = 0;
};
class InputFunc : public InputSource {
public:
InputFunc(std::function<InputEvent(void)> f) : InputSource(), m_func(f) {}
InputFunc(std::function<InputEvent(void)> f, const char* name) : InputSource(name), m_func(f) {}
InputFunc(std::function<InputEvent(void)> f, const char* name, Task::State initialState) : InputSource(name, initialState), m_func(f) {}
InputEvent read() override {
return m_func();
}
private:
std::function<InputEvent(void)> m_func;
};
class BufferedInputSource: public InputSource {
public:
BufferedInputSource() : InputSource() {}