84 lines
1.6 KiB
C++
84 lines
1.6 KiB
C++
|
|
#ifndef _COL_H_
|
|
#define _COL_H_
|
|
|
|
class Node;
|
|
typedef void (*drawfun_t)(int offset, int size, Node*);
|
|
|
|
void draw_menu(int, int, Node*);
|
|
|
|
class Drawable{
|
|
public:
|
|
const int minsize;
|
|
const int maxsize;
|
|
drawfun_t render;
|
|
Drawable(drawfun_t fun, int min = 0, int max=0): minsize(min), maxsize(max), render(fun){
|
|
}
|
|
};
|
|
|
|
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;
|
|
Node(int min = 24, int max=48): next_(nullptr), child_(nullptr), parent_(nullptr), view(nullptr, min, max){
|
|
}
|
|
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){
|
|
}
|
|
|
|
template<typename ... Args>
|
|
Node(const char* t, Node* n, Args ... ns) : title_(t), view(draw_menu, 24, 48){
|
|
child_ = n;
|
|
n->parent_=this;
|
|
child_->addNodes(true,ns...);
|
|
}
|
|
Node* getChild(){
|
|
return child_;
|
|
}
|
|
};
|
|
|
|
class Value: public Node{
|
|
public:
|
|
const char* header;
|
|
int state;
|
|
Value(const char* t, int val, drawfun_t fun): Node(t, fun, 64, 96), header(t), state(val){
|
|
}
|
|
};
|
|
|
|
class Layout{
|
|
class Slot{
|
|
private:
|
|
int pos_;
|
|
int size_;
|
|
public:
|
|
Node* node;
|
|
friend Layout;
|
|
};
|
|
private:
|
|
const int maxwidth_;
|
|
int allocated_;
|
|
int allocate_(Node*, int);
|
|
int expand_(int );
|
|
int pack_(int);
|
|
public:
|
|
static const int maxslots = 10;
|
|
Layout(int max) : maxwidth_(max){
|
|
|
|
}
|
|
int apply(Node*);
|
|
Slot slots[maxslots];
|
|
void render();
|
|
};
|
|
|
|
#endif
|