New method ConfigOptionDef::set_enum_values() to initialize enum

names / values for UI combo boxes using an initializer list of pairs
of values.
This commit is contained in:
Vojtech Bubnik 2022-10-12 14:12:07 +02:00
parent 418734f41b
commit 009fe1cab4

View File

@ -1786,6 +1786,17 @@ public:
// Initialized by ConfigOptionEnum<xxx>::get_enum_values()
const t_config_enum_values *enum_keys_map = nullptr;
void set_enum_values(std::initializer_list<std::pair<std::string_view, std::string_view>> il) {
enum_values.clear();
enum_values.reserve(il.size());
enum_labels.clear();
enum_labels.reserve(il.size());
for (const std::pair<std::string_view, std::string_view> p : il) {
enum_values.emplace_back(p.first);
enum_labels.emplace_back(p.second);
}
}
bool has_enum_value(const std::string &value) const {
for (const std::string &v : enum_values)
if (v == value)