From 8f1e8cf6b68c19120e176ae181118f1f88074b33 Mon Sep 17 00:00:00 2001 From: Robert Jaros Date: Fri, 5 Jun 2020 14:48:31 +0200 Subject: New DSL builders for DockPanel --- .../kotlin/pl/treksoft/kvision/panel/DockPanel.kt | 61 ++++++++++++++++++++++ 1 file changed, 61 insertions(+) (limited to 'src/main/kotlin/pl/treksoft/kvision/panel') diff --git a/src/main/kotlin/pl/treksoft/kvision/panel/DockPanel.kt b/src/main/kotlin/pl/treksoft/kvision/panel/DockPanel.kt index 52239032..835b9986 100644 --- a/src/main/kotlin/pl/treksoft/kvision/panel/DockPanel.kt +++ b/src/main/kotlin/pl/treksoft/kvision/panel/DockPanel.kt @@ -107,6 +107,67 @@ open class DockPanel(classes: Set = setOf(), init: (DockPanel.() -> Unit init?.invoke(this) } + /** + * DSL function to add components at the UP position. + * @param builder DSL builder function + */ + open fun up(builder: Container.() -> Unit) { + object : Container by this@DockPanel { + override fun add(child: Component): Container { + return add(child, Side.UP) + } + }.builder() + } + + /** + * DSL function to add components at the DOWN position. + * @param builder DSL builder function + */ + open fun down(builder: Container.() -> Unit) { + object : Container by this@DockPanel { + override fun add(child: Component): Container { + return add(child, Side.DOWN) + } + }.builder() + } + + /** + * DSL function to add components on the LEFT side. + * @param builder DSL builder function + */ + open fun left(builder: Container.() -> Unit) { + object : Container by this@DockPanel { + override fun add(child: Component): Container { + return add(child, Side.LEFT) + } + }.builder() + } + + /** + * DSL function to add components on the RIGHT side. + * @param builder DSL builder function + */ + open fun right(builder: Container.() -> Unit) { + object : Container by this@DockPanel { + override fun add(child: Component): Container { + return add(child, Side.RIGHT) + } + }.builder() + } + + /** + * DSL function to add components in CENTER. + * @param builder DSL builder function + */ + open fun center(builder: Container.() -> Unit) { + val tempPanel = object : Container by this@DockPanel { + override fun add(child: Component): Container { + return add(child, Side.CENTER) + } + } + tempPanel.builder() + } + /** * Adds a component to the dock container. * @param child child component -- cgit