18 inline static std::unordered_map<std::type_index, UIElement*> uiComponentRegistry;
20 std::vector<std::unique_ptr<UIElement>> subcomponents;
25 registerUIComponent(
this);
29 virtual void update(
float deltaTime = 0.0f) {
30 for (
auto& component : subcomponents) {
31 component->update(deltaTime);
35 virtual void OnImGuiRender() = 0;
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;
41 subcomponents.push_back(std::move(newComponent));
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);
54 T* getSubcomponent() {
55 for (
auto& component : subcomponents) {
56 if (T* casted =
dynamic_cast<T*
>(component.get())) {
69 static void registerUIComponent(
UIElement* component) {
70 uiComponentRegistry[std::type_index(
typeid(*component))] = component;