TazGraph Project v0.1.0
Loading...
Searching...
No Matches
UIElement.h
1#pragma once
2
3#include "TazGraphEngine.h"
4
5#include "../AssetManager/AssetManager.h"
6
8 EntityID realEntityId; // the actual Node / Link selected
9 EntityID overlayEntityId; // the entity used for rendering selection box
10 glm::vec3 relativeOffset;
11};
12
13std::vector<EntityID> selectedEntities_RealIds(std::vector<SelectedInfo> sel_entities);
14
15
16class UIElement {
17public:
18 inline static std::unordered_map<std::type_index, UIElement*> uiComponentRegistry;
19
20 std::vector<std::unique_ptr<UIElement>> subcomponents;
21 UIElement* parent = nullptr; // Pointer to parent element
22
23 UIElement() {
24 // Auto-register on construction
25 registerUIComponent(this);
26 };
27 virtual ~UIElement() = default;
28
29 virtual void update(float deltaTime = 0.0f) {
30 for (auto& component : subcomponents) {
31 component->update(deltaTime);
32 }
33 }
34
35 virtual void OnImGuiRender() = 0; // must implement
36
37 template<typename T, typename... Args>
38 void addUIComponent(Args&&... args) {
39 auto newComponent = std::make_unique<T>(std::forward<Args>(args)...);
40 newComponent->parent = this; // Set parent pointer
41 subcomponents.push_back(std::move(newComponent));
42 }
43
44 template<typename T>
45 static T* getUIComponent() {
46 auto it = uiComponentRegistry.find(std::type_index(typeid(T)));
47 if (it != uiComponentRegistry.end()) {
48 return dynamic_cast<T*>(it->second);
49 }
50 return nullptr;
51 }
52
53 template<typename T>
54 T* getSubcomponent() {
55 for (auto& component : subcomponents) {
56 if (T* casted = dynamic_cast<T*>(component.get())) {
57 return casted;
58 }
59 }
60 return nullptr;
61 }
62
63protected:
64 std::string name;
65 bool visible = true;
66
67private:
68 // Helper methods for registration
69 static void registerUIComponent(UIElement* component) {
70 uiComponentRegistry[std::type_index(typeid(*component))] = component;
71 }
72
73};
Definition UIElement.h:16
Definition UIElement.h:7