From d16f7d80415c34400bf125efb9897db063811147 Mon Sep 17 00:00:00 2001 From: roby2014 Date: Mon, 20 Nov 2023 18:52:03 +0000 Subject: [PATCH] docs(imgui): add more data examples --- engine/samples/imgui/main.cpp | 42 +++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/engine/samples/imgui/main.cpp b/engine/samples/imgui/main.cpp index 6f48e9060..374b4ee01 100644 --- a/engine/samples/imgui/main.cpp +++ b/engine/samples/imgui/main.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -18,6 +19,7 @@ /// [Including plugin headers] +using cubos::core::reflection::ConstructibleTrait; using cubos::core::reflection::FieldsTrait; using cubos::core::reflection::NullableTrait; using cubos::core::reflection::reflect; @@ -39,25 +41,28 @@ struct Person CUBOS_REFLECT_IMPL(Person) { - return Type::create("Person").with(FieldsTrait() - .withField("name", &Person::name) - .withField("age", &Person::age) - .withField("weight", &Person::weight) - .withField("dead", &Person::dead)) - .with(NullableTrait{[](const void* instance) { + return Type::create("Person") + .with(FieldsTrait() + .withField("name", &Person::name) + .withField("age", &Person::age) + .withField("weight", &Person::weight) + .withField("dead", &Person::dead)) + .with(NullableTrait{[](const void* instance) { const auto* person = static_cast(instance); - return person->dead == true; + return person->dead; }, [](void* instance) { auto* person = static_cast(instance); person->dead = true; - }}); + }}) + .with(ConstructibleTrait::typed().withDefaultConstructor().build()); } struct DummyResource { int integer; Person person; + std::vector persons; std::vector vec; std::map map; }; @@ -71,6 +76,7 @@ static void exampleDataInspectorSystem(Write inspector, Writeshow("data->integer", data->integer); inspector->edit("data->person", data->person); + inspector->edit("data->persons", data->persons); inspector->edit("data->vec", data->vec); inspector->edit("data->map", data->map); @@ -103,15 +109,17 @@ int main() /// [Adding the system] /// [Filling the dummy resource 1] - cubos.addResource(DummyResource{.integer = 1337, - .person = Person{"roby", 1337, 666.5F, false}, - .vec = {12, 59, 25}, - .map = { - {1, 2}, - {2, 4}, - {3, 6}, - {4, 8}, - }}); + cubos.addResource( + DummyResource{.integer = 1337, + .person = Person{"roby", 1337, 666.5F, false}, + .persons{Person{"roby", 1337, 666.5F, false}, Person{"riscado", 123, 321.0F, false}}, + .vec = {12, 59, 25}, + .map = { + {1, 2}, + {2, 4}, + {3, 6}, + {4, 8}, + }}); /// [Filling the dummy resource 1] /// [Adding the system and a dummy resource with data]