micromenu/inc/col.h

88 lines
1.7 KiB
C
Raw Normal View History

2018-10-19 11:49:11 +00:00
2018-10-28 13:01:25 +00:00
#ifndef _COL_H_
#define _COL_H_
2018-11-05 09:53:59 +00:00
class canvas;
#include "gfx/canvas.h"
2018-10-19 11:49:11 +00:00
class Node;
2018-11-05 09:53:59 +00:00
typedef void (*drawfun_t)(int offset, int size, Node*, canvas& c);
2018-10-19 11:49:11 +00:00
2018-11-05 09:53:59 +00:00
void draw_menu(int, int, Node*, canvas& c);
2018-10-19 11:49:11 +00:00
class Drawable{
public:
const int minsize;
const int maxsize;
drawfun_t render;
2018-10-28 13:01:25 +00:00
Drawable(drawfun_t fun, int min = 0, int max=0): minsize(min), maxsize(max), render(fun){
2018-10-19 11:49:11 +00:00
}
};
class Node{
private:
Node* parent_ = 0;
Node* child_ = 0;
Node* next_ = 0;
void addNodes(bool b){
}
template<class ...Us>
void addNodes(bool b, Node* n, Us ... ns){
next_ = n;
next_->parent_ = parent_;
next_->addNodes(!b,ns...);
}
public:
Drawable view;
const char* title_ = 0;
2018-10-28 13:01:25 +00:00
Node(int min = 24, int max=48): next_(nullptr), child_(nullptr), parent_(nullptr), view(nullptr, min, max){
2018-10-19 11:49:11 +00:00
}
2018-10-28 13:01:25 +00:00
Node(const char* t, drawfun_t fun=draw_menu, int min = 24, int max=48) : title_(t), view(fun, min, max), next_(nullptr), child_(nullptr), parent_(nullptr){
2018-10-19 11:49:11 +00:00
}
template<typename ... Args>
2018-10-28 13:01:25 +00:00
Node(const char* t, Node* n, Args ... ns) : title_(t), view(draw_menu, 24, 48){
2018-10-19 11:49:11 +00:00
child_ = n;
n->parent_=this;
child_->addNodes(true,ns...);
}
2018-10-28 13:01:25 +00:00
Node* getChild(){
return child_;
}
2018-10-19 11:49:11 +00:00
};
class Value: public Node{
public:
const char* header;
int state;
2018-10-28 13:01:25 +00:00
Value(const char* t, int val, drawfun_t fun): Node(t, fun, 64, 96), header(t), state(val){
2018-10-19 11:49:11 +00:00
}
};
class Layout{
2018-10-28 13:01:25 +00:00
class Slot{
private:
int pos_;
int size_;
public:
Node* node;
friend Layout;
};
2018-10-19 11:49:11 +00:00
private:
2018-10-28 13:01:25 +00:00
const int maxwidth_;
int allocated_;
int allocate_(Node*, int);
int expand_(int );
int pack_(int);
2018-10-19 11:49:11 +00:00
public:
2018-10-28 13:01:25 +00:00
static const int maxslots = 10;
Layout(int max) : maxwidth_(max){
2018-10-19 11:49:11 +00:00
}
2018-10-28 13:01:25 +00:00
int apply(Node*);
Slot slots[maxslots];
2018-11-01 13:37:30 +00:00
void render();
2018-10-19 11:49:11 +00:00
};
2018-10-28 13:01:25 +00:00
#endif