aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/pl/treksoft/kvision/panel
diff options
context:
space:
mode:
authorRobert Jaros <rjaros@finn.pl>2018-02-21 13:32:31 +0100
committerRobert Jaros <rjaros@finn.pl>2018-02-21 13:35:55 +0100
commit1aefed336f9ef305f59d3668abc8a39c550e921d (patch)
tree5eb468ac855b58718a4c15d86bd9915e64769278 /src/main/kotlin/pl/treksoft/kvision/panel
parentf88c59c04d9f7053a8a97b0c65a282f961913f1b (diff)
downloadkvision-1aefed336f9ef305f59d3668abc8a39c550e921d.tar.gz
kvision-1aefed336f9ef305f59d3668abc8a39c550e921d.tar.bz2
kvision-1aefed336f9ef305f59d3668abc8a39c550e921d.zip
Small style fixes contributed by tieskedh
Diffstat (limited to 'src/main/kotlin/pl/treksoft/kvision/panel')
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/panel/ResponsiveGridPanel.kt20
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/panel/StackPanel.kt2
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/panel/TabPanel.kt2
3 files changed, 8 insertions, 16 deletions
diff --git a/src/main/kotlin/pl/treksoft/kvision/panel/ResponsiveGridPanel.kt b/src/main/kotlin/pl/treksoft/kvision/panel/ResponsiveGridPanel.kt
index dbada3dc..4a82ed5b 100644
--- a/src/main/kotlin/pl/treksoft/kvision/panel/ResponsiveGridPanel.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/panel/ResponsiveGridPanel.kt
@@ -86,8 +86,8 @@ open class ResponsiveGridPanel(
* @return this container
*/
open fun add(child: Component, col: Int, row: Int, size: Int = 0, offset: Int = 0): ResponsiveGridPanel {
- val cRow = if (row < 0) 0 else row
- val cCol = if (col < 0) 0 else col
+ val cRow = maxOf(row, 0)
+ val cCol = maxOf(col, 0)
if (row > rows - 1) rows = cRow + 1
if (col > cols - 1) cols = cCol + 1
map.getOrPut(cRow, { mutableMapOf() })[cCol] = WidgetParam(child, size, offset)
@@ -107,16 +107,9 @@ open class ResponsiveGridPanel(
@Suppress("NestedBlockDepth")
override fun remove(child: Component): ResponsiveGridPanel {
- for (i in 0 until rows) {
- val row = map[i]
- if (row != null) {
- for (j in 0 until cols) {
- val wp = row[j]
- if (wp != null) {
- if (wp.widget == child) row.remove(j)
- }
- }
- }
+ map.values.forEach { row ->
+ row.filterValues { it.widget == child }
+ .forEach { (i, _) -> row.remove(i) }
}
refreshRowContainers()
return this
@@ -143,8 +136,7 @@ open class ResponsiveGridPanel(
val rowContainer = SimplePanel(setOf("row"))
val row = map[i]
if (row != null) {
- for (j in 0 until cols) {
- val wp = row[j]
+ (0 until cols).map { row[it] }.forEach { wp ->
if (auto) {
val widget = wp?.widget?.let {
WidgetWrapper(it, setOf("col-" + gridsize.size + "-" + num))
diff --git a/src/main/kotlin/pl/treksoft/kvision/panel/StackPanel.kt b/src/main/kotlin/pl/treksoft/kvision/panel/StackPanel.kt
index 235c76ec..bac027fe 100644
--- a/src/main/kotlin/pl/treksoft/kvision/panel/StackPanel.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/panel/StackPanel.kt
@@ -56,7 +56,7 @@ open class StackPanel(
}
override fun childrenVNodes(): Array<VNode> {
- return if (activeIndex >= 0 && activeIndex < children.size) {
+ return if (activeIndex in children.indices) {
arrayOf(children[activeIndex].renderVNode())
} else {
arrayOf()
diff --git a/src/main/kotlin/pl/treksoft/kvision/panel/TabPanel.kt b/src/main/kotlin/pl/treksoft/kvision/panel/TabPanel.kt
index 4572036d..1ac69b7b 100644
--- a/src/main/kotlin/pl/treksoft/kvision/panel/TabPanel.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/panel/TabPanel.kt
@@ -51,7 +51,7 @@ open class TabPanel(classes: Set<String> = setOf(), init: (TabPanel.() -> Unit)?
nav.children.forEach {
it.removeCssClass("active")
}
- if (content.activeIndex >= 0 && content.activeIndex <= nav.children.size) {
+ if (content.activeIndex in nav.children.indices) {
nav.children[content.activeIndex].addCssClass("active")
}
}