diff options
author | Robert Jaros <rjaros@finn.pl> | 2017-10-28 23:45:26 +0200 |
---|---|---|
committer | Robert Jaros <rjaros@finn.pl> | 2017-10-28 23:45:26 +0200 |
commit | 06f297d68887c7934e66d2c757abc8bf619df66a (patch) | |
tree | a828eec09f0bdc99b0f3fd45972b8cead37fbdec /src/main/kotlin/pl/treksoft/kvision/panel/SimplePanel.kt | |
parent | 6b13b8909a302b0f0f2155b81b83cd5ab4d7a046 (diff) | |
download | kvision-06f297d68887c7934e66d2c757abc8bf619df66a.tar.gz kvision-06f297d68887c7934e66d2c757abc8bf619df66a.tar.bz2 kvision-06f297d68887c7934e66d2c757abc8bf619df66a.zip |
Databinding components
Event handlers refactoring
Diffstat (limited to 'src/main/kotlin/pl/treksoft/kvision/panel/SimplePanel.kt')
-rw-r--r-- | src/main/kotlin/pl/treksoft/kvision/panel/SimplePanel.kt | 59 |
1 files changed, 59 insertions, 0 deletions
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<String> = setOf()) : Widget(classes), Container { + internal val children: MutableList<Widget> = mutableListOf() + + override fun render(): VNode { + return kvh("div", childrenVNodes()) + } + + protected open fun childrenVNodes(): Array<VNode> { + 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<Widget>): 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<Widget> { + return ArrayList(children) + } + + override fun dispose() { + children.forEach { it.dispose() } + removeAll() + } +} |