-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvxgui.hpp
111 lines (90 loc) · 2.3 KB
/
vxgui.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
#pragma once
#include <memory>
#include <vector>
#include <functional>
#include <string>
#include <cstdint>
#include <cglm/types.h>
// Forward declarations
struct GuiContext;
class Gui;
class Widget;
struct Color {
uint32_t value;
explicit Color(uint32_t val) : value(val) {}
};
// RAII Wrapper for GuiContext
class GuiHandle {
public:
explicit GuiHandle(std::unique_ptr<GuiContext> context);
~GuiHandle();
GuiContext* get() const;
private:
std::unique_ptr<GuiContext> ctx;
};
enum class ButtonState {
Normal,
Hovered,
Pressed
};
// Base class for all widgets
class Widget {
public:
virtual ~Widget() = default;
virtual void paint(GuiContext& ctx) = 0;
virtual void update(Gui& ctx) = 0;
protected:
vec2 position{0, 0}; // Position relative to the parent widget
vec2 size{0, 0}; // Size of this widget in pixels
std::vector<std::unique_ptr<Widget>> children;
};
// Gui class managing the GUI context and widgets
class Gui {
public:
using OnSubmit = std::function<void()>;
explicit Gui(std::unique_ptr<GuiContext> context);
void add(std::unique_ptr<Widget> widget);
Widget& operator[](std::size_t index);
private:
std::vector<std::unique_ptr<Widget>> widgets;
std::unique_ptr<GuiContext> ctx;
};
// GuiContext class handling low-level drawing operations
struct GuiContext {
void set_fill(Color color);
void draw_rect(const vec2& pos, const vec2& size);
};
struct ButtonProps {
Color bg{0xff2b2e4a};
Color fg{0xff1d1f21};
};
class Button : public Widget {
public:
Button() = default;
void paint(GuiContext& ctx) override;
void update(Gui& ctx) override;
private:
ButtonState state = ButtonState::Normal;
ButtonProps props;
std::string label = "Button";
};
class Container : public Widget {
public:
void paint(GuiContext& ctx) override;
void update(Gui& ctx) override;
void add_widget(std::unique_ptr<Widget> widget);
};
class Graph : public Widget {
public:
void paint(GuiContext& ctx) override;
void update(Gui& ctx) override;
};
// RichText widget for displaying text with formatting
class RichText : public Widget {
public:
explicit RichText(const std::string& text);
void paint(GuiContext& ctx) override;
void update(Gui& ctx) override;
private:
std::string content;
};