aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/pl/treksoft/kvision/panel/SplitPanel.kt
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/SplitPanel.kt
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/SplitPanel.kt')
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/panel/SplitPanel.kt63
1 files changed, 63 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
+ }
+}