This repository has been archived by the owner on Aug 30, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sclui.hpp
159 lines (128 loc) · 4.32 KB
/
sclui.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#pragma once
#define COLOR_BLANK -1
#include <vector>
#include <string>
#include <string_view>
#include <any>
#include <curses.h>
#include <assert.h>
namespace sclui {
void initSclui();
bool TextBoxFilterIsText(int c);
bool TextBoxFilterIsNumber(int c);
bool TextBoxFilterAllowAll(int c);
void doQuit();
int getMaxX();
int getMaxY();
enum class axis {
X,
Y,
XY
};
class BasicItem {
friend class Screen;
public:
enum class types {
BASIC,
BUTTON,
CHECKBOX,
TEXTBOX
};
void (*onDraw)() = nullptr;
void (*onDestruct)() = nullptr;
std::string name = ("");
int x,y,color, colorFocus;
bool visible = true;
protected:
bool interactable = false;
virtual void draw(bool v) = 0;
void moveTo(int yOffet, int xOffset);
BasicItem(std::string_view name, int x, int y, int color, int colorFocus):
name{name},x{x},y{y},color{color},colorFocus{colorFocus} {}
int itemIndex;
types type;
void chooseColor(bool b);
};
template<class T>
class Interactable : public BasicItem {
public:
bool enabled = true;
T value;
protected:
Interactable(std::string_view name, int x, int y, int color, int colorFocus, T value) :
BasicItem(name,x,y,color,colorFocus),
value{value}
{interactable = true;};
};
class TextBox : public Interactable<std::string> {
private:
virtual void draw(bool v) override;
char splitter;
public:
TextBox(std::string_view name,int x, int y,int color, int colorFocus,int maxLength, bool(*filter)(int), char splitter);
bool(*filter)(int) = nullptr;
void(*onKeyPress)(int) = nullptr;
void defaultKeyPressEvent(int c);
int maxLength;
void append(char c);
void pop();
};
class CheckBox : public Interactable<bool> {
private:
virtual void draw(bool v) override;
public:
CheckBox(std::string_view name,int x, int y,int color, int colorFocus, bool value);
void(*onCheckBoxChange)() = nullptr;
};
class Button : public Interactable<std::any> {
private:
virtual void draw(bool v) override;
public:
Button(std::string_view name,int x, int y,int color, int colorFocus);
void(*onButtonPress)() = nullptr;
};
class Text : public BasicItem{
private:
virtual void draw(bool v) override;
public:
Text(std::string_view name,int x, int y,int color);
};
class Screen {
friend class BasicItem;
friend class CheckBox;
private:
bool isDragging = false,isFocused = false;
int vecIndex,subScreenIndex;
BasicItem *currentItem;
void run();
void drawFrame(int v);
void drawItems();
void destroyHelper(Screen *n);
void doMove(int mov);
bool selectNext(BasicItem *i);
BasicItem *getFirstInteractableItem();
void handleDrag(int c);
void switchFocus();
void moveHelper(int i);
public:
Screen(std::string_view title, int width, int height, int x, int y);
std::string title;
int x,y,width, height;
void(*onDestruct)() = nullptr;
void(*onFocus)()= nullptr;
void(*onUnFocus)()= nullptr;
void(*onDragBegin)()= nullptr;
void(*onDrag)()= nullptr;
void(*onDrop)()= nullptr;
void addItem(BasicItem *i);
void addSubScreen(Screen *i);
BasicItem *getItemByName(const char *name);
void centerItem(axis pAxis, BasicItem *i);
std::vector<BasicItem *> items = {};
std::vector<Screen *> subScreens = {};
void draw();
void update();
bool border = true;
Screen *motherScreen = nullptr;
};
}