2026-04-15 08:24:06 +08:00
|
|
|
#include <XCEditor/Panels/UIEditorPanelRegistry.h>
|
2026-04-06 16:20:46 +08:00
|
|
|
|
|
|
|
|
#include <unordered_set>
|
|
|
|
|
#include <utility>
|
|
|
|
|
|
2026-04-06 20:02:34 +08:00
|
|
|
namespace XCEngine::UI::Editor {
|
2026-04-06 16:20:46 +08:00
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
UIEditorPanelRegistryValidationResult MakeValidationError(
|
|
|
|
|
UIEditorPanelRegistryValidationCode code,
|
|
|
|
|
std::string message) {
|
|
|
|
|
UIEditorPanelRegistryValidationResult result = {};
|
|
|
|
|
result.code = code;
|
|
|
|
|
result.message = std::move(message);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
|
|
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 {};
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-06 20:02:34 +08:00
|
|
|
} // namespace XCEngine::UI::Editor
|