summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRobert Jaros <rjaros@finn.pl>2017-10-01 15:16:11 +0200
committerRobert Jaros <rjaros@finn.pl>2017-10-01 15:17:53 +0200
commita61948c5b79d2fb3402e14ee69a9a8f2a18c02b4 (patch)
tree4f51345d2050b141111e3f6ef4bb3d16d4c23e7f /src
parentd732f672bfbfa565c6ec4fc037381554de251ad3 (diff)
downloadkvision-a61948c5b79d2fb3402e14ee69a9a8f2a18c02b4.tar.gz
kvision-a61948c5b79d2fb3402e14ee69a9a8f2a18c02b4.tar.bz2
kvision-a61948c5b79d2fb3402e14ee69a9a8f2a18c02b4.zip
Widget wrapper used inside the containers
Diffstat (limited to 'src')
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/Showcase.kt3
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/core/WidgetWrapper.kt16
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/panel/GridPanel.kt19
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/panel/HPanel.kt4
4 files changed, 32 insertions, 10 deletions
diff --git a/src/main/kotlin/pl/treksoft/kvision/Showcase.kt b/src/main/kotlin/pl/treksoft/kvision/Showcase.kt
index 221ac609..04ce2615 100644
--- a/src/main/kotlin/pl/treksoft/kvision/Showcase.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/Showcase.kt
@@ -13,6 +13,7 @@ import pl.treksoft.kvision.modal.Alert
import pl.treksoft.kvision.modal.Confirm
import pl.treksoft.kvision.modal.Modal
import pl.treksoft.kvision.panel.DIRECTION
+import pl.treksoft.kvision.panel.GRIDTYPE
import pl.treksoft.kvision.panel.GridPanel
import pl.treksoft.kvision.panel.HPanel
import pl.treksoft.kvision.panel.SplitPanel
@@ -114,7 +115,7 @@ class Showcase : ApplicationBase() {
val img = Image(Img("kotlin.png"), "Image", true, IMAGESHAPE.ROUNDED)
root.add(img)
- val grid = GridPanel(align = ALIGN.RIGHT)
+ val grid = GridPanel(gridtype = GRIDTYPE.DSG, align = ALIGN.RIGHT)
grid.add(Tag(DIV, "0,0"), 0, 0)
grid.add(Tag(DIV, "1,1"), 1, 1)
grid.add(Tag(DIV, "2,2"), 2, 2)
diff --git a/src/main/kotlin/pl/treksoft/kvision/core/WidgetWrapper.kt b/src/main/kotlin/pl/treksoft/kvision/core/WidgetWrapper.kt
new file mode 100644
index 00000000..0aa13e64
--- /dev/null
+++ b/src/main/kotlin/pl/treksoft/kvision/core/WidgetWrapper.kt
@@ -0,0 +1,16 @@
+package pl.treksoft.kvision.core
+
+import com.github.snabbdom.VNode
+
+open class WidgetWrapper(private var delegate: Widget, classes: Set<String> = setOf()) : Widget(classes) {
+
+ override fun render(): VNode {
+ val children = if (delegate.visible) {
+ arrayOf(delegate.render())
+ } else {
+ arrayOf()
+ }
+ return kvh("div", children)
+ }
+
+}
diff --git a/src/main/kotlin/pl/treksoft/kvision/panel/GridPanel.kt b/src/main/kotlin/pl/treksoft/kvision/panel/GridPanel.kt
index 243d1442..f7adfe8f 100644
--- a/src/main/kotlin/pl/treksoft/kvision/panel/GridPanel.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/panel/GridPanel.kt
@@ -3,6 +3,7 @@ package pl.treksoft.kvision.panel
import com.github.snabbdom.VNode
import pl.treksoft.kvision.core.Container
import pl.treksoft.kvision.core.Widget
+import pl.treksoft.kvision.core.WidgetWrapper
import pl.treksoft.kvision.html.ALIGN
import pl.treksoft.kvision.html.TAG
import pl.treksoft.kvision.html.Tag
@@ -27,7 +28,7 @@ internal data class WidgetParam(val widget: Widget, val size: Int, val offset: I
open class GridPanel(private val gridtype: GRIDTYPE = GRIDTYPE.BOOTSTRAP, private val gridsize: GRIDSIZE = GRIDSIZE.MD,
protected var rows: Int = 0, protected var cols: Int = 0, align: ALIGN = ALIGN.NONE,
classes: Set<String> = setOf()) : Container(classes) {
- var align = align
+ private var align = align
set(value) {
field = value
refresh()
@@ -97,7 +98,8 @@ open class GridPanel(private val gridtype: GRIDTYPE = GRIDTYPE.BOOTSTRAP, privat
if (row != null) {
for (j in 0 until cols) {
val wp = row[j]
- val widget = wp?.widget?.addCssClass("dsgcol") ?: Tag(TAG.DIV, classes = setOf("dsgcol"))
+ val widget = wp?.widget?.let { WidgetWrapper(it, setOf("dsgcol")) } ?:
+ Tag(TAG.DIV, classes = setOf("dsgcol"))
widget.widthPercent = num
if (align != ALIGN.NONE) {
widget.addCssClass(align.className)
@@ -121,8 +123,9 @@ open class GridPanel(private val gridtype: GRIDTYPE = GRIDTYPE.BOOTSTRAP, privat
for (j in 0 until cols) {
val wp = row[j]
if (auto) {
- val widget = wp?.widget?.addCssClass("col-" + gridsize.size + "-" + num) ?:
- Tag(TAG.DIV, classes = setOf("col-" + gridsize.size + "-" + num))
+ val widget = wp?.widget?.let {
+ WidgetWrapper(it, setOf("col-" + gridsize.size + "-" + num))
+ } ?: Tag(TAG.DIV, classes = setOf("col-" + gridsize.size + "-" + num))
if (align != ALIGN.NONE) {
widget.addCssClass(align.className)
}
@@ -130,14 +133,14 @@ open class GridPanel(private val gridtype: GRIDTYPE = GRIDTYPE.BOOTSTRAP, privat
} else {
if (wp != null) {
val s = if (wp.size > 0) wp.size else num
- wp.widget.addCssClass("col-" + gridsize.size + "-" + s)
+ val widget = WidgetWrapper(wp.widget, setOf("col-" + gridsize.size + "-" + s))
if (wp.offset > 0) {
- wp.widget.addCssClass("col-" + gridsize.size + "-offset-" + wp.offset)
+ widget.addCssClass("col-" + gridsize.size + "-offset-" + wp.offset)
}
if (align != ALIGN.NONE) {
- wp.widget.addCssClass(align.className)
+ widget.addCssClass(align.className)
}
- rowContainer.add(wp.widget)
+ rowContainer.add(widget)
}
}
}
diff --git a/src/main/kotlin/pl/treksoft/kvision/panel/HPanel.kt b/src/main/kotlin/pl/treksoft/kvision/panel/HPanel.kt
index 685cfc87..3d1db0e7 100644
--- a/src/main/kotlin/pl/treksoft/kvision/panel/HPanel.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/panel/HPanel.kt
@@ -3,6 +3,7 @@ package pl.treksoft.kvision.panel
import com.github.snabbdom.VNode
import pl.treksoft.kvision.core.Container
import pl.treksoft.kvision.core.Widget
+import pl.treksoft.kvision.core.WidgetWrapper
import pl.treksoft.kvision.html.ALIGN
import pl.treksoft.kvision.html.TAG
import pl.treksoft.kvision.html.Tag
@@ -21,7 +22,8 @@ open class HPanel(align: ALIGN = ALIGN.NONE, classes: Set<String> = setOf()) : G
if (row != null) {
for (j in 0 until cols) {
val wp = row[j]
- val widget = wp?.widget?.addCssClass("dsgcolf") ?: Tag(TAG.DIV, classes = setOf("dsgcolf"))
+ val widget = wp?.widget?.let { WidgetWrapper(it, setOf("dsgcolf")) } ?:
+ Tag(TAG.DIV, classes = setOf("dsgcolf"))
rowContainer.add(widget)
}
}