From 06f297d68887c7934e66d2c757abc8bf619df66a Mon Sep 17 00:00:00 2001 From: Robert Jaros Date: Sat, 28 Oct 2017 23:45:26 +0200 Subject: Databinding components Event handlers refactoring --- .../pl/treksoft/kvision/panel/SimplePanel.kt | 59 ++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 src/main/kotlin/pl/treksoft/kvision/panel/SimplePanel.kt (limited to 'src/main/kotlin/pl/treksoft/kvision/panel/SimplePanel.kt') diff --git a/src/main/kotlin/pl/treksoft/kvision/panel/SimplePanel.kt b/src/main/kotlin/pl/treksoft/kvision/panel/SimplePanel.kt new file mode 100644 index 00000000..e9cf503b --- /dev/null +++ b/src/main/kotlin/pl/treksoft/kvision/panel/SimplePanel.kt @@ -0,0 +1,59 @@ +package pl.treksoft.kvision.panel + +import com.github.snabbdom.VNode +import pl.treksoft.kvision.core.Container +import pl.treksoft.kvision.core.Widget + +open class SimplePanel(classes: Set = setOf()) : Widget(classes), Container { + internal val children: MutableList = mutableListOf() + + override fun render(): VNode { + return kvh("div", childrenVNodes()) + } + + protected open fun childrenVNodes(): Array { + return children.filter { it.visible }.map { it.renderVNode() }.toTypedArray() + } + + protected fun addInternal(child: Widget): SimplePanel { + children.add(child) + child.parent = this + refresh() + return this + } + + override fun add(child: Widget): SimplePanel { + return addInternal(child) + } + + override fun addAll(children: List): SimplePanel { + this.children.addAll(children) + children.map { it.parent = this } + refresh() + return this + } + + override fun remove(child: Widget): SimplePanel { + if (children.remove(child)) { + child.clearParent() + refresh() + } + return this + } + + override fun removeAll(): SimplePanel { + children.map { it.clearParent() } + children.clear() + refresh() + return this + } + + override fun getChildren(): List { + return ArrayList(children) + } + + override fun dispose() { + children.forEach { it.dispose() } + removeAll() + } +} -- cgit