aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/pl/treksoft/kvision/panel/Root.kt
diff options
context:
space:
mode:
authorRobert Jaros <rjaros@finn.pl>2019-04-04 12:41:48 +0200
committerRobert Jaros <rjaros@finn.pl>2019-04-04 12:41:48 +0200
commit2011c50d03e4b09d968707a142e57891a3d8c5fe (patch)
tree630f1ec5cb1b323cd8d54893def024b9f1792a14 /src/main/kotlin/pl/treksoft/kvision/panel/Root.kt
parenta195fa82f8b4f75cc4fc2dc2a2d578ec45cf4323 (diff)
downloadkvision-2011c50d03e4b09d968707a142e57891a3d8c5fe.tar.gz
kvision-2011c50d03e4b09d968707a142e57891a3d8c5fe.tar.bz2
kvision-2011c50d03e4b09d968707a142e57891a3d8c5fe.zip
Fix modals rendering.
Diffstat (limited to 'src/main/kotlin/pl/treksoft/kvision/panel/Root.kt')
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/panel/Root.kt25
1 files changed, 16 insertions, 9 deletions
diff --git a/src/main/kotlin/pl/treksoft/kvision/panel/Root.kt b/src/main/kotlin/pl/treksoft/kvision/panel/Root.kt
index 16d3a0f8..c17ea1a4 100644
--- a/src/main/kotlin/pl/treksoft/kvision/panel/Root.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/panel/Root.kt
@@ -46,13 +46,12 @@ import pl.treksoft.kvision.utils.snOpt
*/
@Suppress("TooManyFunctions")
class Root(id: String, private val fixed: Boolean = false, init: (Root.() -> Unit)? = null) : SimplePanel() {
- 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()
+ val isFirstRoot = roots.isEmpty()
init {
rootVnode = KVManager.patch(id, this.renderVNode())
@@ -60,6 +59,7 @@ class Root(id: String, private val fixed: Boolean = false, init: (Root.() -> Uni
roots.add(this)
if (isFirstRoot) {
Style.styles.forEach { it.parent = this }
+ Modal.modals.forEach { it.parent = this }
}
@Suppress("LeakingThis")
init?.invoke(this)
@@ -75,12 +75,6 @@ class Root(id: String, private val fixed: Boolean = false, init: (Root.() -> Uni
}
}
- internal fun addModal(modal: Modal) {
- modals.add(modal)
- modal.parent = this
- refresh()
- }
-
internal fun addContextMenu(contextMenu: ContextMenu) {
contextMenus.add(contextMenu)
contextMenu.parent = this
@@ -108,7 +102,11 @@ class Root(id: String, private val fixed: Boolean = false, init: (Root.() -> Uni
}
private fun modalsVNodes(): Array<VNode> {
- return modals.filter { it.visible }.map { it.renderVNode() }.toTypedArray()
+ return if (isFirstRoot) {
+ Modal.modals.filter { it.visible }.map { it.renderVNode() }.toTypedArray()
+ } else {
+ arrayOf()
+ }
}
private fun contextMenusVNodes(): Array<VNode> {
@@ -141,10 +139,19 @@ class Root(id: String, private val fixed: Boolean = false, init: (Root.() -> Uni
roots.remove(this)
if (isFirstRoot) {
Style.styles.clear()
+ Modal.modals.clear()
}
}
companion object {
+ /**
+ * @suppress internal function
+ */
+ fun shutdown() {
+ roots.forEach { it.dispose() }
+ roots.clear()
+ }
+
internal val roots: MutableList<Root> = mutableListOf()
internal fun getFirstRoot(): Root? {