Skip to content

Commit

Permalink
edvin#801 Remove the grid row id key property on when removing the si…
Browse files Browse the repository at this point in the history
…ngle row

Thinking more it feels like the better approach to remove the property rather than going to -1 value.
  • Loading branch information
zshamrock committed Sep 16, 2018
1 parent 59212b5 commit 5118b48
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 6 additions & 2 deletions src/main/java/tornadofx/Layouts.kt
Expand Up @@ -41,8 +41,12 @@ fun GridPane.row(title: String? = null, op: Pane.() -> Unit = {}) {
* @return the row index of the removed row.
*/
fun GridPane.removeRow(node: Node): Int {
if (properties.containsKey(GridPaneRowIdKey)) {
properties[GridPaneRowIdKey] = properties[GridPaneRowIdKey] as Int - 1
val rowIdKey = properties[GridPaneRowIdKey] as Int?
if (rowIdKey != null) {
when (rowIdKey) {
0 -> properties.remove(GridPaneRowIdKey)
else -> properties[GridPaneRowIdKey] = rowIdKey - 1
}
}
val rowIndex = GridPane.getRowIndex(node) ?: 0
val nodesToDelete = mutableListOf<Node>()
Expand Down
2 changes: 1 addition & 1 deletion src/test/kotlin/tornadofx/tests/LayoutsTest.kt
Expand Up @@ -138,7 +138,7 @@ class RegionTest {

root.removeRow(label)

assertEquals(root.properties[GridPaneRowIdKey], -1)
assertFalse(root.properties.containsKey(GridPaneRowIdKey))
assertNull(GridPane.getRowIndex(label))
assertNull(GridPane.getColumnIndex(label))
assertEquals(root.children, emptyList<Node>().observable())
Expand Down

0 comments on commit 5118b48

Please sign in to comment.