-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Description
I'm trying to use Davey as a way to experiment with getting & setting data on meta reflected fields.
My current setup looks something like
float GetSomethingTest(const SomeType& some)
{
return some.thing;
}
void SetSomethingTest(SomeType& some, float value)
{
some.thing = value;
}
auto temp= entt::meta_factory<SomeType>{}.data<&SetSomethingTest, &GetSomethingTest>("Some");In Davey, in present_element where we current display float values, i'm testing with
//ImGui::Text("%s: %f", label, elem.template allow_cast<double>().template cast<double>());
float* temp = const_cast<float *>(elem.template try_cast<float>());
if (ImGui::DragFloat(label, temp)) {
data.set(*obj.try_cast<SomeType>(), *temp);
}Two issues seem to come up here.
First, if I want to be able to edit these values like I wrote above, I don't know how to access SomeType to pass it to the set function. We theoretically have the data for that "parent type" there, but not the template type at compile time, so i don't know how to turn the obj into an actual reference to it's underlying type.
Second issue, is even if I fudge it like this, in meta_setter when we do auto *const clazz = instance->try_cast<Type>(); at least for my example it returns nullptr, because the type being passed hits that first part of the try_cast ternary (storage.policy() == any_policy::cref) && !std::is_const_v<Type> which then early-returns out of the set function and never actually calls my SetSomethingTest.
I see in meta_getter, there is some logic around this, where it tries to fallback to the const version of try_cast, but that doesn't happen in the setter.
All the examples/tests in this repo are with member variables/functions, is that what I need to do?
Is this sort of thing tested/supported? Or am I just doing things wrong?