diff options
author | Robert Jaros <rjaros@finn.pl> | 2019-03-24 00:47:11 +0100 |
---|---|---|
committer | Robert Jaros <rjaros@finn.pl> | 2019-03-24 00:47:11 +0100 |
commit | 38d8447b7024112f54a4d2a4404840cae5e4d849 (patch) | |
tree | 5715fd6ebc195390d3e41f1f288175f6baa2d74f /src/main/kotlin/pl/treksoft/kvision/panel | |
parent | c56ddc135c7caa9a9b62ced9425544d599e9eb69 (diff) | |
download | kvision-38d8447b7024112f54a4d2a4404840cae5e4d849.tar.gz kvision-38d8447b7024112f54a4d2a4404840cae5e4d849.tar.bz2 kvision-38d8447b7024112f54a4d2a4404840cae5e4d849.zip |
Some fixes for 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 | 39 |
1 files changed, 24 insertions, 15 deletions
diff --git a/src/main/kotlin/pl/treksoft/kvision/panel/Root.kt b/src/main/kotlin/pl/treksoft/kvision/panel/Root.kt index 1a90f7fc..16d3a0f8 100644 --- a/src/main/kotlin/pl/treksoft/kvision/panel/Root.kt +++ b/src/main/kotlin/pl/treksoft/kvision/panel/Root.kt @@ -46,17 +46,21 @@ import pl.treksoft.kvision.utils.snOpt */ @Suppress("TooManyFunctions") 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() internal var renderDisabled = false + private val isFirstRoot = roots.isEmpty() + init { rootVnode = KVManager.patch(id, this.renderVNode()) this.id = id roots.add(this) + if (isFirstRoot) { + Style.styles.forEach { it.parent = this } + } @Suppress("LeakingThis") init?.invoke(this) } @@ -71,12 +75,6 @@ class Root(id: String, private val fixed: Boolean = false, init: (Root.() -> Uni } } - internal fun addStyle(style: Style) { - styles.add(style) - style.parent = this - refresh() - } - internal fun addModal(modal: Modal) { modals.add(modal) modal.parent = this @@ -96,10 +94,14 @@ class Root(id: String, private val fixed: Boolean = false, init: (Root.() -> Uni } private fun stylesVNodes(): Array<VNode> { - val visibleStyles = styles.filter { it.visible } - return if (visibleStyles.isNotEmpty()) { - val stylesDesc = visibleStyles.joinToString("\n") { it.generateStyle() } - arrayOf(h("style", arrayOf(stylesDesc))) + return if (isFirstRoot) { + val visibleStyles = Style.styles.filter { it.visible } + if (visibleStyles.isNotEmpty()) { + val stylesDesc = visibleStyles.joinToString("\n") { it.generateStyle() } + arrayOf(h("style", arrayOf(stylesDesc))) + } else { + arrayOf() + } } else { arrayOf() } @@ -135,18 +137,25 @@ 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) + if (isFirstRoot) { + Style.styles.clear() + } } companion object { internal val roots: MutableList<Root> = mutableListOf() + internal fun getFirstRoot(): Root? { + return if (roots.isNotEmpty()) + roots[0] + else + null + } + internal fun getLastRoot(): Root? { - return if (roots.size > 0) + return if (roots.isNotEmpty()) roots[roots.size - 1] else null |