add: config ui
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
#include "WidgetRegistry.hpp"
|
||||
|
||||
#include "ContainerWidget.hpp"
|
||||
|
||||
namespace frame::widgets
|
||||
{
|
||||
|
||||
@@ -19,4 +21,23 @@ namespace frame::widgets
|
||||
return it->second();
|
||||
}
|
||||
|
||||
Widget::shared_ptr WidgetRegistry::BuildFromConfig(WidgetConfig const& w)
|
||||
{
|
||||
fmt::print("INFO: Creating widget {} \n", w.name);
|
||||
auto widget = Create(w.name);
|
||||
|
||||
auto container = std::dynamic_pointer_cast<ContainerWidget>(widget);
|
||||
if(container)
|
||||
{
|
||||
int counter = 0;
|
||||
for(auto const& el : w.widgets)
|
||||
{
|
||||
int slot = el.slot ? el.slot.value() : counter;
|
||||
|
||||
container->setSlot(slot, BuildFromConfig(el));
|
||||
}
|
||||
}
|
||||
return widget;
|
||||
}
|
||||
|
||||
} // namespace frame::widgets
|
||||
@@ -1,4 +1,5 @@
|
||||
#pragma once
|
||||
#include "../Config.hpp"
|
||||
#include "../ServiceLocator.hpp"
|
||||
#include "Widget.hpp"
|
||||
|
||||
@@ -14,7 +15,6 @@
|
||||
|
||||
namespace frame::widgets
|
||||
{
|
||||
|
||||
class WidgetRegistry : public IService
|
||||
{
|
||||
|
||||
@@ -29,8 +29,15 @@ namespace frame::widgets
|
||||
bool Register(std::string_view name);
|
||||
|
||||
Widget::shared_ptr Create(std::string_view name) const;
|
||||
|
||||
Widget::shared_ptr BuildFromConfig(WidgetConfig const& w);
|
||||
};
|
||||
|
||||
inline WidgetRegistry& LocateRegistry()
|
||||
{
|
||||
return *Service::get<frame::widgets::WidgetRegistry>();
|
||||
}
|
||||
|
||||
template<class WIDGET>
|
||||
bool WidgetRegistry::Register(std::string_view name)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user