-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsettings.h
More file actions
83 lines (66 loc) · 2.2 KB
/
Copy pathsettings.h
File metadata and controls
83 lines (66 loc) · 2.2 KB
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
#pragma once
#include "tabs.h"
#include "textedit.h"
#include "widget.h"
#include <GLFW/glfw3.h>
struct SettingsElement {
std::string name;
std::string key_name;
bool set = false;
virtual ~SettingsElement() = default; // make base polymorphic
};
struct SettingsInt : SettingsElement {
int default_value;
int value = 0;
};
struct SettingsFloat : SettingsElement {
float default_value;
float value = 0.0f;
};
struct SettingsBool : SettingsElement {
bool default_value;
bool value = false;
};
struct SettingsString : SettingsElement {
std::string default_value;
std::string value = "";
};
struct SettingsLabel : SettingsElement {
std::string default_value;
};
class Settings : public Widget {
public:
Settings(Widget* parent);
Tabs* tab_bar;
bool rounded = true;
int scrolled_to = 0;
int max_scroll = 0;
std::unordered_map<int, std::vector<SettingsElement*>> settings_menus;
std::unordered_map<TextEdit*, SettingsElement*> edits_to_element;
std::unordered_map<SettingsElement*, TextEdit*> elements_to_edit;
bool on_key_event(int key, int scancode, int action, int mods);
bool on_mouse_button_event(int button, int action, int mods);
// bool on_mouse_move_event();
bool on_scroll_event(double xchange, double ychange);
void executeAction(WidgetActionType typ);
SettingsFloat* makeFloat(std::string name, std::string key, float default_value);
SettingsInt* makeInt(std::string name, std::string key, int default_value);
SettingsBool* makeBool(std::string name, std::string key, bool default_value);
SettingsString* makeString(std::string name, std::string key, std::string default_value);
SettingsLabel* makeLabel(std::string name);
void handleChildren();
void handleChange(TextEdit* te, SettingsElement* se);
void setWithValue(TextEdit* e, SettingsElement* el);
bool validate_input(SettingsFloat* el);
bool validate_input(SettingsInt* el);
bool validate_input(SettingsBool* el);
bool validate_input(SettingsString* el, std::string before);
void render();
void position(int x, int y, int w, int h);
void after_change(SettingsString* el);
void after_change(SettingsInt* el);
void after_change(SettingsFloat* el);
void after_change(SettingsBool* el);
private:
Widget* before = nullptr;
};