summaryrefslogtreecommitdiff
path: root/engine-ocean/Game/Systems/UI/uielement.h
blob: c2c3a2e23c28753132e5a9ed1803792d06f188be (plain)
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
#ifndef UIELEMENT_H
#define UIELEMENT_H


#include "Game/Systems/UI/UITextures/uitexture.h"
#include "Game/TypeMap.h"
#include <memory>
class UIElement
{
public:
    UIElement();

    template <typename T>
    void addComponent(std::unique_ptr<T> &&component){
        m_components.put<T>(std::forward<std::unique_ptr<T>>(component));
    }

    template <typename T>
    bool hasComponent(){
        return m_components.contains<T>();
    }

    template <class T>
    T* getComponent(){
        auto comp = m_components.find<T>();
        assert(comp != m_components.end());
        return static_cast<T*>(comp->second.get());
    }

    template <class T>
    void removeComponent(){
        m_components.remove<T>();
    }

private:

     TypeMap<std::unique_ptr<UITexture>> m_components;
};

#endif // UIELEMENT_H