-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathUIPoint.kt
56 lines (41 loc) · 1.34 KB
/
UIPoint.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package gg.essential.elementa.components
import gg.essential.elementa.UIComponent
import gg.essential.elementa.constraints.PositionConstraint
import gg.essential.elementa.dsl.pixels
import gg.essential.universal.UMatrixStack
/**
* "Component" with no width/height and therefore no visible rendering.
*
* Used primarily for [UIShape]
*/
class UIPoint(
val x: PositionConstraint,
val y: PositionConstraint
) : UIComponent() {
val relativeX: Float
get() = constraints.getX()
val relativeY: Float
get() = constraints.getY()
val absoluteX: Float
get() = getLeft()
val absoluteY: Float
get() = getTop()
val point: Pair<Float, Float>
get() = relativeX to relativeY
val absolutePoint: Pair<Float, Float>
get() = absoluteX to absoluteY
init {
setX(x)
setY(y)
}
constructor(x: Number, y: Number) : this(x.pixels(), y.pixels())
constructor(point: Pair<Number, Number>) : this(point.first.pixels(), point.second.pixels())
fun withX(x: PositionConstraint) = UIPoint(x, y)
fun withX(x: Number) = UIPoint(x.pixels(), y)
fun withY(y: PositionConstraint) = UIPoint(x, y)
fun withY(y: Number) = UIPoint(x, y.pixels())
override fun draw(matrixStack: UMatrixStack) {
beforeDraw(matrixStack)
super.draw(matrixStack)
}
}