Use enum toString() instead of enum name
This commit is contained in:
parent
135fb96f0b
commit
57323b3ac6
1 changed files with 8 additions and 4 deletions
|
@ -8,12 +8,12 @@ class EnumValue<E : Enum<E>>(name: String, value: E) : RegisteredValue<E>(name,
|
|||
return value
|
||||
.javaClass
|
||||
.enumConstants
|
||||
.first { it.name.equals(representation, ignoreCase = true) }
|
||||
.first { it.toString().equals(representation, ignoreCase = true) }
|
||||
}
|
||||
|
||||
override fun drawUIControl() {
|
||||
val selectedValue = ImInt(value.ordinal ?: -1)
|
||||
ImGui.combo(name, selectedValue, value.javaClass.enumConstants.map { it.name }.toTypedArray())
|
||||
ImGui.combo(name, selectedValue, value.javaClass.enumConstants.map { it.toString() }.toTypedArray())
|
||||
value = value.javaClass.enumConstants[selectedValue.get()]
|
||||
}
|
||||
}
|
||||
|
@ -24,12 +24,16 @@ class OptionalEnumValue<E : Enum<E>>(
|
|||
value: E?
|
||||
) : RegisteredValue<E?>(name, value) {
|
||||
override fun convertValueFromString(representation: String): E {
|
||||
return enumType.enumConstants.first { it.name.equals(representation, ignoreCase = true) }
|
||||
return enumType.enumConstants.first { it.toString().equals(representation, ignoreCase = true) }
|
||||
}
|
||||
|
||||
override fun drawUIControl() {
|
||||
val selectedValue = ImInt(value?.ordinal ?: -1)
|
||||
ImGui.combo(name, selectedValue, arrayOf("<none>") + enumType.enumConstants.map { it.name }.toTypedArray())
|
||||
ImGui.combo(
|
||||
name,
|
||||
selectedValue,
|
||||
arrayOf("<none>") + enumType.enumConstants.map { it.toString() }.toTypedArray()
|
||||
)
|
||||
value = enumType.enumConstants.getOrNull(selectedValue.get() - 1)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue