Skip to content

Commit

Permalink
docs(imgui): add more data examples
Browse files Browse the repository at this point in the history
  • Loading branch information
roby2014 authored and RiscadoA committed Nov 28, 2023
1 parent accf7ca commit d16f7d8
Showing 1 changed file with 25 additions and 17 deletions.
42 changes: 25 additions & 17 deletions engine/samples/imgui/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <cubos/core/reflection/external/string.hpp>
#include <cubos/core/reflection/external/vector.hpp>
#include <cubos/core/reflection/reflect.hpp>
#include <cubos/core/reflection/traits/constructible.hpp>
#include <cubos/core/reflection/traits/fields.hpp>
#include <cubos/core/reflection/traits/nullable.hpp>

Expand All @@ -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;
Expand All @@ -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<const Person*>(instance);
return person->dead == true;
return person->dead;
},
[](void* instance) {
auto* person = static_cast<Person*>(instance);
person->dead = true;
}});
}})
.with(ConstructibleTrait::typed<Person>().withDefaultConstructor().build());
}

struct DummyResource
{
int integer;
Person person;
std::vector<Person> persons;
std::vector<int32_t> vec;
std::map<int32_t, int32_t> map;
};
Expand All @@ -71,6 +76,7 @@ static void exampleDataInspectorSystem(Write<DataInspector> inspector, Write<Dum

inspector->show("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);

Expand Down Expand Up @@ -103,15 +109,17 @@ int main()
/// [Adding the system]

/// [Filling the dummy resource 1]
cubos.addResource<DummyResource>(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>(
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]
Expand Down

0 comments on commit d16f7d8

Please sign in to comment.