Add OptionParameter

Closes #78
This commit is contained in:
Edwin Jakobs
2020-04-14 20:43:26 +02:00
parent a0fd51c3c2
commit 591dccda63
6 changed files with 126 additions and 15 deletions

View File

@@ -22,6 +22,16 @@ import kotlin.reflect.full.memberProperties
@Retention(AnnotationRetention.RUNTIME)
annotation class Description(val title: String, val description: String = "")
/**
* OptionParameter annotation for a double precision parameter
* @property label a short description of the parameter
* @property order hint for where to place the parameter in user interfaces
*/
@Target(AnnotationTarget.PROPERTY)
@Retention(AnnotationRetention.RUNTIME)
annotation class OptionParameter(val label: String, val order: Int = Integer.MAX_VALUE)
/**
* DoubleParameter annotation for a double precision parameter
* @property label a short description of the parameter
@@ -167,7 +177,8 @@ enum class ParameterType(val annotationClass: KClass<out Annotation>) {
DoubleList(DoubleListParameter::class),
Vector2(Vector2Parameter::class),
Vector3(Vector3Parameter::class),
Vector4(Vector4Parameter::class)
Vector4(Vector4Parameter::class),
Option(OptionParameter::class)
;
companion object {
@@ -204,6 +215,7 @@ class Parameter(
val precision: Int?,
val invertY: Boolean?,
val showVector: Boolean?,
// val optionEnum: Enum<*>,
val order: Int)
//</editor-fold>
//<editor-fold desc="4. Add handling annotation code to listParameters" defaultstate="collapsed">
@@ -288,6 +300,10 @@ fun Any.listParameters(): List<Parameter> {
doubleRange = it.min..it.max
precision = it.precision
}
is OptionParameter -> {
label = it.label
order = it.order
}
}
}
Parameter(

View File

@@ -43,6 +43,8 @@ val a = object {
@Vector4Parameter("a vector 4 parameter", order = 10)
var v4 = Vector4.ZERO
@OptionParameter("an option parameter", order = 11)
var o = ParameterType.Option
}
@@ -50,7 +52,7 @@ object TestAnnotations : Spek({
describe("an annotated object") {
it("has listable parameters") {
val list = a.listParameters()
list.size `should be equal to` 11
list.size `should be equal to` 12
list[0].property?.name `should be equal to` "d"
list[0].parameterType `should be equal to` ParameterType.Double
@@ -117,6 +119,11 @@ object TestAnnotations : Spek({
list[10].parameterType `should be equal to` ParameterType.Vector4
list[10].property?.name `should be equal to` "v4"
list[10].label `should be equal to` "a vector 4 parameter"
list[11].parameterType `should be equal to` ParameterType.Option
list[11].property?.name `should be equal to` "o"
list[11].label `should be equal to` "an option parameter"
}
}
})