summaryrefslogtreecommitdiff
path: root/src/main/kotlin/tech/thatgravyboat/rewardclaim/ui/UIButton.kt
blob: ec92f25c0c9415bf669bc62751e7431508834a86 (plain)
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
57
package tech.thatgravyboat.rewardclaim.ui

import gg.essential.elementa.components.UIBlock
import gg.essential.elementa.components.UIImage
import gg.essential.elementa.components.UIText
import gg.essential.elementa.constraints.CenterConstraint
import gg.essential.elementa.constraints.XConstraint
import gg.essential.elementa.dsl.*
import gg.essential.vigilance.gui.VigilancePalette
import java.awt.Color

private val BUTTON_HOVER = Color(0, 212, 105)

class UIButton(
    private val image: UIImage?,
    private val widthIn: Float,
    private var xConstraint: XConstraint,
    private val text: UIText,
    alignment: Alignment
) : UIBlock(VigilancePalette.getAccent()) {

    init {
        if (alignment == Alignment.LEFT) {
            xConstraint += (widthIn / 2f + 9f).pixel()
        } else if (alignment == Alignment.RIGHT) {
            xConstraint -= (widthIn / 2f + 9f).pixel()
        }

        constrain {
            width = widthIn.pixel()
            height = 17.pixel()
            x = xConstraint
            y = 95.percent() - 17.pixel()
        }

        text.constrain {
            x = CenterConstraint() - (if (image != null) 9 else 0).pixel()
            y = CenterConstraint()
        } childOf this

        image?.let {
            it.constrain {
                width = 9.pixel()
                height = 9.pixel()
                x = 100.percent() + 9.pixel()
                y = CenterConstraint()
            } childOf text
        }
        this.onMouseEnter { this.setColor(BUTTON_HOVER) }
        this.onMouseLeave { this.setColor(VigilancePalette.getAccent()) }
    }

}

enum class Alignment {
    LEFT, RIGHT, MIDDLE
}