2019-06-24 01:56:58 +00:00
|
|
|
package net.shadowfacts.cacao.view.button
|
2019-06-23 21:56:49 +00:00
|
|
|
|
|
|
|
import net.shadowfacts.cacao.Window
|
|
|
|
import net.shadowfacts.cacao.geometry.Point
|
|
|
|
import net.shadowfacts.cacao.geometry.Size
|
|
|
|
import net.shadowfacts.cacao.util.MouseButton
|
2019-06-24 01:56:58 +00:00
|
|
|
import net.shadowfacts.cacao.view.View
|
2019-06-23 21:56:49 +00:00
|
|
|
import net.shadowfacts.kiwidsl.dsl
|
|
|
|
import org.junit.jupiter.api.Assertions.assertFalse
|
|
|
|
import org.junit.jupiter.api.Assertions.assertTrue
|
|
|
|
import org.junit.jupiter.api.BeforeEach
|
|
|
|
import org.junit.jupiter.api.Test
|
|
|
|
import java.util.concurrent.CompletableFuture
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @author shadowfacts
|
|
|
|
*/
|
|
|
|
class ButtonClickTests {
|
|
|
|
|
|
|
|
lateinit var window: Window
|
|
|
|
|
|
|
|
@BeforeEach
|
|
|
|
fun setup() {
|
|
|
|
window = Window()
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
fun testClickInsideButton() {
|
|
|
|
val clicked = CompletableFuture<Boolean>()
|
|
|
|
val content = View().apply {
|
|
|
|
intrinsicContentSize = Size(25.0, 25.0)
|
|
|
|
}
|
|
|
|
val button = window.addView(Button(content).apply {
|
|
|
|
handler = {
|
|
|
|
clicked.complete(true)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
window.solver.dsl {
|
|
|
|
button.leftAnchor equalTo 0
|
|
|
|
button.topAnchor equalTo 0
|
|
|
|
}
|
|
|
|
window.layout()
|
|
|
|
window.mouseClicked(Point(5.0, 5.0), MouseButton.LEFT)
|
|
|
|
|
|
|
|
assertTrue(clicked.getNow(false))
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
fun testClickOutsideButton() {
|
|
|
|
val clicked = CompletableFuture<Boolean>()
|
|
|
|
val content = View().apply {
|
|
|
|
intrinsicContentSize = Size(25.0, 25.0)
|
|
|
|
}
|
|
|
|
val button = window.addView(Button(content).apply {
|
|
|
|
handler = {
|
|
|
|
clicked.complete(true)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
window.solver.dsl {
|
|
|
|
button.leftAnchor equalTo 0
|
|
|
|
button.topAnchor equalTo 0
|
|
|
|
}
|
|
|
|
window.layout()
|
|
|
|
window.mouseClicked(Point(50.0, 50.0), MouseButton.LEFT)
|
|
|
|
|
|
|
|
assertFalse(clicked.getNow(false))
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|