Sound Bakery  v0.1.0
Open-source audio middleware for games
Loading...
Searching...
No Matches
Widget.h
1#pragma once
2
3#include "pch.h"
4
5#define WIDGET_CONSTRUCT(type) \
6 \
7public: \
8 type(WidgetSubsystem* parentSubsystem) : Widget(parentSubsystem) {} \
9 \
10 type(Widget* parent) : Widget(parent) {}
11
12class WidgetSubsystem;
13
14// Base widget that can render ImGui UI
15class Widget
16{
17public:
18 Widget(WidgetSubsystem* parentSubsystem);
19 Widget(Widget* parentWidget);
20 virtual ~Widget() {}
21
22public:
23 virtual void Start();
24 virtual void Tick(double deltaTime) {}
25 virtual void Render() {}
26 virtual void End() {}
27
28 template <class T>
29 T* AddChildWidget()
30 {
31 m_childWidgets.push_back(std::make_unique<T>(this));
32 Widget* widget = m_childWidgets.back().get();
33 if (m_hasStarted)
34 widget->Start();
35 return dynamic_cast<T*>(widget);
36 }
37
38 bool HasStarted() { return m_hasStarted; }
39
40 void Destroy();
41
42public:
43 MulticastDelegate<Widget*> m_OnDestroy;
44
45protected:
46 void RenderChildren();
47
48protected:
49 class App* GetApp() const;
50 Widget* GetParentWidget() const;
51 WidgetSubsystem* GetParentSubsystem() const;
52
53private:
54 WidgetSubsystem* m_parentSubsystem = nullptr;
55 Widget* m_parentWidget = nullptr;
56 bool m_hasStarted = false;
57
58 std::vector<std::unique_ptr<Widget>> m_childWidgets;
59
60 friend class WidgetSubsystem;
61
62 bool m_wantsDestroy = false;
63};
Definition App.h:10
Definition WidgetSubsystem.h:7
Definition Widget.h:16