renderbug/lib/Figments/Figment.h
Torrie Fischer 2848c8ad12
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
figments: figment: redefine task startup state semantics
2023-02-18 16:33:09 +01:00

56 lines
1.3 KiB
C++

#pragma once
#include <Arduino.h>
#include <functional>
#include <ArduinoLog.h>
class Display;
class InputEvent;
class InputSource;
struct Loopable {
virtual void handleEvent(const InputEvent& event) {}
virtual void loop() = 0;
};
struct Task : public virtual Loopable {
virtual void onStart() {};
virtual void onStop() {};
enum State {
Running,
Stopped,
};
Task() {}
explicit Task(const char* name) : name(name) {}
void start() { state = Running; onStart(); }
void stop() { onStop(); state = Stopped; }
virtual bool isFigment() const { return false; }
const char* name = "";
State state = Stopped;
};
struct TaskFunc: public Task {
TaskFunc(std::function<void()> func) : Task("lambda"), func(func) {}
void loop() override {func();}
std::function<void()> func;
};
struct Figment: public Task {
Figment() : Task() {}
explicit Figment(const char* name) : Task(name) {}
virtual void render(Display* dpy) const = 0;
bool isFigment() const override { return true; }
};
struct FigmentFunc: public Figment {
FigmentFunc(std::function<void(Display*)> func) : Figment("lambda"), func(func) {}
void loop() override {}
void render(Display* dpy) const override {
func(dpy);
}
std::function<void(Display*)> func;
};