Skip to content

Commit

Permalink
Element tree
Browse files Browse the repository at this point in the history
  • Loading branch information
Miigon committed Dec 24, 2016
1 parent 9875c46 commit 4f9bb41
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 4 deletions.
2 changes: 2 additions & 0 deletions example/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ set(CMAKE_CXX_STANDARD 11)

include_directories(../src)

link_libraries("-framework opengl" SDL2 glew eurekaui)

add_executable(helloworld helloworld.cpp)
5 changes: 3 additions & 2 deletions example/helloworld.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@

int main(int argc,char **argv)
{
EurekaUI::Context con;
}
EurekaUI::Context context;
EurekaUI::Element *element = context.root()->createChild<EurekaUI::Element>();
}
9 changes: 9 additions & 0 deletions src/context.cpp
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
#include "eurekaui/context.h"

namespace EurekaUI
{
Context::Context()
:mRoot(nullptr)
{
}

}
18 changes: 18 additions & 0 deletions src/element.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include "eurekaui/element.h"

namespace EurekaUI
{
Element::Element(Element *parent)
:mParent(parent)
{
}

Element::~Element()
{
// Free memory;
for(auto child:mChildren)
{
delete child;
}
}
}
7 changes: 5 additions & 2 deletions src/eurekaui/context.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#ifndef EUREKAUI_CONTEXT_H
#define EUREKAUI_CONTEXT_H
#include <vector>
#include "element.h"

namespace EurekaUI
{
Expand All @@ -9,9 +11,10 @@ namespace EurekaUI
class Context
{
public:

explicit Context();
Element *root(){return &mRoot;};
private:

Element mRoot;
};
}

Expand Down
42 changes: 42 additions & 0 deletions src/eurekaui/element.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#ifndef EUREKAUI_ELEMENT_H
#define EUREKAUI_ELEMENT_H
#include <unordered_map>
#include <string>
#include <list>

namespace EurekaUI
{
class Context;
/**
*
*/
class Element
{
friend class Context;
public:
template<class T> Element *createChild()
{
Element *e = new T(*this);
mChildren.push_back(e);
return e;
};

template<class T> Element *createChild(const std::string &&Id)
{
Element *e = createChild<T>();
mChildrenById[Id] = e;
return e;
}

Element *getParent(){return mParent;}
private:
explicit Element(Element *parent);
~Element();

Element *mParent;
std::list<Element*> mChildren;
std::unordered_map<std::string,Element*> mChildrenById;
};
}

#endif
1 change: 1 addition & 0 deletions src/eurekaui/eurekaui.h
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
#include "context.h"
#include "element.h"

0 comments on commit 4f9bb41

Please sign in to comment.