Slide 14
Slide 14 text
// Creating our DSL
fun rating(func: RatingDsl.() -> Unit)
= RatingDsl()
.apply { func() }
.build()
class RatingDsl(var initial: Int = 1,
var maximum: Int = 5) {
fun build(): RatingView {
return RatingView().apply {
setStars(initial)
setMaxStars(maximum)
}
}
}
// Using our DSL
rating {
initial = 3
maximum = 5
}
@Miqubel