diff options
Diffstat (limited to 'src/main/kotlin/pl/treksoft/kvision/panel')
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") } } |