52 lines
1.4 KiB
C++
52 lines
1.4 KiB
C++
#pragma once
|
|
#include "shape.h"
|
|
#include "util.h"
|
|
#include "shader.h"
|
|
#include "font.h"
|
|
#include "asset.h"
|
|
#include "rtt.h"
|
|
#include "bezier.h"
|
|
#include "canvas.h"
|
|
#include "event.h"
|
|
#include <tinyxml2.h>
|
|
#include <yoga/Yoga.h>
|
|
|
|
class LayoutManager
|
|
{
|
|
std::map<uint16_t, std::shared_ptr<class Node>> m_layouts;
|
|
std::string m_path;
|
|
struct stat m_file_info { 0 };
|
|
public:
|
|
bool m_loaded = false;
|
|
std::function<void(bool reloaded)> on_loaded;
|
|
std::function<void()> on_reloading;
|
|
void unload();
|
|
void create();
|
|
bool load(const char* path);
|
|
bool reload();
|
|
class Node* operator[](uint16_t id)
|
|
{
|
|
auto i = m_layouts.find(id);
|
|
return i == m_layouts.end() ? nullptr : i->second.get();
|
|
}
|
|
class Node* get(uint16_t id)
|
|
{
|
|
auto i = m_layouts.find(id);
|
|
return i == m_layouts.end() ? nullptr : i->second.get();
|
|
}
|
|
template<class T = Node> std::shared_ptr<T> get_ref(const char* name)
|
|
{
|
|
auto i = m_layouts.find(const_hash(name));
|
|
return i == m_layouts.end() ? nullptr : std::dynamic_pointer_cast<T>(i->second);
|
|
}
|
|
template<class T = Node> std::shared_ptr<T> instantiate(const char* name)
|
|
{
|
|
if (auto layout = get_ref(name))
|
|
return layout->m_children[0]->clone<T>();
|
|
return nullptr;
|
|
}
|
|
void restore_context();
|
|
void clear_context();
|
|
//Node& operator[](const char* ids) { return m_layouts[const_hash(ids)]; }
|
|
};
|