diff options
author | Robbie Cronin <robert.cronin@uqconnect.edu.au> | 2019-06-21 13:17:30 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-06-21 13:17:30 +0800 |
commit | 2f8e0060308b0f5b1eeac9541600bfed3ad5acc9 (patch) | |
tree | 80d40364c5f5957da8c82578dd1152adac06912e /src/main/kotlin/pl/treksoft/kvision/panel/StackPanel.kt | |
parent | 9038555f9e46a32a0a725112304e64cdd408bf8e (diff) | |
parent | d9f1a90c772719d14540eb2bf7bc3b8384fa7a72 (diff) | |
download | kvision-2f8e0060308b0f5b1eeac9541600bfed3ad5acc9.tar.gz kvision-2f8e0060308b0f5b1eeac9541600bfed3ad5acc9.tar.bz2 kvision-2f8e0060308b0f5b1eeac9541600bfed3ad5acc9.zip |
Merge pull request #1 from rjaros/master
merge
Diffstat (limited to 'src/main/kotlin/pl/treksoft/kvision/panel/StackPanel.kt')
-rw-r--r-- | src/main/kotlin/pl/treksoft/kvision/panel/StackPanel.kt | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/src/main/kotlin/pl/treksoft/kvision/panel/StackPanel.kt b/src/main/kotlin/pl/treksoft/kvision/panel/StackPanel.kt index 3b045fa6..37dd449b 100644 --- a/src/main/kotlin/pl/treksoft/kvision/panel/StackPanel.kt +++ b/src/main/kotlin/pl/treksoft/kvision/panel/StackPanel.kt @@ -55,6 +55,8 @@ open class StackPanel( activeIndex = children.indexOf(value) } + internal val childrenMap = mutableMapOf<Int, Component>() + init { @Suppress("LeakingThis") init?.invoke(this) @@ -76,8 +78,11 @@ open class StackPanel( */ open fun add(panel: Component, route: String): StackPanel { add(panel) - val currentIndex = children.size - 1 - routing.on(route, { _ -> activeIndex = currentIndex }).resolve() + val currentIndex = counter++ + childrenMap[currentIndex] = panel + routing.on(route, { _ -> + activeChild = childrenMap[currentIndex]!! + }).resolve() return this } @@ -97,17 +102,23 @@ open class StackPanel( override fun remove(child: Component): StackPanel { super.remove(child) + childrenMap.filter { it.value == child }.keys.firstOrNull()?.let { + childrenMap.remove(it) + } if (activeIndex > children.size - 1) activeIndex = children.size - 1 return this } override fun removeAll(): StackPanel { super.removeAll() + childrenMap.clear() if (activeIndex > children.size - 1) activeIndex = children.size - 1 return this } companion object { + internal var counter = 0 + /** * DSL builder extension function. * |