Added a new shape class instead of UI.
This commit is contained in:
parent
a8d9eb084a
commit
1250605e19
@ -11,4 +11,19 @@ operator fun Point.times(other: Point): Point = Point(x * other.x, y * other.y)
|
||||
operator fun Point.div(other: Point): Point = Point(x / other.x, y / other.y)
|
||||
operator fun Point.rem(other: Point): Point = Point(x % other.x, y % other.y)
|
||||
operator fun Point.times(factor: Int): Point = Point(x * factor, y * factor)
|
||||
operator fun Int.times(point: Point): Point = Point(point.x * this, point.y * this)
|
||||
operator fun Int.times(point: Point): Point = Point(point.x * this, point.y * this)
|
||||
|
||||
class Shape {
|
||||
private val points = mutableListOf<Point>()
|
||||
|
||||
operator fun Point.unaryPlus() {
|
||||
points.add(this)
|
||||
}
|
||||
}
|
||||
|
||||
fun shape(init: Shape.() -> Unit): Shape {
|
||||
val shape = Shape()
|
||||
shape.init()
|
||||
|
||||
return shape
|
||||
}
|
@ -1,30 +0,0 @@
|
||||
interface View
|
||||
class TextView(val value: String) : View
|
||||
class ImageView(val url: String) : View
|
||||
|
||||
class UI {
|
||||
private val views = mutableListOf<View>()
|
||||
|
||||
operator fun String.unaryPlus() {
|
||||
views.add(TextView(this))
|
||||
}
|
||||
|
||||
operator fun View.unaryPlus() {
|
||||
views.add(this)
|
||||
}
|
||||
}
|
||||
|
||||
fun ui(init: UI.() -> Unit): UI {
|
||||
val ui = UI()
|
||||
ui.init()
|
||||
|
||||
return ui
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val header = ui {
|
||||
+ImageView("http://logo.com")
|
||||
+"Brand name"
|
||||
+"Brand description"
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user