aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/pl/treksoft/kvision/panel
diff options
context:
space:
mode:
authorRobert Jaros <rjaros@finn.pl>2017-11-25 13:39:39 +0100
committerRobert Jaros <rjaros@finn.pl>2017-11-25 13:39:39 +0100
commit343390df5a0e01f45539939291c35d535a1b8af6 (patch)
treefcba5b87efa1b740bd5a011739af1e066cba28f0 /src/main/kotlin/pl/treksoft/kvision/panel
parent4a31ea44d479358658a614ad56a5675436260813 (diff)
downloadkvision-343390df5a0e01f45539939291c35d535a1b8af6.tar.gz
kvision-343390df5a0e01f45539939291c35d535a1b8af6.tar.bz2
kvision-343390df5a0e01f45539939291c35d535a1b8af6.zip
Form validation
Diffstat (limited to 'src/main/kotlin/pl/treksoft/kvision/panel')
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/panel/DockPanel.kt20
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/panel/FlexPanel.kt12
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/panel/GridPanel.kt12
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/panel/ResponsiveGridPanel.kt12
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/panel/SimplePanel.kt13
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/panel/StackPanel.kt8
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/panel/TabPanel.kt10
7 files changed, 44 insertions, 43 deletions
diff --git a/src/main/kotlin/pl/treksoft/kvision/panel/DockPanel.kt b/src/main/kotlin/pl/treksoft/kvision/panel/DockPanel.kt
index 6e037c28..376e34b9 100644
--- a/src/main/kotlin/pl/treksoft/kvision/panel/DockPanel.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/panel/DockPanel.kt
@@ -1,6 +1,6 @@
package pl.treksoft.kvision.panel
-import pl.treksoft.kvision.core.Widget
+import pl.treksoft.kvision.core.Component
enum class SIDE {
LEFT,
@@ -11,11 +11,11 @@ enum class SIDE {
}
open class DockPanel(classes: Set<String> = setOf()) : SimplePanel(classes = classes) {
- protected var left: Widget? = null
- protected var center: Widget? = null
- protected var right: Widget? = null
- protected var up: Widget? = null
- protected var down: Widget? = null
+ protected var left: Component? = null
+ protected var center: Component? = null
+ protected var right: Component? = null
+ protected var up: Component? = null
+ protected var down: Component? = null
protected val mainContainer = FlexPanel(direction = FLEXDIR.COLUMN, justify = FLEXJUSTIFY.SPACEBETWEEN,
alignItems = FLEXALIGNITEMS.STRETCH)
@@ -27,7 +27,7 @@ open class DockPanel(classes: Set<String> = setOf()) : SimplePanel(classes = cla
}
@Suppress("MagicNumber")
- open fun add(widget: Widget, position: SIDE): DockPanel {
+ open fun add(widget: Component, position: SIDE): DockPanel {
when (position) {
SIDE.UP -> {
up?.let { mainContainer.remove(it) }
@@ -58,16 +58,16 @@ open class DockPanel(classes: Set<String> = setOf()) : SimplePanel(classes = cla
return this
}
- override fun add(child: Widget): DockPanel {
+ override fun add(child: Component): DockPanel {
return this.add(child, SIDE.CENTER)
}
- override fun addAll(children: List<Widget>): DockPanel {
+ override fun addAll(children: List<Component>): DockPanel {
children.forEach { this.add(it) }
return this
}
- override fun remove(child: Widget): DockPanel {
+ override fun remove(child: Component): DockPanel {
if (child == left) removeAt(SIDE.LEFT)
if (child == center) removeAt(SIDE.CENTER)
if (child == right) removeAt(SIDE.RIGHT)
diff --git a/src/main/kotlin/pl/treksoft/kvision/panel/FlexPanel.kt b/src/main/kotlin/pl/treksoft/kvision/panel/FlexPanel.kt
index 6b6e11fb..80eddb23 100644
--- a/src/main/kotlin/pl/treksoft/kvision/panel/FlexPanel.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/panel/FlexPanel.kt
@@ -1,6 +1,6 @@
package pl.treksoft.kvision.panel
-import pl.treksoft.kvision.core.Widget
+import pl.treksoft.kvision.core.Component
import pl.treksoft.kvision.core.WidgetWrapper
import pl.treksoft.kvision.snabbdom.StringPair
@@ -73,22 +73,22 @@ open class FlexPanel(direction: FLEXDIR? = null, wrap: FLEXWRAP? = null, justify
}
@Suppress("LongParameterList")
- fun add(child: Widget, order: Int? = null, grow: Int? = null, shrink: Int? = null,
+ fun add(child: Component, order: Int? = null, grow: Int? = null, shrink: Int? = null,
basis: Int? = null, alignSelf: FLEXALIGNITEMS? = null, classes: Set<String> = setOf()): FlexPanel {
addInternal(FlexWrapper(child, order, grow, shrink, basis, alignSelf, classes))
return this
}
- override fun add(child: Widget): FlexPanel {
+ override fun add(child: Component): FlexPanel {
return add(child, null)
}
- override fun addAll(children: List<Widget>): FlexPanel {
+ override fun addAll(children: List<Component>): FlexPanel {
children.forEach { add(it, null) }
return this
}
- override fun remove(child: Widget): FlexPanel {
+ override fun remove(child: Component): FlexPanel {
children.find { (it as FlexWrapper).delegate == child }?.let {
super.remove(it)
it.dispose()
@@ -128,7 +128,7 @@ open class FlexPanel(direction: FLEXDIR? = null, wrap: FLEXWRAP? = null, justify
}
}
-class FlexWrapper(delegate: Widget, private val order: Int? = null, private val grow: Int? = null,
+class FlexWrapper(delegate: Component, private val order: Int? = null, private val grow: Int? = null,
private val shrink: Int? = null, private val basis: Int? = null,
private val alignSelf: FLEXALIGNITEMS? = null,
classes: Set<String> = setOf()) : WidgetWrapper(delegate, classes) {
diff --git a/src/main/kotlin/pl/treksoft/kvision/panel/GridPanel.kt b/src/main/kotlin/pl/treksoft/kvision/panel/GridPanel.kt
index cac5c79b..dac5867c 100644
--- a/src/main/kotlin/pl/treksoft/kvision/panel/GridPanel.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/panel/GridPanel.kt
@@ -1,6 +1,6 @@
package pl.treksoft.kvision.panel
-import pl.treksoft.kvision.core.Widget
+import pl.treksoft.kvision.core.Component
import pl.treksoft.kvision.core.WidgetWrapper
import pl.treksoft.kvision.snabbdom.StringPair
@@ -112,23 +112,23 @@ open class GridPanel(autoColumns: String? = null, autoRows: String? = null, auto
}
@Suppress("LongParameterList")
- fun add(child: Widget, columnStart: Int? = null, rowStart: Int? = null,
+ fun add(child: Component, columnStart: Int? = null, rowStart: Int? = null,
columnEnd: String? = null, rowEnd: String? = null, area: String? = null, justifySelf: GRIDJUSTIFY? = null,
alignSelf: GRIDALIGN? = null, classes: Set<String> = setOf()): GridPanel {
addInternal(GridWrapper(child, columnStart, rowStart, columnEnd, rowEnd, area, justifySelf, alignSelf, classes))
return this
}
- override fun add(child: Widget): GridPanel {
+ override fun add(child: Component): GridPanel {
return add(child, null, null)
}
- override fun addAll(children: List<Widget>): GridPanel {
+ override fun addAll(children: List<Component>): GridPanel {
children.forEach { add(it, null, null) }
return this
}
- override fun remove(child: Widget): GridPanel {
+ override fun remove(child: Component): GridPanel {
children.find { (it as GridWrapper).delegate == child }?.let {
super.remove(it)
it.dispose()
@@ -190,7 +190,7 @@ open class GridPanel(autoColumns: String? = null, autoRows: String? = null, auto
}
}
-class GridWrapper(delegate: Widget, private val columnStart: Int? = null, private val rowStart: Int? = null,
+class GridWrapper(delegate: Component, private val columnStart: Int? = null, private val rowStart: Int? = null,
private val columnEnd: String? = null, private val rowEnd: String? = null,
private val area: String? = null, private val justifySelf: GRIDJUSTIFY? = null,
private val alignSelf: GRIDALIGN? = null,
diff --git a/src/main/kotlin/pl/treksoft/kvision/panel/ResponsiveGridPanel.kt b/src/main/kotlin/pl/treksoft/kvision/panel/ResponsiveGridPanel.kt
index 3587ea8e..88d70a64 100644
--- a/src/main/kotlin/pl/treksoft/kvision/panel/ResponsiveGridPanel.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/panel/ResponsiveGridPanel.kt
@@ -1,6 +1,6 @@
package pl.treksoft.kvision.panel
-import pl.treksoft.kvision.core.Widget
+import pl.treksoft.kvision.core.Component
import pl.treksoft.kvision.core.WidgetWrapper
import pl.treksoft.kvision.html.ALIGN
import pl.treksoft.kvision.html.TAG
@@ -15,7 +15,7 @@ enum class GRIDSIZE(val size: String) {
const val MAX_COLUMNS = 12
-internal data class WidgetParam(val widget: Widget, val size: Int, val offset: Int)
+internal data class WidgetParam(val widget: Component, val size: Int, val offset: Int)
open class ResponsiveGridPanel(private val gridsize: GRIDSIZE = GRIDSIZE.MD,
private var rows: Int = 0, private var cols: Int = 0, align: ALIGN? = null,
@@ -29,7 +29,7 @@ open class ResponsiveGridPanel(private val gridsize: GRIDSIZE = GRIDSIZE.MD,
internal val map = mutableMapOf<Int, MutableMap<Int, WidgetParam>>()
private var auto: Boolean = true
- open fun add(child: Widget, row: Int, col: Int, size: Int = 0, offset: Int = 0): ResponsiveGridPanel {
+ open fun add(child: Component, row: Int, col: Int, size: Int = 0, offset: Int = 0): ResponsiveGridPanel {
val cRow = if (row < 0) 0 else row
val cCol = if (col < 0) 0 else col
if (row > rows - 1) rows = cRow + 1
@@ -40,17 +40,17 @@ open class ResponsiveGridPanel(private val gridsize: GRIDSIZE = GRIDSIZE.MD,
return this
}
- override fun add(child: Widget): ResponsiveGridPanel {
+ override fun add(child: Component): ResponsiveGridPanel {
return this.add(child, 0, this.cols)
}
- override fun addAll(children: List<Widget>): ResponsiveGridPanel {
+ override fun addAll(children: List<Component>): ResponsiveGridPanel {
children.forEach { this.add(it) }
return this
}
@Suppress("NestedBlockDepth")
- override fun remove(child: Widget): ResponsiveGridPanel {
+ override fun remove(child: Component): ResponsiveGridPanel {
for (i in 0 until rows) {
val row = map[i]
if (row != null) {
diff --git a/src/main/kotlin/pl/treksoft/kvision/panel/SimplePanel.kt b/src/main/kotlin/pl/treksoft/kvision/panel/SimplePanel.kt
index e9cf503b..90362127 100644
--- a/src/main/kotlin/pl/treksoft/kvision/panel/SimplePanel.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/panel/SimplePanel.kt
@@ -2,10 +2,11 @@ package pl.treksoft.kvision.panel
import com.github.snabbdom.VNode
import pl.treksoft.kvision.core.Container
+import pl.treksoft.kvision.core.Component
import pl.treksoft.kvision.core.Widget
open class SimplePanel(classes: Set<String> = setOf()) : Widget(classes), Container {
- internal val children: MutableList<Widget> = mutableListOf()
+ internal val children: MutableList<Component> = mutableListOf()
override fun render(): VNode {
return kvh("div", childrenVNodes())
@@ -15,25 +16,25 @@ open class SimplePanel(classes: Set<String> = setOf()) : Widget(classes), Contai
return children.filter { it.visible }.map { it.renderVNode() }.toTypedArray()
}
- protected fun addInternal(child: Widget): SimplePanel {
+ protected fun addInternal(child: Component): SimplePanel {
children.add(child)
child.parent = this
refresh()
return this
}
- override fun add(child: Widget): SimplePanel {
+ override fun add(child: Component): SimplePanel {
return addInternal(child)
}
- override fun addAll(children: List<Widget>): SimplePanel {
+ override fun addAll(children: List<Component>): SimplePanel {
this.children.addAll(children)
children.map { it.parent = this }
refresh()
return this
}
- override fun remove(child: Widget): SimplePanel {
+ override fun remove(child: Component): SimplePanel {
if (children.remove(child)) {
child.clearParent()
refresh()
@@ -48,7 +49,7 @@ open class SimplePanel(classes: Set<String> = setOf()) : Widget(classes), Contai
return this
}
- override fun getChildren(): List<Widget> {
+ override fun getChildren(): List<Component> {
return ArrayList(children)
}
diff --git a/src/main/kotlin/pl/treksoft/kvision/panel/StackPanel.kt b/src/main/kotlin/pl/treksoft/kvision/panel/StackPanel.kt
index e8975dce..55bd2cca 100644
--- a/src/main/kotlin/pl/treksoft/kvision/panel/StackPanel.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/panel/StackPanel.kt
@@ -1,7 +1,7 @@
package pl.treksoft.kvision.panel
import com.github.snabbdom.VNode
-import pl.treksoft.kvision.core.Widget
+import pl.treksoft.kvision.core.Component
open class StackPanel(private val activateLast: Boolean = true,
classes: Set<String> = setOf()) : SimplePanel(classes) {
@@ -19,21 +19,21 @@ open class StackPanel(private val activateLast: Boolean = true,
}
}
- override fun add(child: Widget): StackPanel {
+ 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<Widget>): StackPanel {
+ 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: Widget): StackPanel {
+ override fun remove(child: Component): StackPanel {
super.remove(child)
if (activeIndex > children.size - 1) activeIndex = children.size - 1
return this
diff --git a/src/main/kotlin/pl/treksoft/kvision/panel/TabPanel.kt b/src/main/kotlin/pl/treksoft/kvision/panel/TabPanel.kt
index 4190dbae..e60d9480 100644
--- a/src/main/kotlin/pl/treksoft/kvision/panel/TabPanel.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/panel/TabPanel.kt
@@ -1,7 +1,7 @@
package pl.treksoft.kvision.panel
+import pl.treksoft.kvision.core.Component
import pl.treksoft.kvision.core.ResString
-import pl.treksoft.kvision.core.Widget
import pl.treksoft.kvision.html.Link
import pl.treksoft.kvision.html.TAG
import pl.treksoft.kvision.html.Tag
@@ -25,7 +25,7 @@ open class TabPanel : SimplePanel(setOf()) {
this.addInternal(content)
}
- open fun addTab(title: String, panel: Widget, icon: String? = null,
+ open fun addTab(title: String, panel: Component, icon: String? = null,
image: ResString? = null): TabPanel {
val tag = Tag(TAG.LI)
tag.role = "presentation"
@@ -53,16 +53,16 @@ open class TabPanel : SimplePanel(setOf()) {
return this
}
- override fun add(child: Widget): TabPanel {
+ override fun add(child: Component): TabPanel {
return addTab("", child)
}
- override fun addAll(children: List<Widget>): TabPanel {
+ override fun addAll(children: List<Component>): TabPanel {
children.forEach { add(it) }
return this
}
- override fun remove(child: Widget): TabPanel {
+ override fun remove(child: Component): TabPanel {
val index = content.children.indexOf(child)
return removeTab(index)
}