diff options
author | Robert Jaros <rjaros@finn.pl> | 2019-03-23 19:49:05 +0100 |
---|---|---|
committer | Robert Jaros <rjaros@finn.pl> | 2019-03-23 19:49:05 +0100 |
commit | 514d95a8f3f16b11b406bcfc9028cbf8d662227e (patch) | |
tree | 8f35315a0ee5181113592a359ddeb4b6878d91a0 /src/main/kotlin/pl/treksoft/kvision/panel | |
parent | 61649cb1b34771b3f7d9ae996040dec32c4a01c6 (diff) | |
download | kvision-514d95a8f3f16b11b406bcfc9028cbf8d662227e.tar.gz kvision-514d95a8f3f16b11b406bcfc9028cbf8d662227e.tar.bz2 kvision-514d95a8f3f16b11b406bcfc9028cbf8d662227e.zip |
CSS style objects.
Diffstat (limited to 'src/main/kotlin/pl/treksoft/kvision/panel')
-rw-r--r-- | src/main/kotlin/pl/treksoft/kvision/panel/Root.kt | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/src/main/kotlin/pl/treksoft/kvision/panel/Root.kt b/src/main/kotlin/pl/treksoft/kvision/panel/Root.kt index 24eff10f..e069dd4c 100644 --- a/src/main/kotlin/pl/treksoft/kvision/panel/Root.kt +++ b/src/main/kotlin/pl/treksoft/kvision/panel/Root.kt @@ -25,6 +25,7 @@ import com.github.snabbdom.VNode import com.github.snabbdom.h import pl.treksoft.kvision.KVManager import pl.treksoft.kvision.core.StringBoolPair +import pl.treksoft.kvision.core.Style import pl.treksoft.kvision.dropdown.ContextMenu import pl.treksoft.kvision.modal.Modal import pl.treksoft.kvision.utils.snClasses @@ -44,6 +45,7 @@ import pl.treksoft.kvision.utils.snOpt * @param init an initializer extension function */ class Root(id: String, private val fixed: Boolean = false, init: (Root.() -> Unit)? = null) : SimplePanel() { + private val styles: MutableList<Style> = mutableListOf() private val modals: MutableList<Modal> = mutableListOf() private val contextMenus: MutableList<ContextMenu> = mutableListOf() private var rootVnode: VNode = renderVNode() @@ -62,12 +64,18 @@ class Root(id: String, private val fixed: Boolean = false, init: (Root.() -> Uni return if (!fixed) { render("div#$id", arrayOf(h("div", snOpt { `class` = snClasses(listOf("row" to true)) - }, childrenVNodes() + modalsVNodes() + contextMenusVNodes()))) + }, stylesVNodes() + childrenVNodes() + modalsVNodes() + contextMenusVNodes()))) } else { - render("div#$id", childrenVNodes() + modalsVNodes() + contextMenusVNodes()) + render("div#$id", stylesVNodes() + childrenVNodes() + modalsVNodes() + contextMenusVNodes()) } } + internal fun addStyle(style: Style) { + styles.add(style) + style.parent = this + refresh() + } + internal fun addModal(modal: Modal) { modals.add(modal) modal.parent = this @@ -86,6 +94,16 @@ class Root(id: String, private val fixed: Boolean = false, init: (Root.() -> Uni refresh() } + private fun stylesVNodes(): Array<VNode> { + val visibleStyles = styles.filter { it.visible } + return if (visibleStyles.isNotEmpty()) { + val stylesDesc = visibleStyles.map { it.generateStyle() }.joinToString("\n") + arrayOf(h("style", arrayOf(stylesDesc))) + } else { + arrayOf() + } + } + private fun modalsVNodes(): Array<VNode> { return modals.filter { it.visible }.map { it.renderVNode() }.toTypedArray() } @@ -116,6 +134,9 @@ class Root(id: String, private val fixed: Boolean = false, init: (Root.() -> Uni } override fun dispose() { + styles.forEach { it.dispose() } + modals.forEach { it.dispose() } + contextMenus.forEach { it.dispose() } super.dispose() roots.remove(this) } |