Custom element registration
This commit is contained in:
22
src/element_registry.hpp
Normal file
22
src/element_registry.hpp
Normal file
@@ -0,0 +1,22 @@
|
||||
#pragma once
|
||||
|
||||
#include <RmlUi/Core/ElementInstancer.h>
|
||||
#include <RmlUi/Core/Factory.h>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
#include <vector>
|
||||
|
||||
class ElementRegistry {
|
||||
public:
|
||||
template <typename T>
|
||||
void Register(const std::string& tag) {
|
||||
static_assert(std::is_base_of<Rml::Element, T>::value, "T must derive from Rml::Element");
|
||||
auto instancer = std::make_unique<Rml::ElementInstancerGeneric<T>>();
|
||||
Rml::Factory::RegisterElementInstancer(tag, instancer.get());
|
||||
instancers.push_back(std::move(instancer));
|
||||
}
|
||||
|
||||
private:
|
||||
std::vector<std::unique_ptr<Rml::ElementInstancer>> instancers;
|
||||
};
|
||||
Reference in New Issue
Block a user