Skip to content
This repository has been archived by the owner on Sep 28, 2024. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
Edvin Syse committed Oct 30, 2017
2 parents 5658ab4 + 328d708 commit 031c907
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/main/java/tornadofx/Layouts.kt
Original file line number Diff line number Diff line change
Expand Up @@ -329,3 +329,35 @@ fun Region.paddingAll(p: Double) {
var Region.paddingAll: Number get() = (padding.top + padding.right + padding.bottom + padding.left) / 4.0; set(value) {
padding = Insets(value.toDouble(), value.toDouble(), value.toDouble(), value.toDouble())
}

fun Region.fitToParentHeight() {
val parent = this.parent
if (parent != null && parent is Region) {
fitToHeight(parent)
}
}

fun Region.fitToParentWidth() {
val parent = this.parent
if (parent != null && parent is Region) {
fitToWidth(parent)
}
}

fun Region.fitToParentSize() {
fitToParentHeight()
fitToParentWidth()
}

fun Region.fitToHeight(region: Region) {
minHeightProperty().bind(region.heightProperty())
}

fun Region.fitToWidth(region: Region) {
minWidthProperty().bind(region.widthProperty())
}

fun Region.fitToSize(region: Region) {
fitToHeight(region)
fitToWidth(region)
}
58 changes: 58 additions & 0 deletions src/test/kotlin/tornadofx/tests/LayoutsTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package tornadofx.tests

import javafx.scene.Scene
import javafx.scene.control.ScrollPane
import javafx.scene.layout.Pane
import javafx.scene.layout.VBox
import javafx.stage.Stage
import org.junit.Test
import org.testfx.api.FxToolkit
import tornadofx.*
import kotlin.test.assertEquals

/**
*
* @author Anindya Chatterjee
*/
class RegionTest {
val primaryStage: Stage = FxToolkit.registerPrimaryStage()

lateinit var vbox: VBox

@Test
fun testFitToParentSize() {
FxToolkit.setupFixture {
val root = Pane().apply {
vbox {
this@RegionTest.vbox = this
fitToParentSize()
}
setPrefSize(400.0, 160.0)
}
primaryStage.scene = Scene(root)
primaryStage.show()

assertEquals(root.width, vbox.width)
assertEquals(root.height, vbox.height)
}
}

@Test
fun testFitToSize() {
FxToolkit.setupFixture {
val root = ScrollPane().apply {
content = vbox {
this@RegionTest.vbox = this
}
setPrefSize(400.0, 160.0)
}

vbox.fitToSize(root)
primaryStage.scene = Scene(root)
primaryStage.show()

assertEquals(root.width, vbox.width)
assertEquals(root.height, vbox.height)
}
}
}

0 comments on commit 031c907

Please sign in to comment.