mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-05-05 02:20:11 -05:00
Feature/codegen (#1480)
* Add the ability to automatically generate code to extract values out of a Dictionary (see https://github.com/openspace/codegen for more information on how to use this) * Applied this technique to a large number of cases in the codebase * Don't add _codegen files to the repository Co-authored-by: Emma Broman <emma.broman@liu.se>
This commit is contained in:
@@ -31,6 +31,7 @@
|
||||
#include <ghoul/font/fontmanager.h>
|
||||
#include <ghoul/font/fontrenderer.h>
|
||||
#include <ghoul/misc/profiling.h>
|
||||
#include <optional>
|
||||
|
||||
namespace {
|
||||
constexpr openspace::properties::Property::PropertyInfo TextInfo = {
|
||||
@@ -38,44 +39,28 @@ namespace {
|
||||
"Text",
|
||||
"The text to be displayed"
|
||||
};
|
||||
|
||||
struct [[codegen::Dictionary(DashboardItemText)]] Parameters {
|
||||
// [[codegen::verbatim(TextInfo.description)]]
|
||||
std::optional<std::string> text;
|
||||
};
|
||||
#include "dashboarditemtext_codegen.cpp"
|
||||
} // namespace
|
||||
|
||||
namespace openspace {
|
||||
|
||||
documentation::Documentation DashboardItemText::Documentation() {
|
||||
using namespace documentation;
|
||||
return {
|
||||
"DashboardItem Text",
|
||||
"base_dashboarditem_text",
|
||||
{
|
||||
{
|
||||
"Type",
|
||||
new StringEqualVerifier("DashboardItemText"),
|
||||
Optional::No
|
||||
},
|
||||
{
|
||||
TextInfo.identifier,
|
||||
new StringVerifier,
|
||||
Optional::Yes,
|
||||
TextInfo.description
|
||||
}
|
||||
}
|
||||
};
|
||||
documentation::Documentation doc = codegen::doc<Parameters>();
|
||||
doc.id = "base_dashboarditem_text";
|
||||
return doc;
|
||||
}
|
||||
|
||||
DashboardItemText::DashboardItemText(const ghoul::Dictionary& dictionary)
|
||||
: DashboardTextItem(dictionary)
|
||||
, _text(TextInfo, "")
|
||||
{
|
||||
documentation::testSpecificationAndThrow(
|
||||
Documentation(),
|
||||
dictionary,
|
||||
"DashboardItemText"
|
||||
);
|
||||
|
||||
if (dictionary.hasKey(TextInfo.identifier)) {
|
||||
_text = dictionary.value<std::string>(TextInfo.identifier);
|
||||
};
|
||||
const Parameters p = codegen::bake<Parameters>(dictionary);
|
||||
_text = p.text.value_or(_text);
|
||||
addProperty(_text);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user