Is it possible to get enum name from meta::uvalue
?
#93
-
I'm using something like this to draw a dropdown with the enum value as options: for (auto const& evalue : enum_type.get_evalues()) {
if (ImGui::Selectable(evalue.get_name().c_str())) {
member.set(ptr, evalue.get_value());
}
} It works fine and i can set the member just fine. But I can't seem to find a way to go from a |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
Hm... It's a good feature request, because right now we can't get an |
Beta Was this translation helpful? Give feedback.
-
Thanks for replying! I appreciate your help! auto GetName = [&enum_type](int i) -> std::string_view {
for (auto const& evalue : enum_type.get_evalues()) {
if (auto as_underlying_ptr = static_cast<int const*>(evalue.get_underlying_value().get_data()); *as_underlying_ptr == i) {
return evalue.get_name();
}
}
return std::string_view{ "Invalid" };
};
auto as_underlying_ptr = static_cast<int**>(value.get_data());
auto name = GetName(**as_underlying_ptr); I guess this only really works because i don't specify an underlying type for my enums so it's In any case, i'm waiting for the refactor! |
Beta Was this translation helpful? Give feedback.
-
So, Here is some examples/tests of this new functionality: |
Beta Was this translation helpful? Give feedback.
So,
enum_type
was refactored. Now it containsvalue_to_evalue
overloaded methods that work with static and dynamic values as well, and can be used in your case!Here is some examples/tests of this new functionality:
https://github.com/BlackMATov/meta.hpp/blob/main/develop/untests/meta_issues/github_discussion_93.cpp