blob: 1d4b1b68d222aa6a96eedcf456f58db6022532d9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
package pl.treksoft.kvision.panel
import com.github.snabbdom.VNode
import pl.treksoft.kvision.core.Component
open class StackPanel(
private val activateLast: Boolean = true,
classes: Set<String> = setOf()
) : SimplePanel(classes) {
var activeIndex = -1
set(value) {
field = value
refresh()
}
override fun childrenVNodes(): Array<VNode> {
return if (activeIndex >= 0 && activeIndex < children.size) {
arrayOf(children[activeIndex].renderVNode())
} else {
arrayOf()
}
}
override fun add(child: Component): StackPanel {
super.add(child)
if (activateLast) activeIndex = children.size - 1
else if (activeIndex == -1) activeIndex = 0
return this
}
override fun addAll(children: List<Component>): StackPanel {
super.addAll(children)
if (activateLast) activeIndex = this.children.size - 1
else if (activeIndex == -1) activeIndex = 0
return this
}
override fun remove(child: Component): StackPanel {
super.remove(child)
if (activeIndex > children.size - 1) activeIndex = children.size - 1
return this
}
override fun removeAll(): StackPanel {
super.removeAll()
if (activeIndex > children.size - 1) activeIndex = children.size - 1
return this
}
}
|