1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-04-19 12:02:24 +02:00
vcmi/client/gui/InterfaceBuilder.h

47 lines
1.1 KiB
C
Raw Normal View History

2022-12-12 03:27:59 +04:00
/*
* InterfaceBuilder.h, part of VCMI engine
*
* Authors: listed in file AUTHORS in main folder
*
* License: GNU General Public License v2.0 or later
* Full text of license available in license.txt file, in main folder
*
*/
#pragma once
#include "CIntObject.h"
#include "../../lib/JsonNode.h"
class InterfaceBuilder: public CIntObject
{
public:
InterfaceBuilder();
InterfaceBuilder(const JsonNode & config);
protected:
//must be called after adding callbacks
void init(const JsonNode & config);
void addCallback(const std::string & callbackName, std::function<void(int)> callback);
2022-12-12 11:38:27 +04:00
template<class T>
const std::shared_ptr<T> widget(const std::string & name) const
{
auto iter = widgets.find(name);
if(iter == widgets.end())
return nullptr;
2022-12-12 11:43:54 +04:00
return std::dynamic_pointer_cast<T>(iter->second);
2022-12-12 11:38:27 +04:00
}
2022-12-12 03:27:59 +04:00
private:
std::map<std::string, std::shared_ptr<CIntObject>> widgets;
std::map<std::string, std::function<void(int)>> callbacks;
std::shared_ptr<CIntObject> buildWidget(const JsonNode & config);
std::string buildText(const JsonNode & param) const;
};