-
Notifications
You must be signed in to change notification settings - Fork 283
Expand file tree
/
Copy pathWidgetContainer.h
More file actions
83 lines (69 loc) · 1.63 KB
/
WidgetContainer.h
File metadata and controls
83 lines (69 loc) · 1.63 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
/**
* @project: Overload
* @author: Overload Tech.
* @licence: MIT
*/
#pragma once
#include <memory>
#include <vector>
#include "OvUI/Widgets/AWidget.h"
#include "OvUI/Internal/EMemoryMode.h"
namespace OvUI::Internal
{
/**
* The base class for any widget container
*/
class WidgetContainer
{
public:
/**
* Constructor
*/
WidgetContainer() = default;
/**
* Destructor. Handle the memory de-allocation of every widgets that are internally managed
*/
virtual ~WidgetContainer();
/**
* Remove a widget from the container
* @param p_widget
*/
void RemoveWidget(Widgets::AWidget& p_widget);
/**
* Remove all widgets from the container
*/
void RemoveAllWidgets();
void TransferOwnership(Widgets::AWidget& p_widget, WidgetContainer& p_widgetCoontainer);
/**
* Collect garbages by removing widgets marked as "Destroyed"
*/
void CollectGarbages();
/**
* Draw every widgets
*/
void DrawWidgets();
/**
* Allow the user to reverse the draw order of this widget container
*/
void ReverseDrawOrder(bool reversed = true);
/**
* Create a widget
* @param p_args
*/
template <typename T, typename ... Args>
T& CreateWidget(Args&&... p_args)
{
m_widgets.emplace_back(std::make_unique<T>(p_args...));
T& instance = *static_cast<T*>(m_widgets.back().get());
instance.SetParent(this);
return instance;
}
/**
* Returns the widgets and their memory management mode
*/
std::vector<std::unique_ptr<Widgets::AWidget>>& GetWidgets();
protected:
std::vector<std::unique_ptr<Widgets::AWidget>> m_widgets;
bool m_reversedDrawOrder = false;
};
}