Files
XCEngine/new_editor/src/Panels/UIEditorPanelRegistry.cpp

75 lines
2.1 KiB
C++

#include <XCEditor/Panels/UIEditorPanelRegistry.h>
#include <unordered_set>
#include <utility>
namespace XCEngine::UI::Editor {
namespace {
UIEditorPanelRegistryValidationResult MakeValidationError(
UIEditorPanelRegistryValidationCode code,
std::string message) {
UIEditorPanelRegistryValidationResult result = {};
result.code = code;
result.message = std::move(message);
return result;
}
} // namespace
UIEditorPanelRegistry BuildDefaultEditorShellPanelRegistry() {
UIEditorPanelRegistry registry = {};
registry.panels = {
{
"editor-foundation-root",
"Root Surface",
UIEditorPanelPresentationKind::Placeholder,
true,
false,
false
}
};
return registry;
}
const UIEditorPanelDescriptor* FindUIEditorPanelDescriptor(
const UIEditorPanelRegistry& registry,
std::string_view panelId) {
for (const UIEditorPanelDescriptor& descriptor : registry.panels) {
if (descriptor.panelId == panelId) {
return &descriptor;
}
}
return nullptr;
}
UIEditorPanelRegistryValidationResult ValidateUIEditorPanelRegistry(
const UIEditorPanelRegistry& registry) {
std::unordered_set<std::string> panelIds = {};
for (const UIEditorPanelDescriptor& descriptor : registry.panels) {
if (descriptor.panelId.empty()) {
return MakeValidationError(
UIEditorPanelRegistryValidationCode::EmptyPanelId,
"Panel registry entry must define a panelId.");
}
if (descriptor.defaultTitle.empty()) {
return MakeValidationError(
UIEditorPanelRegistryValidationCode::EmptyDefaultTitle,
"Panel descriptor '" + descriptor.panelId + "' must define a defaultTitle.");
}
if (!panelIds.insert(descriptor.panelId).second) {
return MakeValidationError(
UIEditorPanelRegistryValidationCode::DuplicatePanelId,
"Panel descriptor '" + descriptor.panelId + "' is duplicated in the registry.");
}
}
return {};
}
} // namespace XCEngine::UI::Editor