micromenu/inc/node.h

85 lines
2.2 KiB
C
Raw Normal View History

2018-11-05 20:09:01 +00:00
//
// Created by jedi on 11/5/18.
//
2021-02-24 19:37:27 +00:00
#pragma once
2018-11-05 20:09:01 +00:00
2021-02-24 19:37:27 +00:00
#include "gfx/Canvas.h"
2018-11-05 20:09:01 +00:00
2021-02-24 19:37:27 +00:00
namespace micromenu {
2018-11-05 20:09:01 +00:00
2021-02-24 19:37:27 +00:00
class node {
private:
node *parent_ = nullptr;
node *child_ = nullptr;
node *cursor_ = nullptr;
node *next_ = nullptr;
2018-11-05 20:09:01 +00:00
2021-02-24 19:37:27 +00:00
void addNodes(bool b) {
}
2018-11-05 20:09:01 +00:00
2021-02-24 19:37:27 +00:00
template<class ...Us>
void addNodes(bool b, node *n, Us ... ns) {
next_ = n;
next_->parent_ = parent_;
next_->addNodes(!b, ns...);
}
2018-11-05 20:09:01 +00:00
2021-02-24 19:37:27 +00:00
public:
const char *title_ = 0;
const int minsize;
const int maxsize;
2018-11-05 20:09:01 +00:00
2021-02-24 19:37:27 +00:00
virtual void render(Canvas &c) = 0;
2018-11-05 20:09:01 +00:00
2021-02-24 19:37:27 +00:00
explicit node(int min = 24, int max = 48) : next_(nullptr), child_(nullptr), parent_(nullptr), minsize(min),
maxsize(max) {
}
2018-11-05 20:09:01 +00:00
2021-02-24 19:37:27 +00:00
explicit node(const char *t, int min = 24, int max = 48) : title_(t), minsize(min), maxsize(max),
next_(nullptr),
child_(nullptr),
parent_(nullptr) {
}
2018-11-05 20:09:01 +00:00
2021-02-24 19:37:27 +00:00
template<typename ... Args>
node(const char *t, node *n, Args ... ns) : title_(t), minsize(24), maxsize(48) {
child_ = n;
cursor_ = n;
n->parent_ = this;
child_->addNodes(true, ns...);
}
2018-11-06 15:06:05 +00:00
2021-02-24 19:37:27 +00:00
node *getChild() {
return child_;
}
2018-11-06 15:06:05 +00:00
2021-02-24 19:37:27 +00:00
node *getNext() {
return next_;
}
2018-11-06 17:30:21 +00:00
2021-02-24 19:37:27 +00:00
node *getCursor() {
return cursor_;
}
2018-11-06 17:30:21 +00:00
2021-02-24 19:37:27 +00:00
node *getParent() {
return parent_;
}
2018-11-05 20:09:01 +00:00
2021-02-24 19:37:27 +00:00
void setCursor(node *c) {
cursor_ = c;
}
};
2018-11-05 20:09:01 +00:00
2021-02-24 19:37:27 +00:00
class value : public node {
public:
const char *header;
int state;
2018-11-05 20:09:01 +00:00
2021-02-24 19:37:27 +00:00
value(const char *t, int val, int min = 64, int max = 96) : node(t, min, max), header(t), state(val) {
}
};
2018-11-05 20:09:01 +00:00
2021-02-24 19:37:27 +00:00
}