-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWidget.h
More file actions
92 lines (70 loc) · 2.25 KB
/
Widget.h
File metadata and controls
92 lines (70 loc) · 2.25 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
84
85
86
87
88
89
90
91
92
#pragma once
#include <DrawUtils.h>
#include <UIConstants.h>
#include <functional>
#include <memory>
class Widget {
public:
Widget():
m_rect{0,0,0,0},
m_spacing{3},
m_margin{1}
{};
~Widget() {};
// Getters
Rectangle bounding_rect();
Vector2 location();
Vector2 get_size();
unsigned int spacing();
unsigned int margin();
unsigned int width();
unsigned int height();
unsigned int x();
unsigned int y();
Widget* parent();
// Setters
void set_bounding_rect(Rectangle&);
void set_location(Vector2&);
void set_location(unsigned int, unsigned int);
void set_size(Vector2&);
void set_size(unsigned int, unsigned int);
void set_width(unsigned int);
void set_height(unsigned int);
void set_spacing(unsigned int);
void set_margin(unsigned int);
void set_parent(Widget*);
virtual void update(float) = 0;
virtual void draw() = 0;
protected:
private:
Rectangle m_rect;
unsigned int m_spacing = 3;
unsigned int m_margin = 1;
Widget* m_parent;
};
#define WIDGET_CONSTRUCT(Type) \
static std::unique_ptr<Type> construct() {\
auto widget = std::make_unique<Type>();\
return widget;\
}
#define WIDGET_CONSTRUCT_PARENT(Type) \
template<typename TypeWidget>\
static std::unique_ptr<Type> construct(std::unique_ptr<TypeWidget>& parent) {\
auto widget = std::make_unique<Type>();\
parent->add(widget);\
return widget;\
}\
template<typename TypeWidget>\
static std::unique_ptr<Type> construct(TypeWidget* parent) {\
auto widget = std::make_unique<Type>();\
parent->add(widget);\
return widget;\
}
#define WIDGET_ALLOWS_TEXT \
void set_text(const char* value) { m_text = std::string(value); }\
void set_text(std::string& value) { m_text = value; }\
std::string text() { return m_text; }
#define WIDGET_ALLOWS_TITLE \
void set_title(const char* value) { m_title = std::string(value); }\
void set_title(std::string& value) { m_title = value; }\
std::string title() { return m_title; }