aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/pl/treksoft/kvision/panel/ResponsiveGridPanel.kt
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/kotlin/pl/treksoft/kvision/panel/ResponsiveGridPanel.kt')
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/panel/ResponsiveGridPanel.kt20
1 files changed, 6 insertions, 14 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))