aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/pl/treksoft/kvision/panel
diff options
context:
space:
mode:
authorRobert Jaros <rjaros@finn.pl>2017-09-24 05:42:20 +0200
committerRobert Jaros <rjaros@finn.pl>2017-09-24 05:42:20 +0200
commit176215818b2572eefc1df18401ddaa896ea8a1fb (patch)
treea16b910d83760b6472e48dcefd8c8490b883c360 /src/main/kotlin/pl/treksoft/kvision/panel
parent659b87f5c1c297c68b125f67bc0b29b547debfd0 (diff)
downloadkvision-176215818b2572eefc1df18401ddaa896ea8a1fb.tar.gz
kvision-176215818b2572eefc1df18401ddaa896ea8a1fb.tar.bz2
kvision-176215818b2572eefc1df18401ddaa896ea8a1fb.zip
New containers: StackPanel, SplitPanel, Tabs
Diffstat (limited to 'src/main/kotlin/pl/treksoft/kvision/panel')
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/panel/SplitPanel.kt63
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/panel/StackPanel.kt52
2 files changed, 115 insertions, 0 deletions
diff --git a/src/main/kotlin/pl/treksoft/kvision/panel/SplitPanel.kt b/src/main/kotlin/pl/treksoft/kvision/panel/SplitPanel.kt
new file mode 100644
index 00000000..234a9a20
--- /dev/null
+++ b/src/main/kotlin/pl/treksoft/kvision/panel/SplitPanel.kt
@@ -0,0 +1,63 @@
+package pl.treksoft.kvision.panel
+
+import com.github.snabbdom.VNode
+import pl.treksoft.jquery.JQuery
+import pl.treksoft.kvision.core.Container
+import pl.treksoft.kvision.html.TAG
+import pl.treksoft.kvision.html.Tag
+import pl.treksoft.kvision.snabbdom.obj
+
+enum class DIRECTION(val dir: String) {
+ HORIZONTAL("horizontal"),
+ VERTICAL("vertical")
+}
+
+open class SplitPanel(val direction: DIRECTION = DIRECTION.VERTICAL,
+ classes: Set<String> = setOf()) : Container(classes + ("splitpanel-" + direction.dir)) {
+
+ internal val splitter = Splitter(this, direction)
+
+ internal fun afterInsertSplitter() {
+ if (children.size == 2) {
+ val horizontal = direction == DIRECTION.HORIZONTAL
+ children[0].getElementJQueryD().resizable(obj {
+ handleSelector = "#" + splitter.id
+ resizeWidth = !horizontal
+ resizeHeight = horizontal
+ onDragEnd = { _: dynamic, el: JQuery, _: dynamic ->
+ if (horizontal) {
+ children[0].height = el.height().toInt()
+ } else {
+ children[0].width = el.width().toInt()
+ }
+ }
+ })
+ }
+ }
+
+ override fun childrenVNodes(): Array<VNode> {
+ return if (children.size == 2) {
+ arrayOf(children[0].render(), splitter.render(), children[1].render())
+ } else {
+ arrayOf()
+ }
+ }
+}
+
+class Splitter(val splitPanel: SplitPanel, direction: DIRECTION) : Tag(TAG.DIV,
+ classes = setOf("splitter-" + direction.dir)) {
+ private val idc = "kv_splitter_" + counter
+
+ init {
+ counter++
+ this.id = idc
+ }
+
+ override fun afterInsert(node: VNode) {
+ splitPanel.afterInsertSplitter()
+ }
+
+ companion object {
+ var counter = 0
+ }
+}
diff --git a/src/main/kotlin/pl/treksoft/kvision/panel/StackPanel.kt b/src/main/kotlin/pl/treksoft/kvision/panel/StackPanel.kt
new file mode 100644
index 00000000..24429d42
--- /dev/null
+++ b/src/main/kotlin/pl/treksoft/kvision/panel/StackPanel.kt
@@ -0,0 +1,52 @@
+package pl.treksoft.kvision.panel
+
+import com.github.snabbdom.VNode
+import pl.treksoft.kvision.core.Container
+import pl.treksoft.kvision.core.Widget
+
+open class StackPanel(private val activateLast: Boolean = true,
+ classes: Set<String> = setOf()) : Container(classes) {
+ var activeIndex = -1
+ set(value) {
+ field = value
+ refresh()
+ }
+
+ override fun childrenVNodes(): Array<VNode> {
+ return if (activeIndex >= 0 && activeIndex < children.size) {
+ arrayOf(children[activeIndex].render())
+ } else {
+ arrayOf()
+ }
+ }
+
+ override fun add(child: Widget): Container {
+ super.add(child)
+ if (activateLast) activeIndex = children.size - 1
+ return this
+ }
+
+ override fun addAll(children: List<Widget>): Container {
+ super.addAll(children)
+ if (activateLast) activeIndex = this.children.size - 1
+ return this
+ }
+
+ override fun remove(child: Widget): Container {
+ super.remove(child)
+ if (activeIndex > children.size - 1) activeIndex = children.size - 1
+ return this
+ }
+
+ override fun removeAt(index: Int): Container {
+ super.removeAt(index)
+ if (activeIndex > children.size - 1) activeIndex = children.size - 1
+ return this
+ }
+
+ override fun removeAll(): Container {
+ super.removeAll()
+ if (activeIndex > children.size - 1) activeIndex = children.size - 1
+ return this
+ }
+}