andrea-vinci/Insulator

View on GitHub
app/src/main/kotlin/insulator/ui/component/AppBar.kt

Summary

Maintainability
A
0 mins
Test Coverage
A
100%
package insulator.ui.component

import insulator.ui.style.AppBarStyle
import javafx.beans.value.ObservableStringValue
import javafx.event.EventTarget
import javafx.geometry.Pos
import javafx.scene.control.Button
import tornadofx.addClass
import tornadofx.borderpane
import tornadofx.buttonbar
import tornadofx.vbox

data class AppBarBuilder(
    var title: String = "",
    var subtitle: ObservableStringValue? = null,
    var buttons: List<Button> = emptyList()
)

fun EventTarget.appBar(op: AppBarBuilder.() -> Unit) {
    val builder = AppBarBuilder().apply(op)
    this.borderpane {
        center = vbox {
            h1(builder.title)
            builder.subtitle?.let { subTitle(builder.subtitle!!) }
            alignment = Pos.CENTER_LEFT
        }
        right = buttonbar {
            buttons.addAll(builder.buttons)
        }
        addClass(AppBarStyle.appBar)
    }
}